0

我已经完成了这个批处理文件,它应该转换给定文件夹中的所有 mp3 文件,但是,我不知道为什么,它不起作用......

这是代码:

@echo off
title Converting...

set fold=C:\Users\Username\Music\Music to convert\
set ext=*.mp3
set dest=C:\Users\Username\Music\Converted Music\

for %%f in (%fold%%ext%) do ffmpeg -i %%f -b 192k %dest%%%f

pause>nul
exit

我认为这是因为文件名和文件夹名称中的空格,但我实际上并不知道......有人可以验证并找出正确的代码吗?

谢谢...

4

1 回答 1

1

简单的。

for %%f in ("%fold%%ext%") do ffmpeg -i "%%f" -b 192k "%dest%%%~nxf"

(修改版)

这是我的测试批次

@echo OFF
SETLOCAL
REM title Converting...

set fold=U:\Users\Username\Music\Music to convert\
set ext=*.mp3
set dest=U:\Users\Username\Music\Converted Music\

:: This makes the directories, then creates two dummy files
:: only used for testing.

MD "%fold%"
MD "%dest%"
dir>"%fold%file1.mp3"
dir>"%fold%file two.mp3"

for %%f in ("%fold%%ext%") do ECHO ffmpeg -i "%%f" -b 192k "%dest%%%~nxf"

最后ECHO一行是显示将要执行的内容。验证后,删除ECHO关键字以激活FFMPEG命令。

%%~nxf是文件名+扩展名%%f

结果:

ffmpeg -i "U:\Users\Username\Music\Music to convert\file1.mp3" -b 192k "U:\Users\Username\Music\Converted Music\file1.mp3"
ffmpeg -i "U:\Users\Username\Music\Music to convert\file two.mp3" -b 192k "U:\Users\Username\Music\Converted Music\file two.mp3"

嗯......也许你需要USERNAME在设置FOLDDEST更换%username%


修改为添加对多种文件类型的处理

@echo OFF
SETLOCAL
REM title Converting...

set fold=U:\Users\Username\Music\Music to convert\
set ext=*.mp3 *.wma *.m4a
set dest=U:\Users\Username\Music\Converted Music\

:: This makes the directories, then creates dummy files

MD "%fold%"
MD "%fold%subdir"
MD "%dest%"
dir>"%fold%file1.mp3"
dir>"%fold%file two.mp3"
dir>"%fold%file3.wma"
dir>"%fold%subdir\file four.wma"

 for /r "%fold%" %%f in (%ext%) do ECHO ffmpeg -i "%%~ff" -b 192k "%dest%%%~nxf"

请注意,我没有更改FFMPEG命令 - 您知道您需要的参数。命令像往常一样回响。

如果您想使用恒定的输出扩展名,例如 .MP3,请更改"%dest%%%~nxf""%dest%%%~nf.MP3"

修改后的批量输出:

ffmpeg -i "U:\Users\Username\Music\Music to convert\file1.mp3" -b 192k "U:\Users\Username\Music\Converted Music\file1.mp3"
ffmpeg -i "U:\Users\Username\Music\Music to convert\file two.mp3" -b 192k "U:\Users\Username\Music\Converted Music\file two.mp3"
ffmpeg -i "U:\Users\Username\Music\Music to convert\file3.wma" -b 192k "U:\Users\Username\Music\Converted Music\file3.wma"
ffmpeg -i "U:\Users\Username\Music\Music to convert\subdir\file four.wma" -b 192k "U:\Users\Username\Music\Converted Music\file four.wma"
于 2013-04-23T15:17:43.903 回答