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
This commit is contained in:
42
duration_diff
Executable file
42
duration_diff
Executable file
@@ -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")
|
||||
Reference in New Issue
Block a user