1

The problem

I have a folder containing approximately 1000 .avi video files, which should be split to 1 sec long film clips or alternatively cut at a certain point (say between 7 sec and 8 sec) to a length of 1 sec. These film clips contain moving particles and the program I use to measure the speed of these particles requires 1 sec long film clips. The beginning and the end of the .avi files are corrupt, so I want to take the 1 sec clip from somewhere in the middle. I want to keep the file names, as they are references for video samples I have taken. I am working on Windows 7 and have absolutely no back-ground in programming (apart from R), so treat me as a newbie.

Earlier trials

I been trying to find a solution for this problem for a long time. The first time I did this, I manually cut about 1000 clips with Final Cut Pro. This took me couple of days, but I do not have access to the software. Anyway, I figured that there must be a better solution. I tried to understand VirtualDub, but got overwhelmed and gave up. Now I have been looking if FFmpeg could be the solution. I am pretty sure that it could, but I am overwhelmed again. I found this BASH script and @evilsoup's answer to this question. If I could manage to combine these two, this could work. I have so many questions about this process that it is better I keep it concise:

How to combine these two scripts (splitting and for loops) in FFmpeg under Windows 7?

(i.e. can I use BASH script under windows? If yes, how?)

Mikko
  • 183

1 Answers1

3

You don't really need any complicated script.

This simple Bash loop will take every .avi file, skip 5 seconds into the video, cut one second (-t 1) from it, and write to -cut.avi. It will copy the video stream and discard the audio.

for i in *.avi; do ffmpeg -ss 5 -i "$i" -c:v copy -an -t 1 "${i%.avi}-cut.avi"; done

You can replace "${i%.avi}-cut.avi" with "output/$i" to write the output files to the folder output instead without changing their name.

You can use Bash on Windows with Cygwin, but this loop should be easy to translate into a Windows-native one (if anyone knows that, feel free to edit this post).

Notes for the video:

  • FFmpeg is available as a static build for every major OS – it can be installed just be extracting the downloaded archive.
  • If you want a more accurate starting point for cutting, consider placing the -ss behind -i "$i".
  • If the video files are damaged at the beginning, and FFmpeg can't decode the input, this might not work altogether.
slhck
  • 235,242