Monday 20 May 2013

Media Coversion with avconv

This is the note on using some tools at "Ubuntu" to convert different file type of source to multiple destination file type at the destination:


NOTE: 
The bit rate is quantified using the bits per second (bit/s or bps) unit.

MP3

The MP3 audio format lossy data compression. Audio quality improves with increasing bitrate.

    32 kbit/s - generally acceptable only for speech
    96 kbit/s - generally used for speech or low-quality streaming
    128 or 160 kbit/s – mid-range bitrate quality
    192 kbit/s - a commonly used high-quality bitrate
    320 kbit/s - highest level supported by MP3 standard

 Video

    128–384 kbit/s – business-oriented videoconferencing quality using video compression
    1.5 Mbit/s max – VCD quality (using MPEG1 compression)[16]
    9.8 Mbit/s max – DVD (using MPEG2 compression)[17]
    8 to 15 Mbit/s typ – HDTV quality (with bit-rate reduction from MPEG-4 AVC compression)
    19 Mbit/s approximate — HDV 720p (using MPEG2 compression)[18]
    24 Mbit/s max — AVCHD (using MPEG4 AVC compression)[19]
    25 Mbit/s approximate — HDV 1080i (using MPEG2 compression)[18]
    29.4 Mbit/s max – HD DVD
    40 Mbit/s max – Blu-ray Disc (using MPEG2, AVC or VC-1 compression)[20]

I believe youtube 320p use somewhere around 720k  [.7M] bit rate. 


The lower the bit rate the lesser the filesize but it will reduce the file quility, mean while if you use higher bit rate then the original file then you will find empty bits and that is not good.


=========================================================================
 
-> Package needed "ffmpeg"

Converting "mkv" file to "mp4" file.
 avconv -i "file_name.mkv" -c copy "file_name.mp4"

avconv [global options] [[infile options][-i infile]]... {[outfile options] outfile}...

Specified by the "-i" option, and writes to an arbitrary number of output "files", which are specified by a plain output filename. As a general rule, options are applied to the next specified file. Therefore, order is important, and you can have the same option on the command line multiple times. Each occurrence is then applied to the next input or output file.

Do not mix input and output files -- first specify all input files, then all output files. Also do not mix options which belong to different files. All options apply ONLY to the next input or output file and are reset between files.


 ·   To set the video bitrate of the output file to 64kbit/s:
avconv -i input.avi -b 64k output.avi

  ·   To force the frame rate of the output file to 24 fps: 

avconv -i input.avi -r 24 output.avi

  ·   To force the frame rate of the input file (valid for raw formats only) to 1 fps and the frame rate of the output file to 24 fps:
 avconv -r 1 -i input.m2v -r 24 output.avi

The format option may be needed for raw input files.
 -codecs
           Show available codecs. The fields preceding the codec names have the following meanings:
           D   Decoding available
           E   Encoding available
           V/A/S Video/audio/subtitle codec
           S   Codec supports slices
           D   Codec supports direct rendering
           T   Codec can handle input truncated at random locations instead of only at frame boundaries

Main options
       -f fmt (input/output)
           Force input or output file format. The format is normally autodetected for input files and guessed from file extension for output files, so this option is not needed in most cases.


 -i filename (input)
           input file name

 -y (global)
           Overwrite output files without asking.

-t duration (output)
           Stop writing the output after its duration reaches duration.  duration may be a number in seconds, or in "hh:mm:ss[.xxx]" form.
       -fs limit_size (output)
           Set the file size limit.


       -ss position (input/output)
           When used as an input option (before "-i"), seeks in this input file to position. When used as an output option (before an output filename), decodes but discards input until the timestamps reach position. This is slower, but more accurate. position may be either in seconds or in "hh:mm:ss[.xxx]" form.

   -target type (output)
           Specify target file type ("vcd", "svcd", "dvd", "dv", "dv50"). type may be prefixed with "pal-", "ntsc-" or "film-" to use the corresponding standard. All the format options (bitrate, codecs, buffer sizes) are then set automatically. 
You can just type:
                   avconv -i myfile.avi -target vcd /tmp/vcd.mpg

           Nevertheless you can specify additional options as long as you know they do not conflict with the standard, as in:
                   avconv -i myfile.avi -target vcd -bf 2 /tmp/vcd.mpg

       
-aspect[:stream_specifier] aspect (output,per-stream)
           Set the video display aspect ratio specified by aspect. aspect can be a floating point number string, or a string of the form num:den, where num and den are the numerator and denominator of the aspect ratio. For example "4:3",  "16:9", "1.3333", and "1.7777" are valid argument values.


  
 -bt tolerance
           Set video bitrate tolerance (in bits, default 4000k).  Has a minimum value of: (target_bitrate/target_framerate).  In 1-pass mode, bitrate tolerance specifies how far ratecontrol is willing to deviate from the target average bitrate value. This is not related to min/max bitrate. Lowering tolerance too much has an adverse effect on quality.


 -maxrate bitrate
           Set max video bitrate (in bit/s).  Requires -bufsize to be set.

 -minrate bitrate
           Set min video bitrate (in bit/s).  Most useful in setting up a CBR encode:
                   avconv -i myfile.avi -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v
           It is of little use elsewise.


·   You can set several input files and output files:
                   avconv -i /tmp/a.wav -s 640x480 -i /tmp/a.yuv /tmp/a.mpg

Converts the audio file a.wav and the raw YUV video file a.yuv to MPEG file a.mpg.

                   avconv -i /tmp/a.wav -map 0:a -b 64k /tmp/a.mp2 -map 0:a -b 128k /tmp/b.mp2

           Converts a.wav to a.mp2 at 64 kbits and to b.mp2 at 128 kbits. '-map file:index' specifies which input stream is used for each output stream, in the order of the definition of output streams.


 ·   You can transcode decrypted VOBs:
   avconv -i snatch_1.vob -f avi -c:v mpeg4 -b:v 800k -g 300 -bf 2 -c:a libmp3lame -b:a 128k snatch.avi

           This is a typical DVD ripping example; the input is a VOB file, the output an AVI file with MPEG-4 video and MP3 audio. Note that in this command we use B-frames so the MPEG-4 stream is DivX5 compatible, and GOP size is 300 which means one intra frame every 10 seconds for 29.97fps input video. Furthermore, the audio stream is MP3-encoded, so you need to enable LAME support by passing "--enable-libmp3lame" to configure.  The mapping is particularly useful for DVD transcoding to get the desired audio language.

 NOTE: To see the supported input formats, use "avconv -formats".


 ·   You can extract images from a video, or create a video from many images:
           For extracting images from a video:
                   avconv -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg 

 This will extract one video frame per second from the video and will output them in files named foo-001.jpeg, foo-002.jpeg, etc. Images will be rescaled to fit the new WxH values.

           If you want to extract just a limited number of frames, you can use the above command in combination with the -vframes or -t option, or in combination with -ss to start extracting from a certain point in time.
           For creating a video from many images:
                   avconv -f image2 -i foo-%03d.jpeg -r 12 -s WxH foo.avi
           The syntax "foo-%03d.jpeg" specifies to use a decimal number composed of three digits padded with zeroes to express the sequence number. It is the same syntax supported by the C printf function, but only formats accepting a normal integer are suitable.



=========================================================================


For more details man avconv.





No comments:

Post a Comment