[Libav-user] How can I programmatically add .srt subtitle file to MP4 file

Asaf Kave kaveasaf at gmail.com
Sun Mar 6 10:33:23 EET 2022


On Sun, Feb 27, 2022 at 10:19 AM Strahinja Radman <dr.strashni at gmail.com>
wrote:

>
>
> On Sun, 27 Feb 2022 at 09:13, Asaf Kave <kaveasaf at gmail.com> wrote:
>
>>
>>
>> On Mon, Feb 21, 2022 at 6:07 PM Asaf Kave <kaveasaf at gmail.com> wrote:
>>
>>> Hi All,
>>>
>>> I want to embed .srt file to my MP4 output file using code, *not CLI*,
>>> I didn't find any good example for that, the only example I have is the
>>> remuxing.c demo.
>>>
>>> What is the best way to do it?
>>> 1) In the remuxing demo, I see that using libformat I can write chunks
>>> of the subtitles file ( using av_interleaved_write_frame function see line
>>> 169
>>> https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/remuxing.c).
>>> 2) Can I use avcodec_encode_subtitle from libavcodec to do it?
>>> 3) using complex filters?
>>>
>>> Thanks in advance
>>> Asaf
>>>
>>
>> Anyone?
>> _______________________________________________
>> Libav-user mailing list
>> Libav-user at ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/libav-user
>>
>> To unsubscribe, visit link above, or email
>> libav-user-request at ffmpeg.org with subject "unsubscribe".
>
>
> Hello,
>
> You should just be able to load the subtitle and remux it with the video.
> So algorithm would be
> 1. Open video and subtitle
> 2. Open new output file and add two streams (subtitle and video)
> 3. Read packets from video and subtitle using av_read_frame() which will
> give you AVPacket*
> 4. Send those packets to av_interleaved_write_frame()
> 5. Close the file (very important for some containers)
>
>>
> Kind regards,
> Strahinja
>
>
>> --
>
> Regards
> Strahinja Radman
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
>

Thank you  Strahinja,
I am going with your approach, but still have some issues with subtitles
formatting and style, because MP4 uses only "mov_text", I need to
transcode my subtitles, and I saw that there is a lack of code in the
"movtextenc.c".

Asaf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20220306/cb9f4fa4/attachment.htm>


More information about the Libav-user mailing list