如何使用 ffmpeg 中的 libavcodec 将 opus 文件解码为 pcm 文件?
How do I decode opus file to pcm file using libavcodec from ffmpeg?
我正在尝试使用 libavcodec.So 将 opus 解码为 pcm 文件,我使用 https://ffmpeg.org/doxygen/trunk/decode_audio_8c-example.html 中的 ffmpeg 示例。我将 AV_CODEC_ID_MP2 更改为 AV_CODEC_ID_OPUS.But 我收到错误消息.
codec = avcodec_find_decoder((AV_CODEC_ID_MP2);
codec = avcodec_find_decoder(AV_CODEC_ID_OPUS);
错误:
codec ./decode_audio ./out.opus ./out.pcm
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
所以我尝试将作品 AV_CODEC_ID_OPUS 更改为 AV_CODEC_ID_MP3 然后再试一次。
codec ./decode_audio ./out.mp3 ./out.pcm
[mp3float @ 0x7fe564002000] Header missing
Error submitting the packet to the decoder
为什么ffmpeg的例子会报错?我该怎么办?
你不能用这种方式解码作品。 mp3包是自定界的,opus不是。这意味着 opus 需要一个容器(通常是 ogg)。必须解析该容器以确定您随后可以解码的 opus 数据包的开始和结束。 libavformat
可用于从文件中读取 AVPackets。
我正在尝试使用 libavcodec.So 将 opus 解码为 pcm 文件,我使用 https://ffmpeg.org/doxygen/trunk/decode_audio_8c-example.html 中的 ffmpeg 示例。我将 AV_CODEC_ID_MP2 更改为 AV_CODEC_ID_OPUS.But 我收到错误消息.
codec = avcodec_find_decoder((AV_CODEC_ID_MP2);
codec = avcodec_find_decoder(AV_CODEC_ID_OPUS);
错误:
codec ./decode_audio ./out.opus ./out.pcm
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
[opus @ 0x7ff361800000] Error parsing Opus packet header.
所以我尝试将作品 AV_CODEC_ID_OPUS 更改为 AV_CODEC_ID_MP3 然后再试一次。
codec ./decode_audio ./out.mp3 ./out.pcm
[mp3float @ 0x7fe564002000] Header missing
Error submitting the packet to the decoder
为什么ffmpeg的例子会报错?我该怎么办?
你不能用这种方式解码作品。 mp3包是自定界的,opus不是。这意味着 opus 需要一个容器(通常是 ogg)。必须解析该容器以确定您随后可以解码的 opus 数据包的开始和结束。 libavformat
可用于从文件中读取 AVPackets。