I was trying to use FFmpeg to split videos into 30s segments, here is the full code:
from tkinter import filedialog, Tk
import subprocess
import os
Tk().withdraw()
path_to_video = filedialog.askopenfilename()
print(f"Path to video is: {path_to_video}")
segment_duration = input("Enter each segment duration in second: ")
os.chdir(os.path.dirname(__file__))
print(f"-i \"{path_to_video}\" -c copy -map 0 -segment_time {segment_duration} -f segment -reset_timestamps 1 Output_%03d.mp4")
subprocess.run([
"E:\\Programs\\FFmpeg\\ffmpeg-master-latest-win64-gpl\\bin\\ffmpeg.exe",
"-i", path_to_video,
"-c:", "copy",
"-map", "0",
"-segment_time", segment_duration,
"-f", "segment",
"-reset_timestamps", "1",
"Output_%03d.mp4"])
But it actually splits it into videos with really low precision, how can I fix it? Another post regarding this topic suggested adding this line:
"-force_key_frames", f"expr:gte(t,n_forced*{segment_duration})",
But it didn't really work...
source https://stackoverflow.com/questions/74551957/ffmpeg-not-splitting-videos-precisely
Comments
Post a Comment