[Libav-user] Speeding up codec detection of raw bitstream

Wiebe Cazemier wiebe at halfgaar.net
Sun Feb 11 20:09:19 EET 2018


----- Original Message -----
> From: "Wiebe Cazemier" <wiebe at halfgaar.net>
> To: libav-user at ffmpeg.org
> Sent: Sunday, 11 February, 2018 12:51:01
> Subject: [Libav-user] Speeding up codec detection of raw bitstream

> Hi,
> 
> I'm working on an application for a hardware device I built. In essence, I
> obtain raw data from an optical receiver, which can be AC3, DTS, etc, and use
> ffmpeg to decode this into multi-channel analog output. It all works, but I was
> wondering what I can do to speed up the detection of the codec, especially if
> header packets are missed (because it captures mid-stream).
> 
> To give ffmpeg IO, I make my own AVIOContext [1] with a callback function that
> reads from a semaphore controlled buffer. I assign that to avFormatContext->pb
> [2]. Then I open the stream with:
> 
>  avformat_open_input(&avFormatContext, NULL, NULL, NULL) [3]
> 
> This function blocks until a good codec is detected (or gives up?). Especially
> for DTS, this can take a very long time, especially when it missed headers.
> 
> Is there a way to speed this up? Would it help for instance to not use
> av_register_all() and avcodec_register_all()? If so, how and what do I register
> what I need (documentation is unclear to me; it doesn't give examples).
> 
> If there is any information in the original s/pdif bitstream, that is lost. The
> DIR9001 chip only outputs the contents.
> 
> Regards,
> 
> Wiebe
> 
> 
> 
> [1] http://ffmpeg.org/doxygen/trunk/structAVIOContext.html
> [2] http://ffmpeg.org/doxygen/trunk/structAVFormatContext.html
> [3]
> http://ffmpeg.org/doxygen/3.4/group__lavf__decoding.html#ga31d601155e9035d5b0e7efedc894ee49

Correction, it's the following line that takes a while:

  avformat_find_stream_info(avFormatContext, NULL);

In the docs I find this note with that function: "TODO: Let the user decide somehow what information is needed so that we do not waste time getting stuff the user does not need.
".

Still any options available to speed this up?


More information about the Libav-user mailing list