How to convert video files

From Wiki
Jump to: navigation, search

convert video to new format using ffmpeg:

ffmpeg -i file.avi -strict -2 -c:v libx264 file2.mp4
ffmpeg -i file.avi -strict -2 -c:v libx265 file2.mp4
ffmpeg -i video.avi -c:v libxvid video2.avi
XviD Encoding

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

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..).

(I dont know why? but i experienced FFMPEG doesnot convert all standard vodeos even in MPEG ,AVI format etc into FLV format. Do you know why? please email me at Regards )
[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