Files
bin/duration_diff

43 lines
1.6 KiB
Python
Executable File

#!/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")