Currently on Public Videos alpha, the videos are shot with 2 different consumer camcorders which uses the AVCHD format: a Panasonic HDC SD-5 and a Canon Vixia HF11. All clips are captured in 1080p full HD and from the original files the system generates the different versions (at the moment they are 12 for each clip, including different sizes, formats thumbnails and poster images).
All this transcoding work is made using free tools, the two main open source transcoding tools we use are mencoder and ffmpeg.
It is a great thing that we are able to do everything using only free tools, and it is impressive to see how fast those two projects in particular evolve, the codebase is huge and very active, the pool of features they offer is mind-boggling and the maintainers and contributors are my heroes. But each of them has it's share of bugs too, so at the moment it is not possible to use only one of them for everything, you have to combine them and do the proccess in multiple steps, using the best tool for a particular part of the proccess in each step.
In addition to mencoder and ffmpeg we also use ffmpeg2theora and ffmpeg2dirac to generate the final Ogg Video versions and MPlayer for the JPEGs.
So, after consulting several forums, tutorials, manuals and other documentation online here is what we settled as workflow to convert our .MTS files, basically a conversion made in two parts for each version:
Keep in mind that we are constantly changing the transcoding commands(public videos is alpha!) and the recipies described below might be already outdated, consult the database fixtures in our source control for the latest version of this command lines.
Those two cameras stores whatever was shot in a 60 fps file regardless if you have used the 30P or 24P framerate setting, so the first part is to transcode from 60000/1001 fps to 30000/1001 or 24000/1001 fps deinterlacing (and de-telecining too in the 24fps case), we use mencoder because ffmpeg (at least until the moment of this post) can't do this framerate conversion for mts files correctly, resulting in files that has video and audio out of sync. The same problem is true for ffmpeg2theora and ffmpeg2dirac as well.
So, for a clip shot in 30fps the command line for this first part of a convertion to a 480x270 ogv or mp4 would look like this:
mencoder "$SOURCE" -o "$TARGET" -fps 60000/1001 -ofps 30000/1001 -noskip -mc 0 -demuxer mpegts -oac copy -ovc raw -vf scale=480:272,pullup,softskip,pp=lb
However, if you try the same thing for a clip from the canon hf11 changing the -ofps to 24000/1001 you will end up with an intermediate file with artifacts due to a decoding issue that mencoder has. The solution then was to change this first step to the one found on this forum thread that uses a different demuxer and a different output format:
mencoder "$SOURCE" -fps 60000/1001 -oac pcm -demuxer lavf -vf pp=ci,scale=480:272,detc,softskip -ofps 24000/1001 -ovc lavc -lavcopts vcodec=ffvhuff:format=YV12:vstrict=-1:aspect=16/9 -o "$TARGET"
Once done this first step, you have a file that can be used as the source for all the versions, bellow are the command lines used for converting this intermediate file into 5 different formats:
Convert a given video to theora ogv 1200k bitrate, two pass.
ffmpeg2theora --videobitrate 1200 --keyint 30 --audiobitrate 128 --samplerate 44100 --optimize --two-pass -o "$TARGET" "$SOURCE"
Converts a given video to dirac ogv 1000k bitrate.
ffmpeg2dirac --videobitrate 1000 --keyint 30 --audiobitrate 128 --samplerate 44100 -o "$TARGET" "$SOURCE"
Converts a given video to h2.64 baseline mp4 1000k bitrate, two pass.
ffmpeg -i "$SOURCE" -b 1000k -an -pass 1 -vcodec libx264 -vpre hq -vpre libx264-baseline -f ipod -threads 0 -benchmark -y /dev/null&&ffmpeg -i "$SOURCE" -b 1000k -pass 2 -vcodec libx264 -vpre hq -vpre libx264-baseline -acodec libfaac -ab 128k -ar 44100 -threads 0 -benchmark -y "$TARGET"
Generate a JPG from the second #2 of a video
mplayer "$SOURCE" -ss 2 -nosound -frames 1 -vo jpeg:outdir=$TARGET:smooth=0:quality=60:progressive
Generate black and white low contrast JPG from the second #2 of a video
mplayer "$SOURCE" -ss 2 -nosound -frames 1 -vo jpeg:outdir=$TARGET:smooth=0:quality=60:progressive -saturation -100 -brightness -0 -contrast -10
The examples above are for our smaller size (480x272) we encode the larger sizes using higher bitrates.
curl -O http://diracvideo.org/download/dirac-research/dirac-1.0.2.tar.gz
tar -vxzf dirac-1.0.2.tar.gz
cd dirac-1.0.2
./configure
make
sudo make install
git clone git://diracvideo.org/git/ffmpeg2dirac.git ffmpeg2dirac
cd ffmpeg2dirac
Not much development was made this week since I've spent most part of the week in a LAN party in Sao Paulo, presenting the project to other open source/free culture enthusiasts and meeting other folks.