Saturday, January 19, 2008

video editing in linux

I had some old camcorder videos that I wanted to digitize/transfer to DVD and distribute to family. I borrowed an ATI USB 2.0 TV wonder gadget from a friend and unfortunately was stuck with windoze to capture the streams. After capturing all the videos, I switched back to linux to start chopping up the files as appropriate. This is where it got tough.

I captured to MPEG-2 and simply wanted to split videos at specific times. With AVI files it's easy, just use avisplit which I believe is part of the transcode package. MPEG2 isn't quite as simple. I was hoping to simply load a video into a program, scroll to the split point, mark it and tell the program to split at the nearest I-frame, without re-encoding the file.

So, I soon found Cinelerra, Kino, Avidemux and Kdenlive. A quick search showed that Cinelerra and Kino are both complex, so I started with Kdenlive which was said to be super simple - and it seemed overly complicated as well to me. And it quickly became apparent that it'd want to re-encode my files. So I switched to avidemux - it was great for scrolling through files and finding the split points. However, it wanted to re-encode my files as well :(

More googling pointed me to mpgtx - a command line MPEG toolbox. Perfect. I used avidemux to locate all the split points in all the files, put them into a script file that would call mpgsplit as appropriate. I thought I had this in the bag until I started playing back the files and noticed the split points were just wrong in some files. Ugh. No idea why.

Ok, more searching leads me to GOPchop, which installs but crashes - says my MPEG-2 files have incorrect headers and I-frames. Next is GOPdit. Ok, very simple, but effective. Had to make sure the pereferences were setup. This tool is good, but could use some more effective keyboard shortcuts and editing tools. But for the most part it seemed to work.

Notable mentions include ProjectX which is supposed to be good for fixing up the MPEG-2 files that capture devices often hack up. Didn't manage to get it installed, but may still be of use when I get to 8mm projector files. Also, Lives is supposed to be another good program, but it's not in the repositories either.

Lastly, another good site I am going to mention for searching for linux equivalents of windoze programs: http://www.linuxalt.com/

5 comments:

Anonymous said...

ProjectX is the only one I've managed to get to produce properly working output that isn't re-encoded. I don't know how you can fail to install it since you just have to unpack it. After unpacking it you can run it by running:
java -jar ProjectX.jar
in the directory where you unpacked it. (You need a java runtime installed, too.)

Then just remember to select "(0) use BytePos. for cuts" at the bottom right if you want to cut mpeg videos, or it probably won't work.

Unknown said...

For a GUI option try Open Movie Editor.

Best to build from source at this time, but it will handle MPEG2 files no problem. Drop them on a video track in the timeline, split at your preferred points, then render the project in your desired format.

Another option is FFmpeg. Again, build from the latest source in SVN. FFmpeg will split your files and retain format.

Your command might look something like this:

Code:

ffmpeg -i input.mpg -ss 00:00:10 -t 00:00:30 out1.mpg

-ss is the start point in hh:mm:ss from the beginning of your video file

-t is the length of time in hh:mm:ss of your new segment.

So, in the above example, you're starting 10 seconds in from the beginning of the original file and ending 30 seconds later.

If you want to create multiple parts in one pass then the following should work:

Code:

ffmpeg -i input.mpg -ss 00:00:10 -t 00:00:30 out1.mpg -ss 00:00:35 -t 00:00:30 out2.mpg

In this example, the first segment is the same as the first example, but you're also creating a second file starting at 35 seconds in and being 30 seconds long.

Anonymous said...

> FFmpeg will split your files and retain format.

No, it won't. It will re-encode the stream(s). (At least that what it does for me, and the result is butt-ugly.) Re-encoding is completely unacceptable when GOP-precision cutting would do just fine.

Unknown said...

Does anyone have a definitive answer on this? Obviously re-encoding isn't ideal. When I use the above commandline, I get files that very few players will play without crashing.

If it worked, I'd love the convenience though.

Lionel said...

Try:

ffmpeg -i "France 3 national - Sans titre - 27-06-2008 14h25 2h40m.ts" -ss 00:00:10 -t 00:00:30 -vcodec copy -acodec copy ffm.mpg

Lionel

PS: mencoder may be another solution, though I have not tested it a lot (just once):
mencoder "France 3 national - Sans titre - 27-06-2008 14h25 2h40m.ts" -ovc copy -oac copy -of mpeg -endpos 00:01:00 -o test.mpg