1

I'm having an issue figuring out how to do the last for loop in my first really useful python program. I am trying to split a video with ffmpeg based on a bunch of logic to figure out edit points.

I have a list of dictionaries 'cut_list' that I have sorting figured out like this

[{'Cutstart': '01:00:00:00', 'CutEnd': '01:00:05:00'}, {'Cutstart': '01:00:10:01', 'CutEnd': '01:00:15:00'}, {'Cutstart': '01:00:20:01', 'CutEnd': '01:00:25:01'}]

I then am trying to feed these values to ffmpeg, iterating over the list of dicts like so:

cutcounter=1
for Cutstart & CutEnd in cut_list:
    for k in Cutstart.items() & v in CutEnd.items() :
        print(k)
        print(v)
        intime=Timecode(fps_real, k)
        intime.set_fractional(True)
        outtime=Timecode(fps_real, v)
        outtime.set_fractional(True)
        cutfile=str(cutcounter)+".mxf"
        print(k)
        print(v)
        subprocess.call(['ffmpeg', '-i', "C:\\path\\to\\file\\BaseFile.mxf", '-ss', k, '-to', v, '-c:v', 'copy', '-c:a', 'copy', cutfile])
        cutcounter=cutcounter+1

My expected output is to iterate over the list and have chunks of the video split off at those specific timecodes and numbered 1.mxf and count up for every for loop to be recombined with inserted fixes to those timespans. I think after I figure out the for loop I will need to also feed the timecode values as HH:mm:ss:mss instead of HH:mm:ss:ff but that's not the part that I'm having trouble figuring out yet. Right now I just can't grok the logic of getting the cutstart and cutend for each timecode to feed into the ffmpeg script.

Current error as I bash my head against the wall trying to get smarter is: Syntax Error: cannot assign to operator

I'm definitely inexperienced and have hacked this together from a lot of other helpful posts, but am struggling with sorting and lists vs list of dicts vs tuples etc. and where and when to use each one.

  • Problem is with your for loops. This [SO](https://stackoverflow.com/questions/9152431/iterating-over-list-of-dictionaries) will show how to loop through list of dicts. – Vencat Dec 31 '19 at 11:28

0 Answers0