How do I decode opus file to pcm file using libavcodec from ffmpeg?

ぐ巨炮叔叔 提交于 2020-06-16 03:37:09

问题


I am trying to decode opus to pcm file using libavcodec.So,I use ffmpeg example from https://ffmpeg.org/doxygen/trunk/decode_audio_8c-example.html .And I change AV_CODEC_ID_MP2 to AV_CODEC_ID_OPUS.But I get an error.

codec = avcodec_find_decoder((AV_CODEC_ID_MP2);
codec = avcodec_find_decoder(AV_CODEC_ID_OPUS);

error:

    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.

So I try to change opus AV_CODEC_ID_OPUS to AV_CODEC_ID_MP3 and try again.

    codec ./decode_audio ./out.mp3 ./out.pcm            
    [mp3float @ 0x7fe564002000] Header missing
    Error submitting the packet to the decoder

Why does the example from ffmpeg get error?What should I do ?


回答1:


You can't decode opus this way. Mp3 packets are self-delimiting, opus is not. Which means that opus requires a container (usually ogg). That container must be parsed to determine the start and end of an opus packet that you can then decode. libavformat can be used to read AVPackets from the file.



来源:https://stackoverflow.com/questions/62155671/how-do-i-decode-opus-file-to-pcm-file-using-libavcodec-from-ffmpeg

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!