问题
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