[Libav-user] Pulling valid subtitle from lavfi

Deron deron at pagestream.org
Mon Dec 18 18:10:33 EET 2023


Hello,

I have a streaming app I wrote that started from the transcode example 
and grew.

So I'm trying to add subtitle support now, and it mostly works. From a 
file that contains subtitles, I get valid subtitle packets with 
avPacket->data that contains valid text and webvtt outputs valid data.

However, another type of input I am trying to reproduce is from this 
ffmpeg command that I use that works to extract video/audio and 
subtitles from a local tv station tuner pickup.

     ffmpeg -f lavfi -i 
movie=/dev/dvb/adapter0/dvr0:f=mpegts:s=dv+da[out0+subcc][out1] test.mkv

So the only difference in my code was the addition of:

     avdevice_register_all();

And finding the lavfi input format:

     in_format = av_find_input_format("lavfi");

And passing the format to the avformat_open_input function.

The video and audio comes out just fine, but the subtitle packets all 
have a length of 30 bytes, and the data appears to be garbage (well, 
could be raw data I've not explored that).

The only thing I can think of is the need for something unique when 
setting up the AVCodecContext for the subtitle besides just

     const AVCodec *dec = 
avcodec_find_decoder(dec_stream->codecpar->codec_id)

     AVCodecContext *codec_ctx = avcodec_alloc_context3(dec)

     avcodec_parameters_to_context(codec_ctx, dec_stream->codecpar)

     avcodec_open2(codec_ctx, dec, NULL);


Thanks for any hints!

Deron



More information about the Libav-user mailing list