gpt4 book ai didi

python - PyDub : ffmpeg header missing

转载 作者:行者123 更新时间:2023-12-04 23:04:47 30 4
gpt4 key购买 nike

我做了一个简单的 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

关于python - PyDub : ffmpeg header missing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67881094/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com