Discussion:
[Libav-user] decode audio example broken
drwho
2018-11-21 19:47:32 UTC
Permalink
Hello,

The audio decoder example below fails to decode any file I've tried
(mp3, opus, wav).....

[mp2 @ 0x55d075c3d780] Header missing
Error submitting the packet to the decoder

https://libav.org/documentation/doxygen/master/decode__audio_8c_source.html

Jon
Paul B Mahol
2018-11-21 20:02:30 UTC
Permalink
Post by drwho
Hello,
The audio decoder example below fails to decode any file I've tried
(mp3, opus, wav).....
Error submitting the packet to the decoder
https://libav.org/documentation/doxygen/master/decode__audio_8c_source.html
Wrong project link, This is FFmpeg, not Libav.
drwho
2018-11-21 20:18:50 UTC
Permalink
Hi Paul,

Let me change my issue then....FFmpeg's demux and decoding example uses
deprecated APIs (avcodec_decode_audio4
<https://ffmpeg.org/doxygen/3.3/group__lavc__decoding.html#gaaa1fbe477c04455cdc7a994090100db4>)

https://ffmpeg.org/doxygen/3.3/demuxing_decoding_8c-example.html#a93
Post by Paul B Mahol
Post by drwho
Hello,
The audio decoder example below fails to decode any file I've tried
(mp3, opus, wav).....
Error submitting the packet to the decoder
https://libav.org/documentation/doxygen/master/decode__audio_8c_source.html
Wrong project link, This is FFmpeg, not Libav.
_______________________________________________
Libav-user mailing list
http://ffmpeg.org/mailman/listinfo/libav-user
Jaka Bac
2018-11-21 20:13:03 UTC
Permalink
Post by drwho
Hello,
The audio decoder example below fails to decode any file I've tried
(mp3, opus, wav).....
Error submitting the packet to the decoder
https://libav.org/documentation/doxygen/master/decode__audio_8c_source.html
Jon
Hello,

The audio decoding example specifically uses the MP2 audio codec to decode
the audio.
It does this:
codec = avcodec_find_decoder(AV_CODEC_ID_MP2);

For more general example you can look at:
https://www.ffmpeg.org/doxygen/trunk/demuxing_decoding_8c-example.html

Jaka
drwho
2018-11-21 20:30:54 UTC
Permalink
Post by drwho
Hello,
The audio decoder example below fails to decode any file I've tried
(mp3, opus, wav).....
Error submitting the packet to the decoder
https://libav.org/documentation/doxygen/master/decode__audio_8c_source.html
Jon
Hello,
The audio decoding example specifically uses the MP2 audio codec to
decode the audio.
codec = avcodec_find_decoder(AV_CODEC_ID_MP2);
Hi Jaka,

I've tried changing it to

AV_CODEC_ID_MP3

error = [mp3 @ 0x56136ad2f780] Header missing

AV_CODEC_ID_OPUS

error = [opus @ 0x55caa0cb7200] Error parsing Opus packet header.

I've noticed that the packet size is always 0 after calling
av_parser_parse2().  It would be nice to have an example for
avcodec_send_packet() and avcodec_receive_frame() that works.

Jon
Jaka Bac
2018-11-21 20:40:48 UTC
Permalink
Post by drwho
Post by drwho
Hello,
The audio decoder example below fails to decode any file I've tried
(mp3, opus, wav).....
Error submitting the packet to the decoder
https://libav.org/documentation/doxygen/master/decode__audio_8c_source.html
Jon
Hello,
The audio decoding example specifically uses the MP2 audio codec to decode
the audio.
codec = avcodec_find_decoder(AV_CODEC_ID_MP2);
Hi Jaka,
I've tried changing it to
AV_CODEC_ID_MP3
AV_CODEC_ID_OPUS
I've noticed that the packet size is always 0 after calling
av_parser_parse2(). It would be nice to have an example for
avcodec_send_packet() and avcodec_receive_frame() that works.
Jon
Hi Jon,

The decode example here:
https://www.ffmpeg.org/doxygen/trunk/decode_audio_8c-example.html
uses the new API.

But you have to be aware that it does not involve libavformat for demuxing
and it expects the "raw" bitstream for the specified codec, if you are
opening a file which has a wrapper, you should use libavformat to first
extract the packets and then just send the packets to the codec.

The deprecated API will still work. For a working example you need to
combine the decode example linked above and the demuxing/decoding example.
The new API is nothing special, you can find example usage here:
https://blogs.gentoo.org/lu_zero/2016/03/29/new-avcodec-api/

Jaka
drwho
2018-11-22 16:52:34 UTC
Permalink
Post by Jaka Bac
Hi Jon,
https://www.ffmpeg.org/doxygen/trunk/decode_audio_8c-example.html
uses the new API.
But you have to be aware that it does not involve libavformat for
demuxing and it expects the "raw" bitstream for the specified codec,
if you are opening a file which has a wrapper, you should use
libavformat to first extract the packets and then just send the
packets to the codec.
Hi Jaka,

That was the issue...I was sending the decoder a container and not the
raw bitstream.  I guess I assumed av_parse_parse2() would demux.

I tried the old api demux and decode example....

https://www.ffmpeg.org/doxygen/trunk/demuxing_decoding_8c-example.html

Should I be able to send a wav file to this example and get correct
output (it maybe expects video+audio)?

./example input.wav video.mkv output.wav

The output is distorted.  When I compare input.wav and output.wav
(beginning of each attached) they are identical until offset / position
0x82C.  The input is a 440Hz sine wave, so it is easy to see the
periodic data in the hex viewer.  It looks like every so often the
output stream skips over parts of the sign wave (at for example offset /
position 0x82C).  Maybe the decoder is doing some time
re-synchronization?  My application is audio only and has the same
behavior if I use the new or old apis.  I thought I could use the
example to compare against to see where I went wrong.

built on Debian 9.....

gcc example.c -lavcodec -lavformat -lavutil -o example

Loading...