Opened 2 years ago

Last modified 2 years ago

#5781 reopened enhancement

Improve documentation and examples for AVCodecParameters related functions

Reported by: patacca Owned by:
Priority: wish Component: documentation
Version: git-master Keywords:
Cc: cirrus, jamrial Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
Bug previously opened on mpd bug tracker: https://bugs.musicpd.org/view.php?id=4564 (see cirrus's comment https://bugs.musicpd.org/view.php?id=4564#c10084)

When decoding a m4a file avcodec_send_packet fails if the AVCodecContext instance is created via avcodec_alloc_context3.

How to reproduce:
See mpd code:
http://git.musicpd.org/cgit/master/mpd.git/commit/?id=8825393660b95664141ce818089359e1edd612a3
http://git.musicpd.org/cgit/master/mpd.git/tree/src/decoder/plugins/FfmpegDecoderPlugin.cxx?h=v0.19.x#n497

Change History (7)

comment:1 Changed 2 years ago by jamrial

Looks like they are not copying codec parameters from the AVStream.AVCodecParameters struct to the avcodec_alloc_context3 allocated context before calling avcodec_open2.
The function avcodec_parameters_to_context should be used for this purpose.

Can't really test but it could be the source of the problem.

comment:2 follow-up: Changed 2 years ago by pritambaral

I can confirm that jamrial's suggestion works.

comment:3 in reply to: ↑ 2 Changed 2 years ago by jamrial

  • Resolution set to invalid
  • Status changed from new to closed

Replying to pritambaral:

I can confirm that jamrial's suggestion works.

Could you report this to MPD's developers, then?

Thanks for testing.

comment:4 follow-up: Changed 2 years ago by cirrus

jamrial, I can't find documentation on this requirement in the FFmpeg API documentation. Quite contrary, none of the code samples has this call.

I'm not quite happy with the situation. I closed the bug report on the MPD bug tracker as an apparent FFmpeg bug, because I couldn't find anything that's wrong with MPD.

This looks like a secret trick, but it shouldn't be secret. Did I miss something?

comment:5 in reply to: ↑ 4 Changed 2 years ago by jamrial

  • Component changed from undetermined to documentation
  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Type changed from defect to enhancement

Replying to cirrus:

jamrial, I can't find documentation on this requirement in the FFmpeg API documentation. Quite contrary, none of the code samples has this call.

If you check ffplay.c and ffprobe.c you'll see this in action (ffmpeg.c has yet to be updated to this API).

Similarly, i recently pushed a patch for the demuxing_decoding example as commit bba6a03b2816d805d44bce4f9701a71f7d3f8dad.

I'm not quite happy with the situation. I closed the bug report on the MPD bug tracker as an apparent FFmpeg bug, because I couldn't find anything that's wrong with MPD.

This looks like a secret trick, but it shouldn't be secret. Did I miss something?

No, you didn't. The doxygen documentation in avcodec.h for avcodec_open2() doesn't mention it because an input AVStream is not required unless you're demuxing with libavformat.
I agree it should be mentioned somewhere, though.

Basically, since AVStream.AVCodecContext (which has all the stream's parameters already filled) shouldn't be used anymore, the manually allocated AVCodecContext needs to be filled with said parameters in some way, and as its doxy states that's what the above function does.

Last edited 2 years ago by jamrial (previous) (diff)

comment:6 Changed 2 years ago by jamrial

  • Cc cirrus jamrial added
  • Summary changed from avcodec_send_packet() fails with m4a files when AVCodecContext is created with avcodec_alloc_context3() to Improve documentation and examples for AVCodecParameters related functions

comment:7 Changed 2 years ago by cehoyos

  • Priority changed from normal to wish
Note: See TracTickets for help on using tickets.