Monday, May 7, 2012

Reformatting and recoding video files for Internet TV's and other devices

You have a .mkv or .wmv movie, but you want to play it on PS3, or internet TV's that only know mp4.

You have a .avi movie with old Xvid video codec.

You only need one package in Linux - ffmpeg.  It comes with Ubuntu, but because of codec licensing, you need to install the aac avc and such codec separately.

Ubuntu Precise Pangolin 12.04 LTS and Ubuntu Oneiric Ocelot 11.10
#sudo apt-get install ffmpeg libavcodec-extra-53

Ubuntu Natty Narwhal 11.04 and Ubuntu Lucid Lynx 10.04 LTS
 #sudo apt-get install ffmpeg libavcodec-extra-52

You need to look at the streams of your movie file:
#ffmpeg -i movie.mkv

If the first stream is the video in AVC and the 2nd stream is audio in AC3, and your TV understands AC3 in MP4, then you just copy the v(ideo) and a(udio) into a new mp4 container:
#ffmpeg -i movie.mkv -vcodec copy -acodec copy movie.mp4

Most of the time, blu ray movies are in DTS, so you need to recode into AC3 or AAC.

#ffmpeg -i movie.mkv -vcodec copy -acodec ac3 movie.mp4

You can look up the exact ac3 encoder you have installed, or just let ffmpeg flag it up and suggest to you.  If the default encoder options do not give you satisfactory results, you can control the bit rate and no. of channels by -ab and -ac options.

If you need to pick a particular language track out of sequence, you need to specific all tracks:

#ffmpeg -i movie.mkv -map 0:0 -vcodec copy -map 0:2 -acodec ac3 movie.mp4

0:0 is the first input file, first stream.  0:2 is the first input file, third stream.  It doesn't matter how the tracks is numbered in the original file.  It's the order of it.  You can also handle subtitles like this.

You can pick only one track and output it into an video file mp4 or audio file like mp3.  You can combine multiple input files and streams with more than one -i options.  All the streams can be selected by -map f:s

ffmpeg also understands wmv and avi formats.

Typically, the Walmart best seller Vizio E3D420VX understands
mp4 - AVC, AAC or AC3, not DTS
wmv - wmv video and wma (libwmav2)
avi -

Even if the TV has the decoder, it may not work on different container formats.

No comments: