【问题标题】:How to get bash script to convert mp3 to wav using ffmpeg working?如何使用 ffmpeg 工作获取 bash 脚本以将 mp3 转换为 wav?
【发布时间】:2017-09-12 00:56:22
【问题描述】:

每次我运行这个脚本时它都不起作用。我得到输出 bash: command not found

我运行 bash -x 来查看问题所在,但我不明白错误

bash -x mp3towav.sh 
+ for f in '*.mp3'
+ ffmpeg -i '' -acodec pcm_s16le -ac 1 -ar .wav
ffmpeg version 3.3 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Trailing options were found on the commandline.
: No such file or directory

脚本是这样的

  1 #!/bin/bash
  2 for f in *.mp3; do ffmpeg -i "$file" -acodec pcm_s16le -ac 1 -ar "${file%.mp3}".wav;done

如果运行更正后的代码,我仍然会收到以下错误:

ffmpeg version 3.3 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Trailing options were found on the commandline.
Input #0, mp3, from 'hiraeth [ep].mp3':
  Duration: 00:23:39.36, start: 0.025057, bitrate: 128 kb/s
    Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
    Metadata:
      encoder         : LAME3.99r
    Side data:
      replaygain: track gain - -4.100000, track peak - unknown, album gain - unknown, album peak - unknown, 
At least one output file must be specified

【问题讨论】:

  • 不应该是for file in *.mp3; do ...吗?在当前代码中,您在循环中使用的是file,而不是f
  • 而且你必须引用*.mp3,否则 Bash 会尝试查找一个字面名称为 *.mp3 的文件。

标签: bash audio ffmpeg type-conversion


【解决方案1】:

解决方案当然在codeforester的评论中:

#!/bin/bash
for file in *.mp3; do
   ffmpeg -i "$file" -acodec pcm_s16le -ac 1 -ar 44100 "${file%.mp3}".wav
done

(LordNeckbeard 每条评论增加 44100) 一些提示:

1) 如果您将脚本拆分为多行,则更容易发现此类错误。

2) 运行bash -x时不要过分关注错误;它在输出上给出命令。那是为了什么。在这种情况下:

+ ffmpeg -i '' -acodec pcm_s16le -ac 1 -ar .wav

从这一行得出的结论是,ffmpeg 以'' 作为输入文件,.wav 作为输出运行。

【讨论】:

  • 这给了我一个错误,说我需要指定我的输出文件。
  • @ADASFA 您的-ar 缺少音频采样率的值。要么删除-ar,输出将尝试使用与输入相同的采样率,或者添加一个适当的值,例如-ar 44100
猜你喜欢
  • 2016-04-22
  • 2014-04-18
  • 2013-04-03
  • 1970-01-01
  • 1970-01-01
  • 2019-03-11
  • 2017-07-06
  • 2017-08-23
  • 2013-01-22
相关资源
最近更新 更多