I've been trying to get this darn programming run since last night and cannot seem to get anything to work. I want to first trim the video and then resize the video. I'm reading which video and what to give the final name from a text file, over 780 lines long, quite a few videos.
Thus far with every idea under the sun I have tried, subprocess and os.system, I can't get anything more than error statements or right now all I get is no file creation of any kind. How the heck do I get this to work correctly?
import ffmpeg
import subprocess
import os
os.chdir('/home/Downloads/SRs/')
a = open('SRt.txt', 'r')
b = a.readlines()
a.close()
for c in range(0, len(b)-1):
words = list(b[c].split(" "))
d = len(words)
e = words[d-1]
f = b[c].replace(e, 'FR' + str(c) + '.mp4')
words[d-1] = 'FR' + str(c) + '.mp4'
print(f)
subprocess.call(f, shell=True)
subprocess.call([
'ffmpeg',
'-i',
"'FR' + str(c) + '.mp4'",
'-vf scale=320:240',
words[d-1],
])
Here are some examples of what the original file would look like:
ffmpeg -i SR.mp4 -ss 00:00:00 -to 00:01:22 -c:v copy -a copy CPH.mp4
ffmpeg -i SR.mp4 -ss 00:01:24 -to 00:02:58 -c:v copy -a copy CG.mp4
ffmpeg -i SR.mp4 -ss 00:02:59 -to 00:05:41 -c:v copy -a copy CSGP.mp4
Nothing fancy just separating video in its own individual segments and then resaving it before resizing it.
I tried:
z=subprocess.call(f, shell=True, stdout=subprocess.PIPE)
print(z)
But all I get is '1'.
When I changed it to:
z=subprocess.call(f, shell=True, stderr=subprocess.PIPE)
print(z)
All I get is '1'.
Maybe I'm doing something wrong.
Based on how I understand your problem, here is what I came up with. My system does not have ffmpeg installed, nor do I have any video to test out, so I comment out the
subprocess.run()line. All do is to transform the lines from the text fileSRt.txtinto commands which you can invoke.Content of my sample SRt.txt
Output:
Note: If you don't want the
-vf scale=320:240, part, comment it out