From 56577d09aadc50a2c80e6018b5fe9c266cd74ef0 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sat, 16 Aug 2025 10:39:02 +1000 Subject: [PATCH] util to take a footy mpeg and with appropriate "trimmed" start/end times, it will work out the ffmpeg line as a start and duration --- duration_diff | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 duration_diff diff --git a/duration_diff b/duration_diff new file mode 100755 index 0000000..1a7b860 --- /dev/null +++ b/duration_diff @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +import argparse +from datetime import datetime + +def time_difference(time1, time2): + # Define the time format + time_format = "%H:%M:%S" + + # Convert strings to datetime objects + t1 = datetime.strptime(time1, time_format) + t2 = datetime.strptime(time2, time_format) + + # Calculate the difference between the two times + delta = t2 - t1 if t2 > t1 else t1 - t2 + + # Extract total seconds from the timedelta object + total_seconds = int(delta.total_seconds()) + + # Calculate hours, minutes, and seconds from the total seconds + hours, remainder = divmod(total_seconds, 3600) + minutes, seconds = divmod(remainder, 60) + + # Return the formatted time difference with leading zeros + return f"{hours:02}:{minutes:02}:{seconds:02}" + +if __name__ == "__main__": + # Set up command-line argument parsing + parser = argparse.ArgumentParser(description="Calculate the difference between two times in hh:mm:ss format.") + + # Add positional arguments for the two time durations + parser.add_argument("time1", type=str, help="The first time in hh:mm:ss format") + parser.add_argument("time2", type=str, help="The second time in hh:mm:ss format") + parser.add_argument("video", type=str, help="video") + + # Parse the command-line arguments + args = parser.parse_args() + + # Calculate and print the time difference + difference = time_difference(args.time1, args.time2) + print(f"Difference: {difference}") + print(f"ffmpeg -ss {args.time2} -i {args.video} -to {difference} -c copy output.mp4")