[Libav-user] Insert DVDSubtitle dynamically to a TS live Stream

Zohan Le le.zohan.fr at gmail.com
Tue Sep 7 16:02:35 EEST 2021


Hello Community ! (Sorry for my awful English !)

We have a mp4 video we stream with ffmpeg API to a TS Stream.

During this stream we want to add live subtitling in DVDSubtitle format (Or
other one if needed)

For that we create an OutputFormat & FormatContext and then we add 2 Streams
1 For video only
and the second for subtitling with avformat_new_stream

We use AV_CODEC_ID_DVD_SUBTITLE for Subtitle codec
and AV_CODEC_ID_MPEG2VIDEO for video codec

i'll try to insert AVSubtitle Struc to an AVPacket and add it to the
subtitle stream with

                            AVSubtitle* ASubtitle = null;
                            ASubtitle =
(AVSubtitle*)ffmpeg.av_realloc(ASubtitle, (ulong)(sizeof(AVSubtitle)));
                            byte* buf = null;
                            buf = (byte*)ffmpeg.av_realloc(buf,
(ulong)(sizeof(byte) * ms.Length));
                            ASubtitle->pts = currentTime;
                            ASubtitle->start_display_time =
(uint)(currentTime * baseRational.num);
                            ASubtitle->end_display_time =
ASubtitle->start_display_time + (uint)(999 * baseRational.num);
                            ASubtitle->pts =
ffmpeg.av_rescale_q(ASubtitle->pts, ffmpeg.av_get_time_base_q(),
outVideoStream->time_base);
                            ASubtitle->pts +=
ffmpeg.av_rescale_q(ASubtitle->start_display_time, baseRational,
ffmpeg.av_get_time_base_q());
                            ASubtitle->end_display_time -=
ASubtitle->start_display_time;

                                ASubtitle->rects =
(AVSubtitleRect**)ffmpeg.av_realloc(ASubtitle->rects,
(ulong)((ASubtitle->num_rects + 1) * sizeof(AVSubtitleRect)));
                                ASubtitle->rects[0]->data = subData;
                                ASubtitle->rects[0]->type =
AVSubtitleType.SUBTITLE_BITMAP;
                                ASubtitle->rects[0]->h =
subtitleBitmap.Height;
                                ASubtitle->rects[0]->w =
subtitleBitmap.Width;
                                ASubtitle->rects[0]->x = 50;
                                ASubtitle->rects[0]->y = 200;
                                ASubtitle->rects[0]->nb_colors = 4;
                            }

subData is the data of my bitmap sub's

If anyone has an idea ...
Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20210907/4a15bed5/attachment.htm>


More information about the Libav-user mailing list