This is a long shot but I’m hoping someone could help with a python script which has one line of ffmpeg code that will not output the required video clips.
For context, I downloaded this script and it is not my own work, it came with another Python script which scans through a folder of Rocket League gameplay videos, looking for moments where a goal has been scored (using tesseract-OCR), and then logs the clip filename and frame into a csv file called “detected.csv”. That part has all worked now I’ve figured it all out! It is the second part, this script is supposed to read the “detected.csv” list of files and frame numbers, to then trim and create the new video clips and output them to a folder. The code looks like this:
import ntpath
import os
detectedGoalList = []
f = open("detected.csv", "r")
for x in f:
tup = x.replace(""[", "").replace("]"", "").split(", ")
print(x)
detectedGoalList.append([tup[0], tup[1]])
for dg in detectedGoalList:
print(dg[0])
input_file = ""{}"".format(dg[0].replace("'", ""))
output_path = "../clips/" + ntpath.basename(dg[0]).replace("'", "").replace(
".mp4", "").replace("Rocket League®_", "").replace("Rocket League™_", "").replace("Rocket
League_", "") + ".clipped.mp4"
start = (int(dg[1]) - int(30 * 10)) / 30
if start < 0:
start = 0
end = (int(dg[1]) / 30) - 3
duration = end - start
os.system("ffmpeg -ss {} -i {} -t {} -c copy {}".format(start, input_file,
duration, output_path))
The script runs instantly and returns no errors. It doesn’t log anything to the terminal. It doesn’t output any new clips. I have 5 mp4 files in the “clips” directory that match in the csv file exactly. The “detected.csv” file contains the following:
"['K:/Gameplay Videos/Rocket League/goals/clips\goal(2).mp4', 1750]"
"['K:/Gameplay Videos/Rocket League/goals/clips\goal(28).mp4', 1200]"
"['K:/Gameplay Videos/Rocket League/goals/clips\goal(3).mp4', 3350]"
"['K:/Gameplay Videos/Rocket League/goals/clips\goal(4).mp4', 3050]"
"['K:/Gameplay Videos/Rocket League/goals/clips\goal(5).mp4', 3500]"
So I’m pretty sure that the final ffmpeg line is the culprit. I understand basic command line ffmpeg syntax but when it’s part of Python code and variables I just can’t figure it out. I see reference to the number “30” a lot – maybe the guy who wrote this had 30fps videos as his source (they were after all Playstation replays), I have 60fps videos. I’ve tried changing those numbers to 60 to no avail.
Any help would be greatly appreciated!
Cheers
Mark