Saturday, December 29, 2012

Why would someone want to do that? One use would be to use the animated gif as a profile pic on a social media site or an avatar for a user forum..those are two cases I can think of.

I wanted to convert this short video into an animated gif loop. The below timelapse was acheived by using the FPS override function of the MagicLantern firmware upgrade for the Canon 5D:

In order to convert the movie, I did two things:
1) in Cinelerra, export a JPG sequence
2) use ImageMagick "convert" to convert to an animated gif

Export a JPG sequence
1) In Cinelerra, you can export your movie as a JPG sequence (among other choices like an EXR/PNG/TGA or TIFF image sequence):

Depending on the number of frames you're exporting, you'll get a whole bunch of files saved to your hard drive. Since my project was set to 24fps, I had about 120 files saved to my filesystem. The file names start and end with the number of the frames you selected to export (shown in this screen cap of the Cinelerra timeline):

Once you've export all the single images from Cinelerra, use ImageMagick's "convert" program to assemble the individual images into an animated gif. Since I wanted to resize the 1080P resolution images (1920x1080) into 1/8th the size of the original, I used 240x135 as the resize value. You can see I've used other specifiers as well:
-delay 0 (no delay between frames)
-loop 0 (infinitely loop the gif)
seq*.jpg (convert is smart enough to assemble the jpgs in ordered sequence)
the other specifiers are essentially "high quality" output settings

The Few, The Proud
After reading some FFmpeg doc (linked in the references), I found out that MP4's can't be concatenated in their native form. There are only a few video formats that CAN be concatenated in their native form: MPEG-1, MPEG-2 PS, DV. After some experimentation and viewing the results, I decided to use mpeg2video as my intermediate format with this command:ffmpeg -threads 8 -i part1.mp4 -sameq -vcodec mpeg2video -acodec mp2 -ac 2 -ar 44100 -ab 256k 1.mpg

Converting en masse
Since I had four of these files to convert, it made sense for me to use some quick shell control flow to get the job done in one shot (input/output streams in bold below):for i in 1 2 3 4;do ffmpeg -threads 8 -i part$i.mp4 -sameq -vcodec mpeg2video -acodec mp2 -ac 2 -ar 44100 -ab 256k $i.mpg;done

Simple filesystem concatenation
After I converted the base files into files of a type that could be concatenated, I used this command to concatenate the files:cat 1.mpg 2.mpg 3.mpg 4.mpg > all.mpg

The resulting file is pretty large ~6GB:[sodo@computer tmp]$ ll all.mpg

-rw-rw-r--. 1 sodo sodo 6165041152 Mar 3 13:16 all.mpg

This would be a quite serviceable intermediate file, but upon reflection, I thought that I could probably do the concatenation and conversion to a final format in one step, rather than two. FFmpeg to the rescue!

FFmpeg's "concat" feature

Because I like my iDevices, I want the file format to be an MP4 container using H264/AAC as my video and audio formats. So instead of doing a two-step conversion:

1) concatenate the files in the filesystem

2) transcode the video to a file format

I decided to combine both of those steps into one by using the "concat" feature of ffmpeg. The command looks like this:

You can change the output specifiers to taste. Also note that you'll need a presets file defined if you are going to use the "-vpre slow" specifier.

There was no way to tell from FFmpeg's output that the concatenation command was working except for this small line:Input #0, mpeg, from 'concat:/tmp/1.mpg|/tmp/2.mpg|/tmp/3.mpg|/tmp/4.mpg'

as well as the fact that the "frame=" counter at the bottom of the FFmpeg output incremented beyond the length of the first video. In this case, 21827.

Verify the total number of framesRedirecting standard error to standard output
As a sanity check, I like to verify the total number of frames in the output. I can do this by capturing the text information that FFmpeg outputs when FFmpeg runs. That text information is not "standard output" in the Unix sense. The text from an FFmpeg command actually outputs "standard error". So instead of trying to grep with a command like this:ffmpeg -i 1.mpg -an -vcodec copy -f mpeg2video -y NUL | grep 'frame'

Here are a few ways to get detailed information about a video file using mplayer, ffmpeg or mencoder. Pardon the format weirdness..blogger tries to overthink things and ends up screwing things up.
- mplayer
- ffmpeg
- mencoder
- ffprobe

Thursday, January 26, 2012

I had this idea that I'm going to start interviewing folks on different technical topics via Skype or Google Hangout. Normally, I would use Cinelerra to perform this task, but for some reason, the recordings in Cinelerra showed some irritating sound artifacts. Testing in audacity showed no such audio problems. I'll bring this up on the Cin mailing list soon.

FFmpeg to the Rescue
So with Cinelerra not working for desktop recordings, I needed an alternate way to record my desktop screen as well as the audio from the person being interviewed. After some searching a good deal of trial and error, I found from the link in the reference section at the bottom of the page, a very nice ffmpeg command. You can save to any format you want. The example below shows how to save the microphone audio (hw:0,0) in PCM format. The desktop video is brought in via the xllgrab format specifier :ffmpeg -f alsa -i hw:0,0 -ac 2 -ar 48000 -acodec pcm_s16le -f x11grab -r 24 -s 1280x720 -i :0.0 -aspect 16:9 -vcodec libx264 -vpre lossless_ultrafast -threads 8 -y output.mov

Why Mule?

"Mules are not really stubborn. They can seem lazy because they will not put themselves in danger. A horse can be worked until it drops, but not so with a mule. The "stubborn" streak is just the mule's way of telling humans that things are not right. Mules are very intelligent and it is not a good idea to abuse a mule. They will do their best for their owner, with the utmost patience."About Mules