I'm using MakeMKV to create a digital copy of my BluRay discs and have created a script to do some processing on the resulting MKV file:
- resample (and downscale if wanted) the video
- convert a single audio track to both AAC and AC3 (for each language I want) and discard the "input" audio track(s)
- copy all subtitles for specific languages
- copy chapter marks
I want to extend the script to burn in a single PGS subtitle track. However, when I add the proper overlay filter the resulting burned in subtitles are out of sync.
In general, the script uses mkvextract to extract the relevant video and audio tracks and uses ffmpeg to convert these to new tracks. After conversion all output tracks are merged using mkvmerge.
For the subtitle handling I use mkvextract to extract the proper subtitle track to a .sup file and pass this as an additional input to ffmpeg:
ffmpeg -i ./title_t00/in/title_t00.mkv.h264 \
-i ./title_t00/in/title_t00.mkv.en.sup \
-codec:v libx264 \
-filter_complex "[0:v][1:s]overlay[v1]; [v1]scale=w=-2:h=480:flags=gauss[v2]"\
-map "[v2]" \
-sws_flags gauss \
-crf 10 \
./title_t00/out/title_t00.mkv.h264
The filter takes the video track from the first input and the subtitle track from the second input and overlay both. This results in a new video stream v1 which is passed through the scale filter and the result is saved.
As said, the overlay works but the subtitles are out of sync. Is there a way I can properly sync them?
Or is there some magic ffmpeg invocation that can do it all in one pass?
mediainfothe videotrack is 29:20 long, the subtitle track 28:15. So I guess I need to add some time shift in the mix. How can this be determined automatically?