2

I'm currently using a couple commands to 1- output two files with cropped regions, and 2- overlay the 2 files back into a single file.

I would like to be able to merge this all into out command and have a single output if this would speed up the process.

Here are my current commands (I'm using this inside a batch file, please excuse the variables):

1.This takes the input file and creates 2 output files cropped at different regions.

ffmpeg -i %input% -filter_complex "[0:v]crop=%size%:%position%[out1];[0:v]crop=200:110:6558:106[out2]" -map "[out1]" -f mp4 -ss %startTime% -t %duration% -rtbufsize 100M -framerate 8 -c:v libx264 -qmin 35 -qmax 35 -b:v 50k -preset ultrafast -movflags +faststart tmp -map "[out2]" -f mp4 -ss %startTime% -t %duration% -rtbufsize 100M -framerate 8 -c:v libx264 -qmin 35 -qmax 35 -b:v 50k -preset ultrafast -movflags +faststart tmpclock

2.This takes the two ouput files from the previous command and overlays them into the final file.

ffmpeg -i tmp -i tmpclock -filter_complex "[0:v][1:v]overlay=%pixFrmLeft%:%pixFrmTop%" -rtbufsize 100M -framerate 8 -c:v libx264 -qmin 35 -qmax 35 -b:v 50k -preset ultrafast -movflags +faststart -f mp4 %input%_Converted.mp4
1

Use

ffmpeg -ss %startTime% -t %duration% -i %input% -filter_complex "[0:v]split=2[c1][c2];[c1]crop=%size%:%position%[c1];[c2]crop=200:110:6558:106[c2];[c1][c2]overlay=%pixFrmLeft%:%pixFrmTop%" {your encoding options} %input%_Converted.mp4

Note that -framerate 8 is an input option for certain file formats. For an output at 8 fps, use -r 8.

  • Thank you, that worked great. I did have to modify it slightly by putting -ss %startTime% -t %duration% at the end with my encoding options. If I didn't do this, it seems like it was doing unnecessary work, or taking a very long time. I cleaning it all up by making %encopts% and included the time options there as well. – ditch Jun 19 at 18:26
  • 1
    Share the log. It's the precise opposite - -ss before input skips unnecessary processing. – Gyan Jun 19 at 18:39
  • Ok, here are two logs. -ss before: link and -ss after: link – ditch Jun 19 at 22:24
  • This is due to the pixel format of the input and a quirk in how ffmpeg processes it when input seek is set. Upgrade to latest ffmpeg and check. – Gyan Jun 20 at 5:36
0

I'd like to offer a version similar to Gyan's, but makes things easier to think about and makes the individual ffmpeg command more readable.

You have a single file, but want to use ffmpeg to crop one part of it differently from another part of it. I find the easiest way to do multiple things on a single file is to mark them as different inputs.

set input1=yourFile.mp4
set input2=yourFile.mp4

ffmpeg -ss %startTime1% -t %duration1% -i %input1% \
       -ss %startTime2% -t %duration2% -i %input2% \
          filter_complex "[0]crop=%size1%[v1];[1]crop%size2%[v2];\
          [v1][v2]overlay=%pixFrmLeft%:%pixFrmTop%" \
       %commands% %input%_Converted.mp4

Gyan does this with the [0:v]split=2[c1][c2] filter, which may be easy to track for now, but in instances where you have more files and want to process more than 2 parts each, creating the list of your inputs (though some are actually the same file) ahead of time is probably the best place to start to help keep you organized and on track.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.