ffmpeg – Combine two videos in python and get frame-precision duration of the end of the first clip within the new combined clip

I am trying to combine two videos (mov files) in Python and get the frame-precision duration of the end of the first clip within the new, combined clip so that I can skip to the end of the first clip/start of the second clip within the newly combined clip.

Here is how I combine the two videos.

def concatenate_videos(video1_path, video2_path, output_path):
    input1 = ffmpeg.input(video1_path)
    input2 = ffmpeg.input(video2_path)

    vid = '/Users/johnlawlor/projects/yesand/backend/media/videos/vid.mp4'
    aud = '/Users/johnlawlor/projects/yesand/backend/media/videos/aud.mp3'
    ffmpeg.concat(input1, input2, n=2, v=1, a=0).output(vid).run()
    ffmpeg.concat(input1, input2, n=2, v=0, a=1).output(aud).run()

    input1 = ffmpeg.input(vid)
    input2 = ffmpeg.input(aud)
    ffmpeg.concat(input1, input2, n=2, v=1, a=1).output(output_path).run()

Then I get the duration of the first clip.

def _get_duration(local_file_path):
    new_addition_metadata = ffmpeg.probe(local_file_path)
    duration = float(new_addition_metadata['streams'][0]['duration'])
    return duration

However, when I skip to the time that is returned by this logic, it skips to a few frames before the actual start of the second clip, so I get a jerky effect that seems like a bug.

I am currently using ffmpeg-python. I am open to any other Python libraries.

Any ideas?

Thanks!

Read more here: Source link