0

I'm trying to merge two (and more in the future) .mkv files that already have subtitles included in them, this means I DO NOT have .srt files that need to be encoded. Let's call the .mkv files intro.mkv and episode.mkv.

However, the way I want to merge them is so a portion of the episode.mkv file is played until a specified timestamp, then intro.mkv plays completely, and after that the rest of episode.mkv.

I've managed to get close with the following code.

import ffmpeg

initial_episode_video = ffmpeg.input('episode.mkv', to='00:00:34.033', hwaccel='cuvid')
intro_video = ffmpeg.input('intro.mkv', hwaccel='cuvid')
remaining_episode_video = ffmpeg.input('episode.mkv', ss='00:00:34.033', hwaccel='cuvid')

full_episode_video = ffmpeg.concat(initial_episode_video, intro_video, remaining_episode_video)

output_video = ffmpeg.output(
    full_episode_video,
    filter_complex='[0:v][0:a][1:v][1:a][2:v][2:a]concat=n=3:v=1:a=1',
    vprofile='main', 
    vcodec='h264_nvenc',
    pix_fmt='yuv420p',
    crf=22,
    map="0:s",
    filename=f'Output/{episode_path}')
ffmpeg.run(output_video)

With this code, the videos are correctly trimmed. The problem is that once intro.mkv starts playing, it doesn't show the subtitles corresponding to it, instead it shows the episode.mkv subtitles corresponding to the '00:00:34.033' timestamp.

My objective is to display the subtitles of intro.mkv, and then, once the full intro is played, continue with the subtitles from episode.mkv.

NOTE: I am aware that I am re-encoding both the episode.mkv and intro.mkv files. If possible, I'd prefer if it only re-encodes episode.mkv, since intro.mkv only needs to be re-encoded once (I can do that individually). I am re-encoding to go from H.264 Hi 10 to H.264 main profile.

Eeshe
  • 3
  • 1

0 Answers0