标题: [文件操作] [已解决]批处理如何获取mp3歌曲时间长度并算出1/4和3/4处的时间点? [打印本页]
作者: pendave 时间: 2015-1-27 18:59 标题: [已解决]批处理如何获取mp3歌曲时间长度并算出1/4和3/4处的时间点?
如何用批处理获取一首mp3(或批量获取同一文件夹里的多个mp3)的歌曲时间长度并算出1/4和3/4处的时间点?
主要是想批量分割多个mp3成前1/4和后3/4的片段。
我参看国外的mp3相关编辑论坛有分割的,但是目前只能手动指定时间点来分割。
现在很不想手动输入时间点,自动能判断算出那2个时间点甚至多个时间点该是多方便啊,因为每个mp3的时间长度都不一样。
dpmp3split.cmd- @echo off
- set "mp3DirectCut=C:\Program Files (x86)\mp3DirectCut_2.20\mp3DirectCut.exe"
- for %%f in (%3) do (
- echo FILE "%%~f" MP3> sheet.cue
- echo TRACK 01 AUDIO>>sheet.cue
- echo INDEX 01 00:00:00>>sheet.cue
- echo TRACK 02 AUDIO>>sheet.cue
- echo INDEX 01 %1>>sheet.cue
- echo TRACK 03 AUDIO>>sheet.cue
- echo INDEX 01 %2>>sheet.cue
- "%mp3DirectCut%" sheet.cue /split
- del *02.mp3
- )
- del sheet.cue
- ren *01.mp3 *" "p01.mp3
- ren *03.mp3 *" "p02.mp3
复制代码
用这个分割片段.bat 来调用- ::在这里手动设置截取片段的两个时间点↓
- dpmp3split.cmd 01:10:00 03:30:00 *.mp3
复制代码
需要安装 mp3DirectCut 2.20 这个编辑mp3的工具,到处有下。
这里有这个软件的命令行代码
Command line options
Usage:
mp3DirectCut.exe <filename> <option(s)> <destination>
As <filename> every file type known by mp3DirectCut is possible (MP3, MP2, Project files, Cue sheets). Usually this is simply for a file to be opened. In your operating system settings you can associate mp3DirectCut to one or more of these file types and with different options. Then you can open the program easily by any file of that type. It is also possible to drag files of known types over mp3DirectCut.
If you use the <filename> parameter together with /rec you can set an individual record filename that differs from the base filename of the recording settings.
The following options can be used to let the program perform an action immediately. After finnishing, the program quits.
Note: adjustments for Normalize, Auto cue, Encoder settings and so on cannot be given over the command line. They must be made before in the normal program environment.
Examples:
mp3DirectCut "artist - song.mp3"
mp3DirectCut track01.mp3 /normalize /overwrite
mp3DirectCut audiobook.mp3 /autocue d:\split
mp3DirectCut album.cue /split
mp3DirectCut /rec
mp3DirectCut other_recname.mp3 /rec
Options:
/normalize Normalizes the file up to 0 dB. Higher or lower levels cannot be set in the command line.
/autocue Splits the given file into segments of the time set in the Autocue dialog. Also for the Split operation the current settings from normal program usage are applied. <destination> can be an existing folder to save the split files to.
/autocrop Cuts silences from beginning and end of track using the "Lowest gain" value which can be set in the configuration window or in the gain dialog.
/split Needs a Cue sheet or Project file and splits the audio file(s). If a <destination> folder is set, the split files will be saved there. The other Split settings must be adjusted in the normal program environment.
/pausesplit Runs the pause detector and splits the given file at the found pause positions. For the performed Pause detection and Save split operations, the current settings are applied. You can change them by normal program usage. <destination> can be an existing folder for the result files.
/save Opens and saves the file. Simple re-save can be used to eliminate incomplete frames or unwanted headers.
/overwrite Replaces the original file on /save or /normalize. The current "Keep date of source file" setting is valid (it can be set in the program environment). If /overwrite is not set, the given file extension will be appended once more.
/rec Starts the recording immediately. This feature is especially made for timer recordings. In a scheduler usually you can also set a duration time after which the program will be terminated. For multiple timer recordings be sure to check Add date and time or Append data in the recording settings, otherwise previous recordings will be overwritten. If a filename is given before the /rec option and Add date and time or Append data is not (!) selected, the program records into a file of that name.
/localini Regulary the program tries to write the settings into its own folder. If this fails, e.g. because of missing rights, the settings are stored in the user's Application data folder. This option prevents the program from reading from or writing to the user profile. This may be useful in special cases, e.g. if local settings are needed when the program is running from a removable drive.
有没有大触手可以把这2个批处理融合成一个文件,我确实太新手了...
关于获取mp3时间长度,我网上看到
BAT和JScript混合编程获取mp3音频文件的播放时间长度
http://bbs.bathome.net/viewthread.php?tid=29969#pid147781
谢谢高手来相助!
作者: pendave 时间: 2015-1-27 19:45
这里看到 .bat .vbs 配合获取mp3信息的代码
http://www.experts-exchange.com/ ... DOS/Q_27077456.html
Batch File Read File Attributes advanced.bat- @echo off
- setlocal
- set FileName=C:\test.mp3
- for /F "tokens=1* delims==" %%A in ('cscript getinfo.vbs "%FileName%"') do set _prop_%%A=%%B
- set _prop
复制代码
getinfo.vbs- if (WScript.Arguments.Count > 0) Then
- strFile = WScript.Arguments(0)
- Else
- WScript.Echo "ERROR : No input filename specified."
- WScript.Quit -1
- End If
-
- Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
-
- If Not objFSO.FileExists(strFile) then
- WScript.Echo "ERROR : Input filename specified does not exist."
- WScript.Quit -1
- End If
-
- Set objFile = objFSO.GetFile(strFile)
- strFolder = objFile.ParentFolder
-
- Dim strAttrName(300)
-
- Set objShell = CreateObject("Shell.Application")
- Set objFolder = objShell.NameSpace(strFolder)
-
- for N = 0 To 300
- strAttrName(N) = Replace(objFolder.GetDetailsOf(Nothing, N), " ", "_")
- Next
-
- Set objFileItem = objFolder.ParseName(objFile.Name)
-
- For i = 0 To 300
- if objFolder.GetDetailsOf(objFileItem, i) <> "" Then
- If Instr("objFolder.GetDetailsOf(objFileItem, i)", Chr(63)) then Wscript.Echo "FOUND"
- WScript.Echo strAttrName(i) & "=" & Replace(objFolder.GetDetailsOf(objFileItem, i), Chr(63), "")
- End If
- Next
-
- Wscript.Quit 0
复制代码
在BAT里怎么计算出一首mp3的1/4位置的时间点和 3/4位置的时间点呢?
作者: apang 时间: 2015-1-27 22:03
- @set @n=0; /* & echo off
- pushd "F:\music\"
- set "JS=cscript -nologo -e:jscript"
- for /f "tokens=1,2*" %%a in ('dir /b *.mp3^|%JS% "%~0"') do (
- set "Name=%%c"
- set /a h1=%%a/3600,m1=%%a%%3600/60,s1=%%a%%3600%%60
- set /a h2=%%b/3600,m2=%%b%%3600/60,s2=%%b%%3600%%60
- set /a h1+=100,m1+=100,s1+=100,h2+=100,m2+=100,s2+=100
- setlocal enabledelayedexpansion
- set "t1=!h1:~1!:!m1:~1!:!s1:~1!"
- set "t2=!h2:~1!:!m2:~1!:!s2:~1!"
- echo,!t1! !t2! !Name!
- endlocal
- )
- pause & exit/b & rem */
-
- WMP = new ActiveXObject("WMPlayer.OCX");
- s = "";
- while (!WScript.StdIn.AtEndOfStream) {
- f = WScript.StdIn.ReadLine();
- t = WMP.newMedia(f).getItemInfo("Duration");
- t1 = Math.round(t/4)
- t2 = Math.round(t*3/4)
- s += t1 + " " + t2 + " " + f + "\n"
- }
- WScript.StdOut.Write(s)
复制代码
调用第3方自己搞定
作者: pendave 时间: 2015-1-27 22:08
本帖最后由 pendave 于 2015-1-27 23:44 编辑
我刚才用2楼的代码获得了mp3的长度了
echo %_prop_长度%
作者: pendave 时间: 2015-1-27 22:13
本帖最后由 pendave 于 2015-1-27 22:27 编辑
回复 3# apang
我刚才用2楼的代码获得了mp3的长度了
echo %_prop_长度%
比如这个值是 00:04:58
我想把它变成 04:58 就是格式是向左移位了的,分:秒
是不是改下你代码中的- set "t1=!m1:~1!:!s1:~1!"
- set "t2=!m2:~1!:!s2:~1!"
复制代码
作者: pendave 时间: 2015-1-27 23:41
本帖最后由 pendave 于 2015-1-28 00:00 编辑
回复 3# apang
亲,调用第三方我那个是个For遍历吧,我弄了半天都整合不好,晕死了- @set @n=0; /* & echo off
-
- set "JS=cscript -nologo -e:jscript"
- set "mp3DirectCut=C:\Program Files (x86)\mp3DirectCut_2.20\mp3DirectCut.exe"
- for /f "tokens=1,2*" %%a in ('dir /b *.mp3^|%JS% "%~0"') do (
- set "Name=%%c"
- set /a h1=%%a/3600,m1=%%a%%3600/60,s1=%%a%%3600%%60
- set /a h2=%%b/3600,m2=%%b%%3600/60,s2=%%b%%3600%%60
- set /a h1+=100,m1+=100,s1+=100,h2+=100,m2+=100,s2+=100
- setlocal enabledelayedexpansion
- rem set "t1=!h1:~1!:!m1:~1!:!s1:~1!"
- rem set "t2=!h2:~1!:!m2:~1!:!s2:~1!"
- set "t1=!m1:~1!:!s1:~1!"
- set "t2=!m2:~1!:!s2:~1!"
- echo,!t1! !t2! !Name!
- endlocal
- )
- pause & exit/b & rem */
-
- WMP = new ActiveXObject("WMPlayer.OCX");
- s = "";
- while (!WScript.StdIn.AtEndOfStream) {
- f = WScript.StdIn.ReadLine();
- t = WMP.newMedia(f).getItemInfo("Duration");
- t1 = Math.round(t/4);
- t2 = Math.round(t*3/4);
- s += t1 + " " + t2 + " " + f + "\n";
- }
- WScript.StdOut.Write(s);
复制代码
和- @echo off
- set "mp3DirectCut=C:\Program Files (x86)\mp3DirectCut_2.20\mp3DirectCut.exe"
- for %%f in (*.mp3) do (
- echo FILE "%%f"> sh.cue
- echo TRACK 01 AUDIO>>sh.cue
- echo INDEX 01 %1>>sh.cue
- echo TRACK 02 AUDIO>>sh.cue
- echo INDEX 01 %2>>sh.cue
- "%mp3DirectCut%" sh.cue /split C:\Temp
- del C:\Temp\*02.mp3
- )
- del sh.cue
复制代码
怎么让第一个代码调用第二个?里面都有For循环,怕怕....
不循环的话能正常运行的是:- @echo off
- set "mp3DirectCut=C:\Program Files (x86)\mp3DirectCut_2.20\mp3DirectCut.exe"
- echo FILE "C:\test.mp3"> sh.cue
- echo TRACK 01 AUDIO>>sh.cue
- echo INDEX 01 01:10>>sh.cue
- echo TRACK 02 AUDIO>>sh.cue
- echo INDEX 01 03:30>>sh.cue
- "%mp3DirectCut%" sh.cue /split C:\Temp
- del C:\Temp\*02.mp3
-
- del sh.cue
复制代码
你的t1 要替换掉01:10
t2 要替换掉03:30
而遍历的所有mp3文件要替换掉 "C:\test.mp3"
作者: pendave 时间: 2015-1-28 00:07
回复 3# apang
我现在代码整合成这样,可是运行就报错无法生成那个 sh.cue 文件啊- @set @n=0; /* & echo off
-
- set "JS=cscript -nologo -e:jscript"
- set "mp3DirectCut=C:\Program Files (x86)\mp3DirectCut_2.20\mp3DirectCut.exe"
- for /f "tokens=1,2*" %%a in ('dir /b *.mp3^|%JS% "%~0"') do (
- set "Name=%%c"
- set /a h1=%%a/3600,m1=%%a%%3600/60,s1=%%a%%3600%%60
- set /a h2=%%b/3600,m2=%%b%%3600/60,s2=%%b%%3600%%60
- set /a h1+=100,m1+=100,s1+=100,h2+=100,m2+=100,s2+=100
- setlocal enabledelayedexpansion
- set "t1=!m1:~1!:!s1:~1!"
- set "t2=!m2:~1!:!s2:~1!"
- echo,!t1! !t2! !Name!
- echo FILE !Name!> sh.cue
- echo TRACK 01 AUDIO>>sh.cue
- echo INDEX 01 !t1!>>sh.cue
- echo TRACK 02 AUDIO>>sh.cue
- echo INDEX 01 !t2!>>sh.cue
- "%mp3DirectCut%" sh.cue /split C:\Temp
- del C:\Temp\*02.mp3
- del sh.cue
- endlocal
- )
- pause & exit/b & rem */
-
- WMP = new ActiveXObject("WMPlayer.OCX");
- s = "";
- while (!WScript.StdIn.AtEndOfStream) {
- f = WScript.StdIn.ReadLine();
- t = WMP.newMedia(f).getItemInfo("Duration");
- t1 = Math.round(t/4);
- t2 = Math.round(t*3/4);
- s += t1 + " " + t2 + " " + f + "\n";
- }
- WScript.StdOut.Write(s);
复制代码
高手请帮我看看是哪个逻辑出问题了....
!Name! 只是mp3文件的一个属性:文件名? 不是mp3文件本身?
作者: apang 时间: 2015-1-28 01:00
- @set @n=0; /* & echo off
- pushd "F:\Music\"
- set "mp3DirectCut=D:\Program Files\mp3DirectCut\mp3DirectCut.exe"
- set "JS=cscript -nologo -e:jscript"
- for /f "tokens=1,2*" %%a in ('dir /b *.mp3^|%JS% "%~0"') do (
- set "Name=%%c"
- set /a m1=%%a/60+100,s1=%%a%%60+100
- set /a m2=%%b/60+100,s2=%%b%%60+100
- setlocal enabledelayedexpansion
- (
- echo FILE "!Name!" MP3
- echo TRACK 01 AUDIO
- echo INDEX 01 00:00:00
- echo TRACK 02 AUDIO
- echo INDEX 01 !m1:~1!:!s1:~1!:00
- echo TRACK 03 AUDIO
- echo INDEX 01 !m2:~1!:!s2:~1!:00
- )>sheet.cue
- "%mp3DirectCut%" sheet.cue /split
- endlocal
- )
- del "*Track 02.mp3" sheet.cue
- ren "*Track 03.mp3" "*Track 02.mp3"
- pause & exit/b & rem */
-
- WMP = new ActiveXObject("WMPlayer.OCX");
- s = "";
- while (!WScript.StdIn.AtEndOfStream) {
- f = WScript.StdIn.ReadLine();
- t = WMP.newMedia(f).getItemInfo("Duration");
- t1 = Math.round(t/4)
- t2 = Math.round(t*3/4)
- s += t1 + " " + t2 + " " + f + "\n"
- }
- WScript.StdOut.Write(s)
复制代码
作者: pendave 时间: 2015-1-28 01:33
本帖最后由 pendave 于 2015-1-28 01:57 编辑
搞定了,一点点调试后发现问题了
解决了!谢谢- @set @n=0; /* & echo off
-
- set "JS=cscript -nologo -e:jscript"
- set "mp3DirectCut=C:\Program Files (x86)\mp3DirectCut_2.20\mp3DirectCut.exe"
- for /f "tokens=1,2*" %%a in ('dir /b *.mp3^|%JS% "%~0"') do (
- set "Name=%%c"
- set /a h1=%%a/3600,m1=%%a%%3600/60,s1=%%a%%3600%%60
- set /a h2=%%b/3600,m2=%%b%%3600/60,s2=%%b%%3600%%60
- set /a h1+=100,m1+=100,s1+=100,h2+=100,m2+=100,s2+=100
- setlocal enabledelayedexpansion
- rem set "t1=!h1:~1!:!m1:~1!:!s1:~1!"
- rem set "t2=!h2:~1!:!m2:~1!:!s2:~1!"
- set "t1=!m1:~1!:!s1:~1!"
- set "t2=!m2:~1!:!s2:~1!"
- echo,!t1! !t2! !Name!
- echo FILE "!Name!"> sh.cue
- echo TRACK 01 AUDIO>>sh.cue
- echo INDEX 01 00:00>>sh.cue
- echo TRACK 02 AUDIO>>sh.cue
- echo INDEX 01 !t1!>>sh.cue
- echo TRACK 03 AUDIO>>sh.cue
- echo INDEX 01 !t2!>>sh.cue
-
- "%mp3DirectCut%" "!Name!" /normalize /overwrite
- "%mp3DirectCut%" sh.cue /split C:\Temp
- "%mp3DirectCut%" C:\Temp\*.mp3 /autocrop
-
- endlocal
- )
- del "C:\Temp\*Track 02.mp3" sh.cue
- ren "C:\Temp\*Track 01.mp3" "* p1.mp3"
- ren "C:\Temp\*Track 03.mp3" "* p2.mp3"
-
- pause & exit/b & rem */
-
- WMP = new ActiveXObject("WMPlayer.OCX");
- s = "";
- while (!WScript.StdIn.AtEndOfStream) {
- f = WScript.StdIn.ReadLine();
- t = WMP.newMedia(f).getItemInfo("Duration");
- t1 = Math.round(t/4);
- t2 = Math.round(t*3/4);
- s += t1 + " " + t2 + " " + f + "\n";
- }
- WScript.StdOut.Write(s);
复制代码
作者: pendave 时间: 2015-1-28 17:44
本帖最后由 pendave 于 2015-1-28 17:52 编辑
回复 8# apang
我想用你那个JScript代码获取mp3的比特率
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsrch.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP+TechHome/WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP
改了下- b = WMP.newMedia(f).GetItemInfo("Bitrate");
复制代码
可是报错:Microsoft JScript 编译错误:无效字符
怎么回事呢?
想用进这个需求里
[求助]如何用ffmpeg来批量把比特率大于192kbs的mp3文件转成128kbs的?
http://www.bathome.net/viewthrea ... mp;extra=#pid161699
谢谢!
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |