python - PyDub:缺少 ffmpeg 标头
问题描述
我做了一个简单的 Python 程序,在 mp3 文件的开头添加了短暂的停顿
import os
from pydub import AudioSegment
AUDIO_DIR = 'C:\\Users\\Ray\\Downloads\\sentence-audio'
OUT_DIR = 'C:\\Users\\Ray\\Downloads\\out-audio'
pause = AudioSegment.silent(duration=400)
for fname in os.listdir(AUDIO_DIR):
print(f'Processing {fname}')
newf = os.path.join(OUT_DIR, os.path.basename(fname))
if os.path.isfile(newf):
print(f'{fname} exists')
continue
audio = AudioSegment.from_mp3(os.path.join(AUDIO_DIR, fname))
new = pause + audio
new.export(newf, format='mp3')
print(f'{fname} lengthened')
运行此程序时,我收到以下针对特定 mp3 文件的错误消息
Traceback (most recent call last):
File "C:\Users\Ray\Downloads\lengthen.py", line 16, in <module>
audio = AudioSegment.from_mp3(os.path.join(AUDIO_DIR, fname))
File "C:\Python39\lib\site-packages\pydub\audio_segment.py", line 796, in from_mp3
return cls.from_file(file, 'mp3', parameters=parameters)
File "C:\Python39\lib\site-packages\pydub\audio_segment.py", line 773, in from_file
raise CouldntDecodeError(
pydub.exceptions.CouldntDecodeError: Decoding failed. ffmpeg returned error code: 1
Output from ffmpeg/avlib:
ffmpeg version git-2020-04-03-52523b6 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9.3.1 (GCC) 20200328
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
libavutil 56. 42.102 / 56. 42.102
libavcodec 58. 77.101 / 58. 77.101
libavformat 58. 42.100 / 58. 42.100
libavdevice 58. 9.103 / 58. 9.103
libavfilter 7. 77.101 / 7. 77.101
libswscale 5. 6.101 / 5. 6.101
libswresample 3. 6.100 / 3. 6.100
libpostproc 55. 6.100 / 55. 6.100
[mp3float @ 0000016489995380] Header missing
Last message repeated 71 times
[mp3 @ 000001648998b500] decoding for stream 0 failed
[mp3 @ 000001648998b500] Could not find codec parameters for stream 0 (Audio: mp3 (mp3float), 0 channels, fltp): unspecified frame size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mp3, from 'C:\Users\Ray\Downloads\sentence-audio\354.mp3':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Audio: mp3, 0 channels, fltp
Stream mapping:
Stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native))
Press [q] to stop, [?] for help
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
[mp3float @ 0000016489995800] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
...
起初我以为 mp3 文件已损坏,因此无法播放。但是,当我在媒体播放器中播放文件时,一切正常。
我不知道如何解决这个问题。有什么解决方法吗?
解决方案
我认为我们需要更多有关您的音频文件的信息。尝试将它们转换为wav
文件而不是使用 mp3。这可能对您更有效。
ffmpeg -i input.mp3 output.wav
推荐阅读
- cassandra - 如何在不知道我会找到什么的情况下查询 Cassandra?
- r - 如何将带有矢量条目的数据框导出到 CSV 文件中?
- ionic-framework - 在从第 2 页导航到第 1 页期间可见页脚
- visual-studio-code - 如何从键盘*退出* VSCode 中的多光标模式?
- php - 我无法在 php 中按 utf8 编码值(if-else)
- python - 如何在 PyQt4 中相对于标签大小的变化保持按钮不变
- c# - 捕获 DllNotFoundException 不使用 Phidget API
- magento2 - 如何在 Magento 2 的 FishPig 中获取当前的 WordPress 类别?
- html - 如何从包含的jsp更改jsp基本页面中body标签的类
- visual-studio-code - 如何通过 VS Code 的 liveshare 共享终端重新加载服务器的更改