ffmpeg same video crop multi times

0

I'm totally a newbie to FFmpeg and programming stuff, so the question might be too stupid... I have a video and want to crop it into small pieces and render out each one, so I'm trying to use a FOR loop:

FOR /l %x IN (0,40,1000) DO ffmpeg -i sample.avi -filter:v "crop=20:20:x:x" outx.avi; done

What I got is: [NULL @ 0000000002624220] Unable to find a suitable output format for 'outx.avi;' outx.avi;: Invalid argument

Anyone can help this out?

Link

Posted 2017-09-28T15:09:40.460

Reputation: 3

Answers

2

You're apparently using Windows batch files. Here, FOR loops do not have a trailing ; done, as Bash loops have.

Under Windows:

FOR ... IN ... DO ...

Under Bash:

for ... in ...; do ...; done

So, make sure you use the proper syntax for your shell.


Note that simply specifying out.avi will make ffmpeg choose MPEG-4 and MP3 as video and audio codecs, respectively, and your quality might be quite bad. Ideally, specify the video and audio encoders, e.g.:

ffmpeg -i <input> -c:v libx264 -crf 23 -c:a aac -b:a 192k out.mp4

Read the H.264 encoding guide for more info.

slhck

Posted 2017-09-28T15:09:40.460

Reputation: 182 472

Thanks for the answering first! I removed the trailing, then the error gone! But seems like all the file will save as a same name"outx.avi", I tried "outx.avi" because I thought it will be save as out1.avi and then out2.avi ... but actually it doen't work... is there anyway I can make them save in different name in the for loop? – Link – 2017-09-28T15:22:12.067

I change the file name to out%x.avi and fixed! – Link – 2017-09-28T15:29:29.357

Glad you got it working. If this answer solved your question, please mark it as accepted using the green checkmark next to it. Thanks. – slhck – 2017-09-28T17:20:33.597