Greetings all,
Ok. I’m admittedly stretching my limited python skills here but, I had an opportunity to try and solve a work related problem with some code and have been giving it the old college try using what I’ve learned so far. I can’t seem to formulate the “for loop” in the “encode_all” function below correctly tho. Here’s what I’ve done so far:
import subprocess, sys, os
def encode_one(in_file, out_file): # This works as expected
process = "ffmpeg -i {} {} ".format(in_file, out_file)
subprocess.run(process, shell=True)
def encode_all(): # This doesn’t work as expected
print(" >>> Entering function: ") # debug check
cwd = os.getcwd
print("cwd = %s " % os.getcwd()) # debug check
in_file = input("Extension of input files: ")
out_file = input("Extensionof desired output file: ")
process = "ffmpeg -i {} {} “.format(in_file, out_file)
for i in in_file:
print(”>>> The in_file = “, in_file)
if i.endswith((in_file)):
print(” i = “, i)
subprocess.Popen(process, shell=True)
print(” <<<< Exiting function ") # debug check
Long story short.
I’ve got a folder with 10 .MOV files in it that I want to batch process using ffmpeg. For the life of me though, I can’t get it to iterate through all the files in the directory and process them based on the .MOV file extension. I’ve done some trouble shooting and debugging like Zed taught in the text and it gets to the “for loop” and outputs the following:
Entering function:
cwd = /home/pi/disk1/test
Extension of input files: .MOV
Extension of desired output files: .mp4The in_file = .MOV
The in_file = .MOV
The in_file = .MOV
The in_file = .MOV
There are 10 files in the current working directory and I can’t wrap my mind around this output. If it was iterating through every file in the directory, I would think I would see 10 similar output statements. Not four. I know the working directory is correct, because it’s listed correctly in the output.
If anyone has an insights, I would greatly appreciate it. I’m stumped at the moment.
Thanks!
Ryan