Tips for Transcoding Cinelerra Compatible Video with FFmpeg, MEncoder

Tips for Transcoding Cinelerra Compatible Video with FFmpeg, MEncoder

I just wanted to post the fruits of my labor so others could benefit. A little background first… for the past couple days I’ve been banging my head against the wall trying to figure out how to take the video produced from my digital camera (Casio Exilim EX-S500) and convert it to a format that Cinelerra (project page) would be able to work with – the following also applies to any video downloaded from the Internet. Yeah, yeah… I know I should buy a REAL camcorder.

Casio Exilim EX-S500 Video Output:
MIME type: video/x-msvideo
[Video]
Dimensions: 640×480
Codec: ISO MPEG-4
Framerate: 29.97
Bitrate: N/A

[Audio]
MS IMA ADPCM
Sample rate: 22050 Hz
Channels: 1

FFmpeg’s take on Casio’s AVI file:
Input #0, avi, from ‘CIMG2687.AVI’:
Duration: 00:00:04.2, start: 0.000000, bitrate: 2106 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 640×480, 29.97 fps(r)
Stream #0.1: Audio: adpcm_ima_wav, 22050 Hz, mono, 88 kb/s

What works:
#1 [MPEG-4 MONO Audio]
ffmpeg -i CIMG2687.AVI -vcodec mpeg4 -r 29.97 -b 768k -acodec mp3 -ab 64k -ar 22050 movie.avi

* You can change the video bitrate and audio bitrate/frequency to whatever setting you like. Note, if you just use -acodec mp3 and skip the other audio settings like -ab and -ar, ffmpeg will use the properties of the original file.

#2 [MPEG-4 Stereo Audio] ffmpeg -i CIMG2687.AVI -vcodec mpeg4 -r 29.97 -b 768k -acodec mp3 -ab 64k -ar 22050 -ac 2 movie.avi

* You can change the video bitrate and audio bitrate/frequency to whatever setting you like

#BEST [MPEG-4 Solution]
ffmpeg -i CIMG2687.AVI -f mp4 -vcodec xvid -maxrate 2000k -b 2000k -qmin 3 -qmax 5 -bufsize 4096k -g 300 -acodec aac -ac 2 -ab 128k -ar 48000 movie.mp4

OR

mencoder CIMG2687.AVI -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:cbp:trell:vbitrate=2000:autoaspect -ofps 29.97 -vf scale=640:480 -ffourcc DX50 -oac mp3lame -lameopts abr:mode=2:br=128 -af resample=48000 -srate 48000 -o movie.avi

* These formats seems to agree with Cinelerra quite nicely. However, I did, on occasion have some audio sync issues when using ffmpeg, while using mencoder I did not. FYI, when using either of these formats I render the edited video with Quicktime for Linux - Audio: MPEG-4 128000, Video: MPEG-4 2000000 (essentially it outputs the same quality as above).

#3 [OGG Theora] ffmpeg -i CIMG2687.AVI -vcodec theora -r 29.97 -b 768k -acodec vorbis -ac 2 movie.ogg

* When using ffmpeg to produce OGG Theora files you have to use 2 channel audio for vorbis (not the case with ffmpeg2theora which has no problem creating file in mono/1 channel). Here’s the warning I got: “[vorbis @ 0xb7e93a68]Current FFmpeg Vorbis encoder only supports 2 channels.”

#4 [OGG Theora] ffmpeg2theora -c 2 -o movie.ogg CIMG2687.AVI

* For better quality add -v 7 -a 3 (-c 2 is for 2 channels) — more details here and here

#5 [MPEG-2 DVD-NTSC] ffmpeg -i CIMG2687.AVI -target ntsc-dvd -aspect 4:3 movie.mpg (must use NTSC format setting in Cinelerra)

* Settings are preset here

What ffmpeg is doing under the hood:
Stream #0.0: Video: mpeg2video, yuv420p, 720×480, q=2-31, 6000 kb/s, 29.97 fps
Stream #0.1: Audio: ac3, 48000 Hz, stereo, 448 kb/s

#6 [MPEG-2 DVD 640×480] ffmpeg -i CIMG2687.AVI -target dvd -s 640×480 -ac 2 movie.mpg (takes care of audio and video format - MPEG-2 + 48KHz PCM audio)

* Setting are preset here expect for the dimensions which we modified with -s 640×480

What ffmpeg is doing under the hood:
Stream #0.0: Video: mpeg2video, yuv420p, 640×480, q=2-31, 6000 kb/s, 29.97 fps
Stream #0.1: Audio: ac3, 48000 Hz, stereo, 448 kb/s

#7 [CUSTOM MPEG-2] ffmpeg -i CIMG3476.AVI -vcodec mpeg2video -r 29.97 -b 6000k -acodec ac3 -ab 448k -ar 48000 -ac 2 movie.mpg

* You can change the video bitrate and audio bitrate/frequency to whatever setting you like, but I’ve noticed Cinelerra doesn’t like much deviation from the above.

#8 [DV] Files converted to DV with KinoDV work (must use NTSC format setting in Cinelerra)

#9 [MJPEG with PCM] mencoder CIMG2687.AVI -ovc lavc-lavcopts vcodec=mjpeg:vhq:vbitrate=1500 -ofps 30000/1001 -oac pcm -o movie.avi (works, but the video was slightly choppy when played back)

#10 [XML Framelist] Another technique that works, but is a bit more difficult and requires more storage space, is extruding the images from your video as individual PNG files, separating the audio, and creating a framelist. If properly formated, Cinelerra has no problem loading the framelist xml file into your media assets. Click here and here for more details. I tried it. It works.

Encoding tools:
Avidemux - http://fixounet.free.fr/avidemux/ (great GUI tool for creating DivX/Xvid, H.264 MPEG-4 videos)
FFmpeg - http://ffmpeg.mplayerhq.hu
MEncoder (bundled with Mplayer) - http://www.mplayerhq.hu

Alternative Non-Linear Video Editor: Kdenlive - recommended if you’re looking for something more like Apple’s iMovie with a smaller learning curve and support for a myriad of codecs (including HD). Personally, I think Kdenlive is pretty sweet. And I like how its built on top of MLT.

Tips: using -ac 2 in ffmpeg will change your audio from mono to stereo (really, it’s creating 2 identical channels). This is helpful when working in a project that has two audio channels. If you don’t convert the video audio from the clip will only play on one speaker, not two. If your project is one channel, and your video is mono, don’t use -ac 2 — it will work perfectly as is. Also, worth doing (improves performance big time) is changing Cinelerra’s audio driver preference to ALSA with Stop playback locks up checked.

SIDE NOTE: I wish the documentation on http://cvs.cinelerra.org/docs/split_manual_en/cinelerra_cv_manual_en_5.html#SEC73
had this information available in a chart or something — would have saved me hours of trial and error.

UPDATE: It looks like the guys at the CVS community have posted some codec results on their wiki.

Also, STAY AWAY from trying to load H.264 video and AAC audio files into Cinelerra. They just doesn’t play nice!

Now if you have any suggestion on using ffmpeg, mencoder, avidemux, etc. for compatible Cinelerra video, I’d love to see what you’ve got.

Popularity: 84% [?]

Tags: , , , , , , ,


Comments

5 Responses to “Tips for Transcoding Cinelerra Compatible Video with FFmpeg, MEncoder”

  1. Hunter Davis on December 27th, 2007 7:37 pm

    Thank you!!! Excellent info! They should really post this on their site.

  2. goibhniu on January 11th, 2008 11:47 am

    Thanks a million for this! Looks like some really great research and a valuable reference, it would be great to add this to a section on the cinelerra wiki! (Let me know if you’re too busy or something and I’ll gladly add it and link back here).
    On a personal note, details here have just rescued me from a world of pain. I spent a couple of hours trying to convert a dvd created in iDVD (by someone on a mac) into something another editor can use in Avid (on a windows box). I had been trying `ffmpeg -i input -vcodec copy -acodec copy out.mpg` but I wasn’t getting any sound in mplayer, vlc or cinelerra. Using -acodec ac3 -ab 448k -ar 48000 -ac 2 instead seems to do the trick nicely (for cinelerra at least). Fwiw the audio was showing as pcm_s16be by ffmpeg.
    Thanks again!

  3. .mp. on March 6th, 2008 5:22 am

    I was in a similar situation. I have a Canon IXUS 700 photo camera that I use to make little home videos. It took me a full day to figure out how to produce good edited videos with cinelerra. My objectives were: take the videos from the Canon IXUS 700, make a home video with cinelerra on Ubuntu, watch it on the PC, watch it on thru a DivX player on the TV, and post it on Google Video or YouTube.

    My main problems were with poor audio and with audio-video sync problems. With the following methodology I coould resolve all problems and achieve my objectives.

    Step 1: convert sample rate on original Canon videos to 48000 via a command like
    mencoder mvi_5123.avi -ovc copy -srate 48000 -oac pcm -o mvi_5123_new.avi

    Step 2: configure cinelerra project to 48000 sample rate and 640×480 video resolution

    Step 3: import these mvi_*_new.avi videos into cinelerra, do all the editing, overlay music, ad title, etc.

    Step 4: save audio only as MP3 (.mp3 file)

    Step 5: save video only as MP4 or Microsoft MP4 (640×480) (.m4v file)

    Step 6: merge result audio-only and video-only into final MP4 video with a command like
    mencoder output.m4v -audiofile output.mp3 -ovc copy -oac copy -info name=”some title” -o output.avi

    Step 7: done, watch output.avi with is an AVi container holding MP3 audio and MP4 video.

  4. yaayaa on May 21st, 2008 1:45 am

    I also have a casio and I convert the video into DV not to lose quality. It works perfectly when I import it into cinelerra.

    Here is the command line I use through a right-click button with kde/konqueror service menu :

    #!/bin/sh
    mencoder -o $1.avi -oac pcm -ovc lavc -lavcopts vstrict=-2:vcodec=ffv1:autoaspect -xy 720 -zoom -vf scale,expand=720:540,dsize=4:3 $1
    ffmpeg -threads 2 -i $1.avi -s 720×576 -r pal -aspect 4:3 -ac 2 -ar 48000 -pix_fmt yuv420p -y $1.dv
    rm $1.avi

    This is for 4:3 PAL video material; for 16:9 and/or NTSC, customize accordingly (or improve the above script to take/set parameters).

    Regards,

    yaayaa

  5. Open Source Video » Blog Archive » Tips for Transcoding Cinelerra Compatible Video with FFmpeg, MEncoder on July 6th, 2008 7:37 am

    […] San Francisco Peninsula based web publisher who likes to play with Linux in his free time. He posts some tips on transcoding video on his blog that might be helpfull for all you Cinelerra […]

Leave a Reply