我已经完成了这个批处理文件应该转换给定文件夹中的所有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
我认为这是因为文件名和文件夹名中的空格,但我实际上并不知道......有人可以验证并找到正确的代码吗?
...谢谢
答案 0 :(得分: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
和FOLD
DEST
设置时%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
注意到我没有更改"%dest%%%~nxf"
命令 - 您知道所需的参数。命令像往常一样回应。
如果您想使用常量输出扩展名,例如.MP3,请将"%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"
修改批量输出:
{{1}}