Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?)

share|improve this question
    
By your title, it sounds like you want to recombine the split files. Is that what you are looking for? –  Kruug Mar 26 '13 at 21:21
    
No, I just want to cut 1 sec film clip somewhere from the middle of each file (beginning and end are corrupt). I need these clips for another program to analyse speeds of particles in film clips. Sorry for ambiguity. I guess I have to edit the question a little bit. –  Mikko Mar 26 '13 at 21:24

1 Answer 1

up vote 3 down vote accepted

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.
share|improve this answer
    
Thank you @slhck. It works kind of, but I get output files that are 23 KB in size and they do not seem to contain video (at least I can't see it, when I play it). Here is the output I get from Cygwin (for one video clip): pastebin.com/BLMfjtLV –  Mikko Mar 27 '13 at 8:38
    
Oh, I just noticed that I gave you a wrong flag. Typo there. Replace -vn with -an. -vn disables video, while -an disables audio. Try it again with that :) –  slhck Mar 27 '13 at 8:51
    
Works like a charm! You have just solved a major issue I have had in finishing my PhD thesis on time. Words are not enough to express my gratitude. –  Mikko Mar 27 '13 at 9:01
    
No worries… I'm glad to help out. Good luck with your thesis! –  slhck Mar 27 '13 at 9:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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