Search This Blog

Tuesday, September 27, 2022

Exporting SRT file from an existing MP4 file

 I was wrestling with Handbrake to convert multiple large MP4 files into smaller, lower-resolution versions -- I would put the files to be processed into its queue, then specify that I wanted it to include the subtitle track as an option for the output file.

The method indicated in the documentation for Handbrake works so long as I'm doing it for one file at a time, but once I load up a queue and run multiple jobs the subtitle settings just don't seem to work -- the files video components are converted perfectly, but the subtitles don't come across in the new, smaller version of the file.

I gave it an hour trying every combination I could think of and had to give up and try something else.

The easier solution in my case was to process the video files using Handbrake but then to independently generate a SRT for each video file which the user (who'd be using VLC as their player) could load on their own if they wanted to view subtitles.

The answer lay with FFMPEG (again) -- this command would read the (single) subtitle track from my video file and then write it out to a "SRT" file:

ffmpeg -i myvideofile.mp4 -map 0:s:0 myvideofile.srt

I could see that this will get more complicated if the video file had multiple subtitle tracks (for different languages).  In that case you can try and wade through the full index of the video file looking for the correct track by using:

ffmpeg -i myvideofile.mp4

Or, if you're lazy like me, start the video file up in VLC and look for the listing of subtitle options.  You can then guess the correct track to use:

ffmpeg -i m.m4v -map 0:s:0 eng.srt
ffmpeg -i m.m4v -map 0:s:1 ita.srt
ffmpeg -i m.m4v -map 0:s:2 fre.srt