python - 使用 PyDub 时出错 : pcm_s8 codec not supported in WAVE format

标签 python audio ffmpeg wave

试图读入 WAVE 文件。

Pydub 在过去几个月里一直运行良好,直到我遇到无法导入 Python 的特定 WAVE 文件格式(但在 windows 媒体播放器和其他播放器上播放时没有问题)。

from pydub import AudioSegment

file = r"NICE_Dev.wav"
print(utils.mediainfo(file))
try:
    data = AudioSegment.from_file(file)

except Exception as e:
    print(e)

错误信息是:

ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8.3.1 (GCC) 20190414
  configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --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-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, wav, from 'NICE_Dev.wav':
  Duration: 00:25:55.39, bitrate: 64 kb/s
    Stream #0:0: Audio: pcm_mulaw ([7][0][0][0] / 0x0007), 8000 Hz, mono, s16, 64 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_mulaw (native) -> pcm_s8 (native))
Press [q] to stop, [?] for help
[wav @ 00000265db3c1bc0] pcm_s8 codec not supported in WAVE format
Could not write header for output file #0 (incorrect codec parameters ?): Function not implemented
Error initializing output stream 0:0 -- 
Conversion failed!

我相信这是由于编码 pcm_s8,但我无法弄清楚如何解决这个问题,使用“utils.mediainfo”的音频文件的详细信息是:

{'index': '0', 'codec_name': 'pcm_mulaw', 'codec_long_name': 'PCM mu-law / 
G.711 mu-law', 'profile': 'unknown', 'codec_type': 'audio', 'codec_time_base': 
'1/8000', 'codec_tag_string': '[7][0][0][0]', 'codec_tag': '0x0007', 
'sample_fmt': 's16', 'sample_rate': '8000', 'channels': '1', 'channel_layout': 
'unknown', 'bits_per_sample': '8', 'id': 'N/A', 'r_frame_rate': '0/0', 
'avg_frame_rate': '0/0', 'time_base': '1/8000', 'start_pts': 'N/A', 
'start_time': 'N/A', 'duration_ts': '12443128', 'duration': '1555.391000', 
'bit_rate': '64000', 'max_bit_rate': 'N/A', 'bits_per_raw_sample': 'N/A', 
'nb_frames': 'N/A', 'nb_read_frames': 'N/A', 'nb_read_packets': 'N/A', 
'DISPOSITION': {'default': '0', 'dub': '0', 'original': '0', 'comment': '0', 
'lyrics': '0', 'karaoke': '0', 'forced': '0', 'hearing_impaired': '0', 
'visual_impaired': '0', 'clean_effects': '0', 'attached_pic': '0', 
'timed_thumbnails': '0'}, 'filename': 'NICE_Dev.wav', 'nb_streams': '1', 
'nb_programs': '0', 'format_name': 'wav', 'format_long_name': 'WAV / WAVE 
(Waveform Audio)', 'size': '12443174', 'probe_score': '99'}

最佳答案

问题已解决 - 不知道为什么,但标准输入不适用于某些 WAV 编码,通过使用未记录的方法 from_file_using_temporary_files() 解决

关于python - 使用 PyDub 时出错 : pcm_s8 codec not supported in WAVE format,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57720320/

相关文章:

python - 将字符串传递给数据框 iloc

python - 尽管使用 Tor 和 Privoxy,页面仍然获取我的 IP

python - python中2个列表的3D插值

actionscript-3 - ffprobe/ffmpeg : know if a input is a video, 图像或音频

java - "audio/mpeg"某些文件的流 api 无法播放某些文件?

java - 在 java 进程中运行 ffmpeg 命令在 waitFor() 中挂起

python - django在模型之间建立正确的关系

java - 通过按钮事件停止声音

ffmpeg2theora 参数超出范围

php - 使用 ffmpeg 从具有 ken burns 效果的图像生成视频