HOWTO Convert video files

From LinuxReviews

Jump to: navigation, search

Contents

[hide]

[edit] Introduction

There are many good reasons to convert video files you made yourself - or video files forwarded to you which you plan to distribute.

Good reasons to change a video file can be:

  • Playability
  • Size

This howto will to introduce to you some of the basic commands to use the most common Linux command-line program to convert video files from one format to another.

[edit] The file-size

Size is important, a videofile reduced by 100 MB will save you 100 GB of bandwidth if 1000 people download it; obviously the reduction of 100 MB pr. file will save you 1 GB of harddrive space if you host 10 video-files on a web-server.

Thus; You will likely want files to be as small as possible without reducing the video quality

kjk

[edit] Playability

There is no point in sending someone a video file if they can not play it. The most common media formats on the Internet today are divx and xvid.

There is a myth among Windows-users that .wmv (Windows Media Video) is some kind of standard. However, this format is extremely poor and limited to users of that OS.

[edit] Basics

Mencoder:

input_filename.mpg
-ovc codec for video output
-oac codec for audio output
-o output_filename.avi
mencoder <filename.avi> -ovc lavc -oac lavc -o <output.avi> 

Transcode:

-i input_filename.mpg

-y codec for audio/video output
-o output_filename.avi
transcode -i movie.mpg -o movie.avi -y divx

These are just the basics. There are many more advanced options for choosing codecs, bitrate and so on for both these tools. dad

[edit] XviD Encoding

[edit] Using MPlayer (mencoder)

You can encode XviD using one or two passes of the original file. You will get better quality if you use two-pass encoding, but does take longer to encode the video.

[edit] One-Pass Encoding

You can only set the bitrate or fixed_quant using one-pass encoding. You can only choose bitrate if you do two-pass encoding.

You must set one of these when encoding XviD using mencoder.

[edit] By setting bitrate

  • Using bitrate will encode the video to a constant bitrate (CBR).
  • Set bitrate=<value>
  • Higher = better quality with larger files, and
  • lower = less quality with smaller files.
  • A bitrate of 800 will give you near DVD quality when encoding hi-quality video like a DVD disc.
  • VCD quality is around 400-500.
  • Internet streaming quality is generally around 80-150.
  • Mencoder's default bitrate is 687 kbits/s.
  • You need about ~800kb/s to get high quality on a 720x480 sized movie.

Encoding example by setting the bitrate:

mencoder <filename.avi> -ovc xvid -oac mp3lame -xvidencopts bitrate=687 -o <output.avi>
[edit] Setting the audio bitrate

You may also want to change the audio bitrate for the audio encoded using mp3lame when you are making a XviD file with the goal of making a small file using -lameopts abr:br=<audiobitrate>. For example, an audio bitrate of 92 (-lameopts abr:br=92) will do nicely for a video bitrate of 150.

mencoder <filename.avi> \
   -ovc xvid \
   -oac mp3lame \
   -lameopts abr:br=92 \
   -xvidencopts bitrate=150 \
   -o <output.avi>

[edit] By bitrate calculated by a fixed file-size

You can set the filesize you want in KiloBytes in order to make mencoder calculate the bitrate for you. This can be done by setting a "negative" bitrate, bitrate=-700000 will give you a movie file which fits nicely on a CD.

mencoder <filename.avi> -ovc xvid -oac mp3lame -xvidencopts bitrate=-700000 -o <output.avi>

[edit] By setting a fixed quality

fixed_quant can also be used when doing one-pass encoding.

  • fixed_quant=<1-31> specifies what "quality level" you want and will make mencoder automatically try to obtain the best quality/size ratio.
  • 1 is the highest quality, and will result in very large file if you use it.
  • 31 is the lowest, and the video will look very poor.
  • 4 and 5 are good setting for high-quality video. 1, 2 and 3 will give you very little improvement compared to 4, but give you way bigger files.(example:1 is 20mb if 4 is 5mb)
mencoder <filename.avi> -ovc xvid -oac mp3lame -xvidencopts fixed_quant=4 -o <output.avi>

[edit] Two-Pass Encoding

nice -n 19 mencoder file.wmx -ofps 23.976 -oac mp3lame -lameopts abr:br=92 -ovc xvid -xvidencopts pass=2:bitrate=150 -o audiofix-150bit-xvid.avi



[edit] Windows Media files (.wmv/.asf/.wmx)

mencoder can convert wmv files. However, it seems that files created with mencoder from .wmv can not be played in many mediaplayers, namely xine. Adding -ofps 23.976 to the command-line makes files made with mencoder from .wmv play in xine.

mencoder infile.wmv -ofps 23.976 -ovc lavc -oac copy -o outfile.avi'

xvid from .wmv or .wmx, using two-pass xvid encoding:

mencoder file.wmx \
   -ofps 23.976 \
   -oac mp3lame \
   -ovc xvid \
   -xvidencopts pass=1 -o /dev/null
mencoder file.wmx \
   -ofps 23.976 \
   -oac mp3lame \
   -ovc xvid \
   -xvidencopts pass=2:bitrate=250 \
   -o 250bit-xvid.avi

The audio track on Windows Media files are sometimes low. You can use midentify to get information about a video file.

midentify file.wmx
ID_AUDIO_BITRATE=64064

With a bitrate of 64k, add -lameopts abr:br=64 when you encode a divx:

mencoder file.wmx -ofps 23.976 \
   -oac mp3lame \
   -ovc xvid \
   -xvidencopts pass=1 \
   -o /dev/null
mencoder file.wmx \
   -ofps 23.976 \
   -oac mp3lame \
   -lameopts abr:br=64 \
   -ovc xvid \
   -xvidencopts pass=2:bitrate=250 \
   -o 250bit-xvid.avi

Storage space is simply wasted if you encode the audio track on the new video file with a higher bitrate than the audio bitrate on the original track.


Convert a video to xVid format:

transcode -i movie.mpg -o movie.avi -y xvid

[edit] divx

[edit] Using transcode

-i ((input file) -o (output) -y (format - xvid/divx)

transcode -i movie.mpg -o movie.avi -y divx

[edit] Video-CD

[edit] Using FFMPEG

ffmpeg can make VCD mpeg video files using -target where the target can be "vcd", "svcd", "dvd", "dv", "pal-vcd", "ntsc-svcd". These switches will set the output format options (bitrate, codecs, buffer sizes) automatically.

The default vcd switch makes a PAL vcd.

ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg

A ntsc vcd:

$ ffmpeg -i myfile.avi -hq -target ntsc-vcd /tmp/vcd.mpg

Same example using same quality as source:

$ ffmpeg -i myfile.avi -sameq -target vcd /tmp/vcd.mpg

Converting a file for VCD format using a and b frames for MPEG 2:

$ ffmpeg -i myfile.avi -target ntsc-vcd -bf 2 /home/user/Video/vcd.mpg

[edit] Flash video (flv)

ffmpeg is the best choice for making flash video sites (.flv files). The syntax is simple:

ffmpeg -i inputfile.avi flashfile.flv

A parameter you likely want is -ab, audio bitrate. The default is 64, which may be fine for home videos, but is is too poor if you want to promote your local talented singer in a music video. Example:

ffmpeg -i musicvideo.mpg -ab 256 Som_du_visnar2.flv

Also note that .flv files do not support a samlerate of 48000, but it will convert using the original file's rate anyway and fault on exit. Flash video can have a sample rate of 44100, 22050 and 11025. Set the audio sampling frequency with -ar freq (usually -ar 44100) if the original file has something other than the valid rates.

Options you may want to consider:

-ab (number)     # audio bitrate
-ar freq         # audio sampling frequency
-b video bitrate # defaults to 200, which is kind of low

You should also be aware of -sameq. This makes the video the same quality as the original, but tends to make flash video files twice the size as original mpeg's. This is bad when it comes to serving files, but it may be worth it if you really want your flash video to have high quality (and you have the bandwidth..).

[edit] DVD

[edit] Using FFMPEG

ffmpeg can also make DVD video files using -target, where the target can be "vcd", "svcd", "dvd", "dv", "pal-vcd", "ntsc-svcd".

ffmpeg -i myfile.avi -target ntsc-dvd /tmp/dvd.mpg
Personal tools
Privacy policy
linux events
games
ipv6
Linux Reviews
IPv6

Search:

linux newz | random page | poetry | free blog | adult dating

You are using a insecure IPv4 connection. Click here to enable SSL encryption..
You can also connect secure and anonymously if you are using Tor.