Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a bunch of game footage from my soccer team's season and I've assigned each of my teammates one game to watch and write down the time intervals where highlights occur.

Now instead of having to cut all of this manually, I want to write a script that will do this for me. I'm familiar with shell scripting, python, and ruby.

Do any of you guys know of any good video editing tools that can help automate this task? I was hoping to be able to put the intervals in a simple input file that my teammates will be able to use.

share|improve this question

I once wrote a Ruby script which does exactly that. You need Ruby ≥1.9.2 (e.g. through RVM) and a recent version of FFmpeg installed (see here on how to install from source).

  1. My script is available here: video-extract.rb

  2. You need to feed it with a CSV input list of edits, most importantly containing the following columns:

    • a prefix (can be empty)
    • a video ID (some sequential number)
    • the input file name
    • the in point in or seconds
    • the length of the edit in or seconds

    For example (note that the Out column is unused):

  3. Then, adjust the variables in the script header. Most importantly, change COPY to true if you want a bitstream copy and no re-encode. Also change the index of the CSV columns and the CSV separator.

Feel free to improve the script or suggest changes (especially if you already know Ruby). I've used this script very often and haven't run into problems yet. The only thing that's missing is proper audio support – it'll just copy the audio stream, which might or might not work in your case. In case of trouble, report back.

If you need to calculate the difference between an in and out-point, you can do this with this little Ruby script, based on this Stack Overflow Q&A:

require "Time"
def time_diff(time1_str, time2_str)
  t = Time.parse(time2_str) - Time.parse(time1_str) )
  (t - t.gmt_offset).strftime("%H:%M:%S.%L")
ins, outs, diffs ="ins.txt"),"outs.txt"),"diffs.txt", "w")
inlines, outlines = [], []
ins.each  { |l| inlines << l }
outs.each { |l| outlines << l } { |ins, outs| diffs.puts time_diff(ins, outs) }

You just create a file called ins.txt and outs.txt where each line corresponds to an in- and out-point (see the screenshot above). The difference will be written to diffs.txt. Simple as that.

share|improve this answer

MEncoder is your friend here. It's a great tool for scripting operations on video. I use it a lot to create video files from individual frames.

I found this Perl script that might do exactly what you want: Video Cutter V2: Video Cutting Using Mencoder

share|improve this answer

Try ffmpeg.

For example:

ffmpeg -i original.mpg -ss 20 -t 30 newmovie.mpg

Will open the original video file (-i original.mpg), skip the first 20 seconds (-ss 20) and then save 30 seconds (-t 30) into a new movie called newmovie.mpg

share|improve this answer
… but it'll re-encode the video, thus resulting in terrible quality. Try -c:v copy -c:a copy (inserted between input and output) to do a bitstream copy. – slhck May 2 '12 at 6:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .