Video Editing Magic with ffmpeg

Your rating: None Average: 5 (3 votes)

Non-linear video editing tools are great, but they're not always the best tool for the job. This is where a powerful tool like ffmpeg becomes useful. This tutorial by Elliot Isaacson covers the basics of transcoding video, as well as more advanced tricks like creating animations, screen captures, and slow motion effects.


__________________________


Special Magazine Offer -- 2 Free Trial Issues!
Receive 2 free trial issues of Linux Journal as well as instant online access to current and past issues. There's NO RISK and NO OBLIGATION to buy. CLICK HERE for offer

Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.

Sorry, offer available in the US only. International orders, click here.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Operating system ?

On July 30th, 2008 Dhaval (not verified) says:

Hello !

After watching this great video , I want to ask one question :

Which is the best operating system for FFMPEG and all the libraries to get best performence ?
I have just tried Fedora core 6 !
can u please suggest me which os you are using ?

:)

ffmpeg performance

On July 30th, 2008 Elliot Isaacson says:

Of all the things that could impact the performance of a tool like ffmpeg, the operating system probably matters the least. Much more important is just the hardware you are using: the processor(s), the hard disk and the RAM. I use Vector Linux, but any distribution will work fine. You can even use windows if you really want to.

script for auto fade transition

On July 29th, 2008 Anonymous (not verified) says:

This video is great, and it make me think that it is possible to do something I've tried in the past with no success. I would like to create a script that will take all the video clips in a fold and put them together with a one second cross-fade transition between each.

Does anyone know how to do this?

script

On August 1st, 2008 Elliot Isaacson says:

OK, I think I found something that sort of works. The code for the script is here:

http://dark-code.bulix.org/kdqxmw-67863 (with syntax highlighting and line numbers)
http://dark-code.bulix.org/kdqxmw-67863?raw (without syntax highlighting and line numbers)

Before you can run the script you need to patch your ffmpeg with the following:

http://dark-code.bulix.org/x6iy8f-67862?raw

which is an ever so slightly modified version of the patch on this page:

http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2006-October/017666.html

After patching the ffmpeg source tree (make sure the resulting pip.c file ends up in the vhook directory), you will need to find the line in your Makefile that looks something like this:

BASEHOOKS = fish null watermark

and change it to:

BASEHOOKS = pip fish null watermark

Then, before the script will run, you need to take all the videos you want to concatenate together and turn them into .mpg files with the same dimensions and frame rate. Then, you need to open up any image editor and create an all black image with the same dimensions as your videos. The script will print out usage information if you execute it with no arguments. Here is an example of how to run the script:

$ ls
video1.mpg
video2.mpg
video3.mpg
all_black_320x240.png
fade.sh
$ OUTPUT_FILE="final_video.mpg" BLACK_PICTURE_FILE="all_black_320x240.png" FADE_FRAMES="25" ./fade.sh video1.mpg video2.mpg video3.mpg

And that's it. Please note that this script doesn't exactly "cross-fade" the videos... the transition is "fade to black," but it might work for some things. As far as I can tell a true cross fade is not possible. I know this is not pretty, please someone improve it :-)

Script

On July 30th, 2008 Elliot Isaacson says:

I had thought that this was not possible (imlib2 only allows changing the opacity of text), although I think I might have found a solution for you. I'll try it out later today and let you know if it actually works :)

Thanks!

On July 24th, 2008 Anonymous (not verified) says:

This was really useful, thanks for putting it together!

Gracias

On July 24th, 2008 Black Wolfette (not verified) says:

Your tutorial is clear, bright and very useful. I expected to see more thankyou comments in this place, but I'm surprised. I say "THANK YOU." This is something I've been searching for since I discovered ffmpeg as a great program. You explain things ans stuff perfectly. Keep on with your excellent work!

Re: Gracias

On July 24th, 2008 Elliot_Isaacson (not verified) says:

You're welcome, I'm glad you found it useful.

hyphen target

On July 24th, 2008 rotten777 (not verified) says:

That's a great find. I never knew about the -target parameter.

+5

On July 24th, 2008 Anonymous (not verified) says:

Wow - +5 geek points for algorithmic spotlight animation from the command line.

Cool.

On July 25th, 2008 Elliot Isaacson says:

How many geek points do I need before I can trade them in for some new hardware?

Speaking of Video Editing...

On July 23rd, 2008 AJ ONeal (not verified) says:

What software do you use for video editing, screencasts, and showing the highlights on the video you created today?

From your tutorial I can see that it's totally possible to place fading highlights on a still image and cat a bunch of mpgs together... but I'd prefer not to do that to create my own.

:-D

The non-linear editor I use

On July 24th, 2008 Elliot_Isaacson (not verified) says:

The non-linear editor I use is cinelerra-cv. It works great. Although if you are going to be expanding still frames into movies (like I had to do with the "highlighting") I would do the expanding in ffmpeg. Otherwise you'll spend unnecessarily large amounts of time zooming in and dragging then zooming out and dragging some more etc. etc. to get the still frame expanded to the right length. The highlighting is just making two still frame movies (one highlighted and one not) and ramping the opacity between them.

For screen captures I usually use pyvnc2swf and then jump through some hoops to get it formated in a way that can be combined with other video clips. If you don't want to deal with that you can use recordmydesktop, which is also very good and much easier to use. Some people like xvidcap but it is not functional at all on my box (1.46Ghz Celeron Laptop.), it needs much more juice than my machine can pump out.

LiVES

On July 25th, 2008 salsaman (not verified) says:

Great movie !

Just so you know, LiVES has a tool for generating clips from still images (Tools/Generate/Generate clip from image). You might find it easier to use than cinelerra.

And btw, LiVES also uses ffmpeg for decoding/encoding videos.

http://lives.sourceforge.net

Featured Videos

Email is one of the least private and least secure forms of communication, although few people realize this. MixMaster is one way to allow secure, anonymous communication even over the very public medium of email. This tutorial will get you started with MixMaster quickly and easily.

In case you were wondering about the fun side of Linux World Expo, we thought we'd give you a peek at our shenanigans. We at Linux Journal love what we do so much, that we can't help but have a ball wherever we go.

From the Magazine

September 2008, #173

Feeling a bit like a Thermian? Never give up, never surrender! Someday, you could go from underdog to top dog. Just take a look at a few of the underdogs we highlight in this issue: Mutt, djbdns, Nginix, Gentoo, Xara and the program voted mostly likely to fail just a few years back—Firefox. If Firefox is not radical enough for you, check out Chef Marcel's column for some more alternatives. Having trouble mapping your program data to your relational database? If so, Rueven Lerner shows you some tricks in his At The Forge column.

Need to run GUI applications on your server in the next state? In his Paranoid Penguin column, Mick Bauer shows you how to do it securely. Kyle Rankin keeps hacking and slashing and shows you a few split screen secrets you may not be familiar with. Finally, we all know what happens next February, but only Doc knows what happens afterward.

Read this issue