Posts Tagged ‘ffmpeg’

How to layer/remix videos with free command line tools

May 18, 2010

This tutorial assumes you know a little bit about script files. All files have some editing that is required before executing and knowing a little bit about a couple parameters really expands what you can do with them. That said, it’s really not too hard and we’re happy to answer basic questions.

Video Overview: (which you can definitely skip)

INSTALL SOFTWARE:
FFmpeg (OS X howto), video utility, format conversions, etc.
Imagemagick:all kinds of image processing goodness. Like a command line version of GIMP or photoshop.
Sox: Audio processing.

We’ve used all of these programs on both Linux and Mac. Linux installs are pretty easy with package managers (apt-get, yum, etc). Mac is little more work for ffmpeg and imagemagick but not too tough.

[Optional] VideoDownloadHelper: Firefox plugin that allows you to download easily from lots of video sharing sites in mp4 and flv format at a variety of resolutions. There are Linux command line downloaders as well but we haven’t tried that yet…

GET SOME MOVIES Maybe you take them with your own camera, maybe you download from online. You’ve probably got a bunch floating around your hard drive already. Start with short ones. Feel free to grab some from http://youtube.com/brooklynmobile, or any other broadcaster, all are public domain.

EXPORT MOVIES TO FRAMES
mkdir frames
ffmpeg -i yourvideoA.avi frames/A%4d.jpg
ffmpeg -i yourvideoB.avi frames/B%4d.jpg

This will export individual frames of the video to A0001.jpg, A0002.jpg, etc
For longer videos you might need to use A%5d.jpg or A%6d.jpg but start with small videos first.

DO SOMETHING TO THE FRAMES and RECOMPILE MOVIE
This is where ImageMagick comes in handy. ImageMagick can do all kinds of image manipulations. We will give you a few examples.

EXAMPLES:
Blending two movies on top of one another. Copy the following code into a file called blurmachine.sh and make it executable[type chmod 755 blurmachine.sh at the command line].

#!/bin/bash
# boranj!
counter=10000 # initialize counter
for f in A*.jpg; do # step through frames
let "counter+=1" # increment counter
# apply some Imagemagick effects to the 2 images and write a new image
composite -blend 50 A${counter:1}.jpg B${counter:1}.jpg -matte ./mixedFrame${counter:1}.jpg
done
#Use FFMPEG to make frames into a movie again
ffmpeg -r 30 -sameq -i mixedFrame%4d.jpg ../outputmovie$DATETIME.mp4

Now you will have a movie with no sound that will look something like this:

ADD AUDIO BACK TO THE MOVIES
After using the above script file, you will have a movie with no sound. You can add the soundtrack of your choice, or add the mixed audio from the original movies.
To extract audio from the original movies and sum it back together:

# AUDIO EXTRACTION
ffmpeg -i movA.mp4 movAsound.wav
ffmpeg -i movB.mp4 movBsound.wav
# AUDIO MIX
sox -m movAsound.wav movBsound.wav mixed.mp3

Add audio back to your movie:
ffmpeg -i movNoSound.mp4 -sameq -i mixed.mp3 -ab 192k movSound.mp4

OTHER IMAGE MANIPULATIONS

Wavy overlay: Script file.

and similar example with more slices.
For this example, you need to create a mix image first. That is done with this line.
convert -size 640x480 gradient: -evaluate sin 20 wave_gradient.png

Place it in an appropriate location and make sure it’s correctly reference in your script file.
This type of combination has all kinds of options. You can take this a lot of other places if you wish to dig deeper. See this forum post and this usage examples page.

Four movie grid montage: Script File.

Six panel version of same effect.

Lots of other possibilities if you poke around Fred’s Imagemagick scripts as well.

Let us know what you come up with.

installing ffmeg on mac os x

July 27, 2009

i’m on a mac mini. 1.83 intel core duo. 1 gb ram.

os x 10.5.4.

my notes on ffmeg install following this article  — http://stephenjungels.com/jungels.net/articles/ffmpeg-howto.html

 tar xvzf lame-3.97.tar.gz

(this line didn’t work for me because mc os x automatically unzipped for me) so instead i need to get rid of the z.

tar xvf lame-3.98-2.tar

then a couple lines down there is a 

./configure

this didn’t work for me either. i got

… configure: error: no acceptable C compiler found in $PATH See `config.log’ for more details.

now i’m downloading xcode and developer tools. i’m assuming this will cover the c compiler part. http://developer.apple.com/technology/Xcode.html

ok. this block works now. 

./config

make

sudo make install 

optional: 

same issue with tar after downloading. i could get the command line download line to work. so i went to download faad from sourceforge. and then used this tar line

tar xvf faad2-2.7.tar

then i ran ./configure, make,and make install.

now back to ffmpeg. mkdir. cd. svn.

“Checked out revision 19521.”

long configure line. make (this is a long one). sudo make install.

now i noticed the additional config flags for the aac stuff. so i go back and run config again.

 

 

 ./configure –enable-libmp3lame –enable-shared  –disable-mmx –enable-libfaac –enable-libfaad

libfaad2 is gpl and –enable-gpl is not specified.

If you think configure made a mistake, make sure you are using the latest version from SVN.  If the latest version fails, report the problem to the ffmpeg-user@mplayerhq.hu mailing list or IRC #ffmpeg on irc.freenode.net. Include the log file “config.err” produced by configure as this will help solving the problem.

not sure what this means but i’m moving on…
so here i am. first try.
$ ffmpeg -i codemovie.mov codemovie.flv
FFmpeg version SVN-r19521, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: –enable-libmp3lame –enable-shared –disable-mmx
  libavutil     50. 3. 0 / 50. 3. 0
  libavcodec    52.32. 0 / 52.32. 0
  libavformat   52.36. 0 / 52.36. 0
  libavdevice   52. 2. 0 / 52. 2. 0
  libswscale     0. 7. 1 /  0. 7. 1
  built on Jul 27 2009 15:15:19, gcc: 4.0.1 (Apple Inc. build 5493)
codemovie.mov: Unknown format

tar xvf faad2-2.7.tar

it can’t understand the native .mov files written by photobooth. that’s all for now. back to this at a later date.