我想在终端中运行此命令:
ffmpeg -i <input-file> -ac 2 -codec:a libmp3lame -b:a 48k -ar 16000 <output-file.mp3>
每 mp3
文件在文件夹中。
输入和输出可以相同(覆盖),但如果这是不可能的,如果有办法获取文件名并附加 _converted
也许?
我不是 bash 专家,但我知道我需要通过管道传输 ls
的结果也许使用变量命令进入 ffmpeg 命令?
最佳答案
您可以尝试以下操作吗,因为我没有 ffpmeg 命令,所以无法测试它。这应该将输出保存到相同的Input_file本身中,更好地在测试文件夹上测试它,一旦对结果满意就可以在实际文件夹上运行。
for file in *.mp3
do
ffmpeg -i "$file" -ac 2 -codec:a libmp3lame -b:a 48k -ar 16000 "temp" && mv "temp" "$file"
done
或者根据OP,您希望将输出_converted
字符串转换为输出文件名,然后尝试执行以下操作。
for file in *.mp3
do
output_file="${file}_converted"
ffmpeg -i "$file" -ac 2 -codec:a libmp3lame -b:a 48k -ar 16000 "$output_file"
done
或者按照 @Gordon Davisson 先生的评论使用以下内容。
for file in *.mp3
do
output_file="${file%.mp3}_converted.mp3"
ffmpeg -i "$file" -ac 2 -codec:a libmp3lame -b:a 48k -ar 16000 "$output_file"
done
关于bash - 如何将文件名通过管道传输到 ffmpeg 命令中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58476778/