Difference between revisions of "Encoding from command line"

From Alessandro's Wiki
Line 30: Line 30:
  codec=mpeg2video:vrc_buf_size=1835:keyint=15:vrc_maxrate=9800:vbitrate=4900:aspect=16/9:acodec=ac3:abitrate=192 \
  codec=mpeg2video:vrc_buf_size=1835:keyint=15:vrc_maxrate=9800:vbitrate=4900:aspect=16/9:acodec=ac3:abitrate=192 \
  -o /fileout.mpeg2  /filein.mpg
  -o /fileout.mpeg2  /filein.mpg
==== Scalare ====
mencoder video.mpg -oav copy -ovc copy -vf scale=120:100 -o scaled.mpg
==== PAL Fullscreen ====
==== PAL Fullscreen ====
  mencoder -of mpeg -mpegopts format=dvd:vaspect=4/3:vframerate=25 -srate 48000 \
  mencoder -of mpeg -mpegopts format=dvd:vaspect=4/3:vframerate=25 -srate 48000 \
Line 38: Line 35:
  codec=mpeg2video:vrc_buf_size=1835:keyint=15:vrc_maxrate=9800:vbitrate=4900:aspect=4/3:acodec=ac3:abitrate=192 \
  codec=mpeg2video:vrc_buf_size=1835:keyint=15:vrc_maxrate=9800:vbitrate=4900:aspect=4/3:acodec=ac3:abitrate=192 \
  -o /fileout.mpeg2  /filein.mpg
  -o /fileout.mpeg2  /filein.mpg
====  Encode DVD title #2, only selected chapters: ====
mencoder dvd://2 -chapter 10-15 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4
==== Encode DVD title #2, resizing to 640x480:====
mencoder dvd://2 -vf scale=640:480 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4
==== Encode DVD title #2, resizing to 512xHHH (keep aspect ratio):====
mencoder dvd://2 -vf scale -zoom -xy 512 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4
==== The same, but with bitrate set to 1800kbit and optimized macroblocks:====
mencoder dvd://2 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4:mbd=1:vbitrate=1800
==== The same, but with MJPEG compression:====
mencoder dvd://2 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mjpeg:mbd=1:vbitrate=1800
----


=== Filters ===
=== Filters ===
==== Crop a video ====
==== Scale ====
mencoder video.mpg -oav copy -ovc copy -vf scale=120:100 -o scaled.mpg
==== Crop ====
  mplayer -vf crop=470:350:5:100 "$fileee"
  mplayer -vf crop=470:350:5:100 "$fileee"
==== tagliare un video dal secondo minuto ('''120''') fino a 20 secondi dopo
mencoder  -ss '''120''' -endpos '''15''' video.avi -o video_tagliato.avi -ovc lavc
==== Tagliare solo i primi 30 min (1800 sec.)====
mencoder -endpos 1800 rec-CUATRO-20070213-01:30.avi -o /mirror160/_video/__Temp/rec-CUATRO-20070213-01:30_tagliato.avi -ovc copy -oac copy
----


=== Television/Camera ===
=== Television/Camera ===
Line 55: Line 73:
Oppure
Oppure
  mencoder  tv:// -tv driver=v4l:width=320:height=240:fps=15:outfmt=rgb24:device=/dev/video0:alsa:forceaudio -flip -ofps 11.44 -ovc lavc -lavcopts vcodec=rv10 -oac pcm -noskip -o prova.avi
  mencoder  tv:// -tv driver=v4l:width=320:height=240:fps=15:outfmt=rgb24:device=/dev/video0:alsa:forceaudio -flip -ofps 11.44 -ovc lavc -lavcopts vcodec=rv10 -oac pcm -noskip -o prova.avi
----


=== Images... ===
=== Images... ===
Line 60: Line 80:
estrarre il 1° frame
estrarre il 1° frame
  ffmpeg -i <file sorgente> -ss 00:00:00 -t 0.04 -f mjpeg <outputfile.jpg>
  ffmpeg -i <file sorgente> -ss 00:00:00 -t 0.04 -f mjpeg <outputfile.jpg>
==== Generate gif89a (-gif animation) mplayer from a video ====
mplayer mov03331.mpg -loop 0 -vo gif89a:fps=15.0:output=caffe1.gif
----


=== Network ===
=== Network ===
Line 73: Line 97:
  mencoder  dumpato_montato.avi -o dumpato_copresv.avi  -oac copy  -ovc lavc -of mpeg -lavcopts vcodec=mpeg2video -ofps 1
  mencoder  dumpato_montato.avi -o dumpato_copresv.avi  -oac copy  -ovc lavc -of mpeg -lavcopts vcodec=mpeg2video -ofps 1


==== Fare il dumpo di un stream (TV da internet per esempio) in XVID ====
mencoder mms://sream
-ovc xvid  -xvidencopts bitrate=1150 -vf scale=640:480 -oac mp3lame -o fileout.avi
==== ...In  DV ====
mencoder timegousbyconloli.avi -ovc libdv -vf scale=720:576 -oac pcm -o timegousbyconlolippp.avi
==== Ascoltare l'audio di mplayer in un host remoto: Vedi [[ESOUND]] ====
==== Ascoltare l'audio di mplayer in un host remoto: Vedi [[ESOUND]] ====
* faccio partire il server audio di rete su elwood:
* faccio partire il server audio di rete su elwood:
Line 88: Line 117:
  mplayer -ao esd:elwood:9876  r24-24luglio.avi
  mplayer -ao esd:elwood:9876  r24-24luglio.avi


==== encodare un video in flv (avi to flv) (mpg to flv) con ffmpeg ====
 
ffmpeg -y -i dumpato2.avi -acodec mp3 -f flv dumpato2.flv
----


==== Motion JPEG audio PCM ====
==== Motion JPEG audio PCM ====
Line 104: Line 133:




==== Fare il dumpo di un stream (TV da internet per esempio) in XVID ====
----
mencoder mms://sream
-ovc xvid  -xvidencopts bitrate=1150 -vf scale=640:480 -oac mp3lame -o fileout.avi
==== ...In qualità DV ====
mencoder timegousbyconloli.avi -ovc libdv -vf scale=720:576 -oac pcm -o timegousbyconlolippp.avi
==== tagliare un video dal secondo minuto ('''120''') fino a 20 secondi dopo
mencoder  -ss '''120''' -endpos '''15''' video.avi -o video_tagliato.avi -ovc lavc
==== Tagliare solo i primi 30 min (1800 sec.)====
mencoder -endpos 1800 rec-CUATRO-20070213-01:30.avi -o /mirror160/_video/__Temp/rec-CUATRO-20070213-01:30_tagliato.avi -ovc copy -oac copy
che prestazioni!
Pos:1494.0s  37349f ( 9%) 1469.33fps Trem:  4min 10447mb  A-V:0.040 [5154:128]


=== Theora ===
=== Theora ===
Line 140: Line 159:
   | oggfwd icast2server 8000 password /theora.ogv
   | oggfwd icast2server 8000 password /theora.ogv


==== Fare una gif89a (-gif animata) con mplayer da un video.====
mplayer mov03331.mpg -loop 0 -vo gif89a:fps=15.0:output=caffe1.gif


==== Informazioni mandando in Play da MPLAYER ====
==== Informazioni mandando in Play da MPLAYER ====
Line 150: Line 166:


==== EXAMPLES OF MENCODER USAGE  (from ~$ man mencoder) ====
==== EXAMPLES OF MENCODER USAGE  (from ~$ man mencoder) ====
* Encode DVD title #2, only selected chapters: ===
 
mencoder dvd://2 -chapter 10-15 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4
*Encode DVD title #2, resizing to 640x480:
mencoder dvd://2 -vf scale=640:480 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4
*Encode DVD title #2, resizing to 512xHHH (keep aspect ratio):
mencoder dvd://2 -vf scale -zoom -xy 512 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4
*The same, but with bitrate set to 1800kbit and optimized macroblocks:
mencoder dvd://2 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4:mbd=1:vbitrate=1800
*The same, but with MJPEG compression:
mencoder dvd://2 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mjpeg:mbd=1:vbitrate=1800
*Encode all *.jpg files in the current directory:
*Encode all *.jpg files in the current directory:
  mencoder "mf://*.jpg" -mf fps=25 -o output.avi -ovc lavc -lavcopts vcodec=mpeg4
  mencoder "mf://*.jpg" -mf fps=25 -o output.avi -ovc lavc -lavcopts vcodec=mpeg4
*Encode from a tuner (specify a format with -vf format):
*Encode from a tuner (specify a format with -vf format):
  mencoder -tv driver=v4l:width=640:height=480 tv:// -o tv.avi -ovc rawnuv
  mencoder -tv driver=v4l:width=640:height=480 tv:// -o tv.avi -ovc rawnuv
*Encode from a pipe:
rar p test-SVCD.rar | mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=800 -ofps 24 -




=== MPEG 2 ===
=== MPEG2 M2S MPEGII ===
http://www.mplayerhq.hu/DOCS/HTML/en/index.html
http://www.mplayerhq.hu/DOCS/HTML/en/index.html
http://forum.doom9.org/archive/index.php/t-110761.html
http://forum.doom9.org/archive/index.php/t-110761.html
Line 198: Line 203:
==== PES (Packetized Elementary Stream) ====
==== PES (Packetized Elementary Stream) ====


=== DA MPG A DV ===
=== DV ===


esempio da Mpg DVD (vob) a DV non compresso:
==== From Mpeg DVD (vob) ====


  ffmpeg -i /mnt/win/linux/dvd_da_convertire/kidd-pivot-01.MPG -target dv /media/LACIE/temp/kidd-pivot-01.dv
  ffmpeg -i /mnt/win/linux/dvd_da_convertire/kidd-pivot-01.MPG -target dv /media/LACIE/temp/kidd-pivot-01.dv


=== Formati 3pg cellulari ===
=== 3pg Mobile Phones ===
* Nokia XpressMusic, display:320x240
* Nokia XpressMusic, display:320x240


mpeg4 libamr_nb
==== mpeg4 libamr_nb ====
  ffmpeg -i "$video" -s 320x240 -r 14.99 -vcodec mpeg4 -ac 1 -ar 8000 -acodec libamr_nb -b 80k -ab 10.2k -y $out
  ffmpeg -i "$video" -s 320x240 -r 14.99 -vcodec mpeg4 -ac 1 -ar 8000 -acodec libamr_nb -b 80k -ab 10.2k -y $out
mpeg4 libamr_wb (va a scatti l'audio)
==== mpeg4 libamr_wb (va a scatti l'audio) ====
  ffmpeg -i "$video" -s 320x240 -r 14.99 -vcodec mpeg4 -ac 1 -ar 8000 -acodec libamr_nb -b 224k -ab 12.2k  
  ffmpeg -i "$video" -s 320x240 -r 14.99 -vcodec mpeg4 -ac 1 -ar 8000 -acodec libamr_nb -b 224k -ab 12.2k  
mpeg4 libamr_wb (va a scatti l'audio)
==== mpeg4 libamr_wb (va a scatti l'audio) ====
  ffmpeg -i "$video" -s 320x240 -r 14.99 -vcodec mpeg4 -ac 1 -ar 16000 -acodec libamr_wb -b 100k -ab 18.25k -y   
  ffmpeg -i "$video" -s 320x240 -r 14.99 -vcodec mpeg4 -ac 1 -ar 16000 -acodec libamr_wb -b 100k -ab 18.25k -y   


  ffmpeg -i "$video" -s 320x240 -r 14.99 -vcodec mpeg4 -ac 1 -ar 16000 -acodec libamr_wb -b 80k -ab 12.65k -y  
  ffmpeg -i "$video" -s 320x240 -r 14.99 -vcodec mpeg4 -ac 1 -ar 16000 -acodec libamr_wb -b 80k -ab 12.65k -y  
h263p mp3 (non letto da cell Nokia per via dell'audio mp3)
==== h263p mp3 (non letto da cell Nokia per via dell'audio mp3) ====
  ffmpeg -i "$video" -s qcif    -r 20    -vcodec h263p -acodec mp3 -ar 22050 -b 128k -ab 32k -y $out
  ffmpeg -i "$video" -s qcif    -r 20    -vcodec h263p -acodec mp3 -ar 22050 -b 128k -ab 32k -y $out
----


=== H.264 (x264) ===
=== H.264 (x264) ===
Line 225: Line 232:
http://en.wikipedia.org/wiki/H.264
http://en.wikipedia.org/wiki/H.264


Very high quality
====Very high quality====
  subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b 6fps 0dB
  subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b 6fps 0dB
High quality
====High quality====
  subq=5:8x8dct:frameref=2:bframes=3:b_pyramid:weight_b 13fps -0.89dB
  subq=5:8x8dct:frameref=2:bframes=3:b_pyramid:weight_b 13fps -0.89dB
Fast
====Fast====
  subq=4:bframes=2:b_pyramid:weight_b 17fps -1.48dB
  subq=4:bframes=2:b_pyramid:weight_b 17fps -1.48dB


Line 235: Line 242:


  level_idc=41:bframes=3:frameref=2:nopsnr:nossim:pass=1:threads=auto
  level_idc=41:bframes=3:frameref=2:nopsnr:nossim:pass=1:threads=auto
----
 
  mencoder $ifile -of avi -vf scale=352:288 -ovc x264 -x264encopts bitrate=1000:subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b:threads=auto -o Desktop/test2641.avi
  mencoder $ifile -of avi -vf scale=352:288 -ovc x264 -x264encopts bitrate=1000:subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b:threads=auto -o Desktop/test2641.avi
   
   
Line 242: Line 249:
  mencoder $ifile -of avi -ovc x264 -x264encopts bitrate=500:subq=5:8x8dct:frameref=2:bframes=3:b_pyramid:weight_b:threads=auto -o Desktop/test2641.avi
  mencoder $ifile -of avi -ovc x264 -x264encopts bitrate=500:subq=5:8x8dct:frameref=2:bframes=3:b_pyramid:weight_b:threads=auto -o Desktop/test2641.avi


=== Per AVID ===
----
 
=== AVID ===
  ffmpeg -i ../hi/1906.dv -vcodec libx264 -b 4096000 -t 10 -subq 6 -acodec libfaac -ar 48000 -ab 128000 -ac 2 -f mp4  1906_ffmpeg_Afaac_Vx264.mp4
  ffmpeg -i ../hi/1906.dv -vcodec libx264 -b 4096000 -t 10 -subq 6 -acodec libfaac -ar 48000 -ab 128000 -ac 2 -f mp4  1906_ffmpeg_Afaac_Vx264.mp4
  ffmpeg -i ../hi/1906.dv -vcodec libx264 -b 4096000 -t 10 -subq 6 -acodec libfaac -ac 2 -f mp4  1906_ffmpeg_Afaac_Vx264.mp4
  ffmpeg -i ../hi/1906.dv -vcodec libx264 -b 4096000 -t 10 -subq 6 -acodec libfaac -ac 2 -f mp4  1906_ffmpeg_Afaac_Vx264.mp4


=== Working PIPE ===
----
 
=== Working with PIPEs ===


* esempio da omf file di avid
* esempio da omf file di avid
Line 260: Line 271:
  dvgrab --autosplit --format raw -|ffmpeg -f dv -i - -target vcd f.mpg
  dvgrab --autosplit --format raw -|ffmpeg -f dv -i - -target vcd f.mpg


elwood _musicali # for a in ls ./*.* ; do ffmpeg -y -i "$a" -acodec mp3 -f flv /scratch/`echo "$a"|sed -e s@' '@'_'@g`; done
*Encode from a pipe:
rar p test-SVCD.rar | mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=800 -ofps 24 -


=== parametri FFmpeg ===
----
Main options:
  -L                  show license
  -h                  show help
  -version            show version
  -formats            show available formats, codecs, protocols, ...
  -f fmt              force format
  -img img_fmt        force image format
  -i filename        input file name
  -y                  overwrite output files
  -t duration        set the recording time
  -fs limit_size      set the limit file size
  -ss time_off        set the start time offset
  -itsoffset time_off  set the input ts offset
  -title string      set the title
  -timestamp time    set the timestamp
  -author string      set the author
  -copyright string  set the copyright
  -comment string    set the comment
  -v verbose          control amount of logging
  -target type        specify target file type ("vcd", "svcd", "dvd", "dv", "pal-vcd", "ntsc-svcd", ...)
  -dframes number    set the number of data frames to record
  -hq                activate high quality settings
  -scodec codec      force subtitle codec ('copy' to copy stream)
  -newsubtitle        add a new subtitle stream to the current output stream
  -slang code        set the ISO 639 language code (3 letters) of the current subtitle stream


  Video options:
===  Flash FLV ===
  -b bitrate          set video bitrate (in kbit/s)
==== encode in flv (avi to flv) (mpg to flv) ffmpeg ====
  -vframes number    set the number of video frames to record
ffmpeg -y -i dumpato2.avi -acodec mp3 -f flv dumpato2.flv
  -r rate            set frame rate (Hz value, fraction or abbreviation)
  -s size            set frame size (WxH or abbreviation)
  -aspect aspect      set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
  -fixaspect          fix aspect ratio
  -croptop size      set top crop band size (in pixels)
  -cropbottom size    set bottom crop band size (in pixels)
  -cropleft size      set left crop band size (in pixels)
  -cropright size    set right crop band size (in pixels)
  -padtop size        set top pad band size (in pixels)
  -padbottom size    set bottom pad band size (in pixels)
  -padleft size      set left pad band size (in pixels)
  -padright size      set right pad band size (in pixels)
  -padcolor color    set color of pad bands (Hex 000000 thru FFFFFF)
  -vn                disable video
  -bt tolerance      set video bitrate tolerance (in kbit/s)
  -maxrate bitrate    set max video bitrate tolerance (in kbit/s)
  -minrate bitrate    set min video bitrate tolerance (in kbit/s)
  -bufsize size      set ratecontrol buffer size (in kByte)
  -vcodec codec      force video codec ('copy' to copy stream)
  -sameq              use same video quality as source (implies VBR)
  -pass n            select the pass number (1 or 2)
  -passlogfile file  select two pass log file name
  -newvideo          add a new video stream to the current output stream


  Advanced Video options:
  video_directory/ # for clip in ls ./*.* ; do ffmpeg -y -i "$clip" -acodec mp3 -f flv /scratch/`echo "$clip"|sed -e s@' '@'_'@g`; done
  -pix_fmt format    set pixel format
  -g gop_size        set the group of picture size
  -intra              use only intra frames
  -vdt n              discard threshold
  -qscale q          use fixed video quantiser scale (VBR)
  -qmin q            min video quantiser scale (VBR)
  -qmax q            max video quantiser scale (VBR)
  -lmin lambda        min video lagrange factor (VBR)
  -lmax lambda        max video lagrange factor (VBR)
  -mblmin q          min macroblock quantiser scale (VBR)
  -mblmax q          max macroblock quantiser scale (VBR)
  -qdiff q            max difference between the quantiser scale (VBR)
  -qblur blur        video quantiser scale blur (VBR)
  -qsquish squish    how to keep quantiser between qmin and qmax (0 = clip, 1 = use differentiable function)
  -qcomp compression video quantiser scale compression (VBR)
  -rc_init_cplx complexity  initial complexity for 1-pass encoding
  -b_qfactor factor  qp factor between p and b frames
  -i_qfactor factor  qp factor between p and i frames
  -b_qoffset offset  qp offset between p and b frames
  -i_qoffset offset  qp offset between p and i frames
  -ibias bias        intra quant bias
  -pbias bias        inter quant bias
  -rc_eq equation    set rate control equation
  -rc_override override  rate control override for specific intervals
  -me method          set motion estimation method
  -dct_algo algo      set dct algo
  -idct_algo algo    set idct algo
  -me_threshold      motion estimaton threshold
  -mb_threshold      macroblock threshold
  -er n              set error resilience
  -ec bit_mask        set error concealment
  -bf frames          use 'frames' B frames
  -mbd mode          macroblock decision
  -mbcmp cmp function  macroblock compare function
  -ildctcmp cmp function  ildct compare function
  -subcmp cmp function  subpel compare function
  -cmp cmp function  fullpel compare function
  -precmp cmp function  pre motion estimation compare function
  -preme              pre motion estimation
  -lelim elim        single coefficient elimination threshold for luminance (negative values also consider DC coefficient)
  -celim elim        single coefficient elimination threshold for chrominance (negative values also consider DC coefficient)
  -lumi_mask          luminance masking
  -dark_mask          darkness masking
  -scplx_mask        spatial complexity masking
  -tcplx_mask        temporal complexity masking
  -p_mask            inter masking
  -4mv                use four motion vector by macroblock (MPEG4)
  -obmc              use overlapped block motion compensation (h263+)
  -lf                use loop filter (h263+)
  -part              use data partitioning (MPEG4)
  -bug param          workaround not auto detected encoder bugs
  -strict strictness  how strictly to follow the standards
  -deinterlace        deinterlace pictures
  -ildct              force interlaced dct support in encoder (MPEG2/MPEG4)
  -ilme              force interlaced me support in encoder (MPEG2/MPEG4)
  -psnr              calculate PSNR of compressed frames
  -vstats            dump video coding statistics to file
  -vhook module      insert video processing module
  -aic                enable Advanced intra coding (h263+)
  -aiv                enable Alternative inter vlc (h263+)
  -umv                enable Unlimited Motion Vector (h263+)
  -ssm                enable Slice Structured mode (h263+)
  -alt                enable alternate scantable (MPEG2/MPEG4)
  -qprd             
  -cbp               
  -trell              enable trellis quantization
  -mv0                try to encode each MB with MV=<0,0> and choose the better one (has no effect if mbd=0)
  -naq                normalize adaptive quantization
  -cgop              closed gop
  -sgop              strict gop
  -noout              skip bitstream encoding
  -scan_offset        enable SVCD Scan Offset placeholder
  -qpel              enable 1/4-pel
  -intra_matrix matrix  specify intra matrix coeffs
  -inter_matrix matrix  specify inter matrix coeffs
  -top                top=1/bottom=0/auto=-1 field first
  -nr                noise reduction
  -qns                quantization noise shaping
  -sc_threshold threshold  scene change threshold
  -me_range range    limit motion vectors range (1023 for DivX player)
  -dc precision      intra_dc_precision
  -coder              coder type
  -context            context model
  -pred              prediction method
  -vprofile          profile
  -vlevel            level
  -nssew              weight
  -subq             
  -mepc factor (1.0 = 256)  motion estimation bitrate penalty compensation
  -lowres           
  -vtag fourcc/tag    force video tag/fourcc
  -skip_threshold threshold  frame skip threshold
  -skip_factor factor  frame skip factor
  -skip_exp exponent  frame skip exponent
  -skip_cmp compare function  frame skip compare function
  -gray              encode/decode grayscale


  Audio options:
----
  -aframes number    set the number of audio frames to record
  -ab bitrate        set audio bitrate (in kbit/s)
  -ar rate            set audio sampling rate (in Hz)
  -ac channels        set number of audio channels
  -an                disable audio
  -acodec codec      force audio codec ('copy' to copy stream)
  -vol volume        change audio volume (256=normal)
  -newaudio          add a new audio stream to the current output stream
  -alang code        set the ISO 639 language code (3 letters) of the current audio stream
 
  Advanced Audio options:
  -atag fourcc/tag    force audio tag/fourcc
 
  Subtitle options:
  -scodec codec      force subtitle codec ('copy' to copy stream)
  -newsubtitle        add a new subtitle stream to the current output stream
  -slang code        set the ISO 639 language code (3 letters) of the current subtitle stream
 
  Audio/Video grab options:
  -vd device          set video grab device
  -vc channel        set video grab channel (DV1394 only)
  -tvstd standard    set television standard (NTSC, PAL (SECAM))
  -ad device          set audio device
  -grab format        request grabbing using
  -gd device          set grab device


  Advanced options:
=== Problem -> Solution ===
  -map file:stream[:syncfile:syncstream]  set input stream mapping
  -map_meta_data outfile:infile  set meta data information of outfile from infile
  -debug              print specific debug info
  -vismv              visualize motion vectors
  -benchmark          add timings for benchmarking
  -dump              dump each input packet
  -hex                when dumping packets, also dump the payload
  -bitexact          only use bit exact algorithms (for codec testing)
  -re                read input at native frame rate
  -loop              loop (current only works with images)
  -loop_output        number of times to loop output in formats that support looping (0 loops forever)
  -threads count      thread count
  -vsync              video sync method
  -async              audio sync method
  -vglobal            video global header storage type
  -copyts            copy timestamps
  -shortest          finish encoding within shortest input
  -b_strategy strategy  dynamic b frame selection strategy
  -ps size            set packet size in bits
  -error rate        error rate
  -muxrate rate      set mux rate
  -packetsize size    set packet size
  -muxdelay seconds  set the maximum demux-decode delay
  -muxpreload seconds  set the initial demux-decode delay
  -muxab bitrate      set the audio bitrate in mux tag (in kbit/s)
  -muxvb bitrate      set the video bitrate in mux tag (in kbit/s)


=== Problema -> Soluzione ===
==== Encoding ====
==== Encoding ====
* convertendo in x264 con RedHat 5.2 il video in uscita risulta corrotto
* convertendo in x264 con RedHat 5.2 il video in uscita risulta corrotto  
** is the x264 library that updatig casuses the problem

Revision as of 12:55, 8 January 2010

elwood _musicali # for a in ls ./*.* ; do ffmpeg -y -i "$a" -acodec mp3 -f flv /scratch/`echo "$a"|sed -e s@' '@'_'@g`; done

Quick commands to Encode/Decode Multimedia files

DVD

Rip DVD to DivX

  1. count dvd titles, this example is using 8 of them:
  2. audio:
mencoder dvd://1 -ovc frameno -o frameno.avi -oac mp3lame -lameopts vbr=3 -alang es -chapter 1-8
  1. video.
  2. last command output will suggest a vbitrate=xxx value:
mencoder dvd://1 -ovc lavc -lavcopts vcodec=mpeg4:vhq:v4mv:vbitrate=1000:vpass=1 -oac copy -o movie.avi -chapter 1-8
mencoder dvd://1 -ovc lavc -lavcopts vcodec=mpeg4:vhq:v4mv:vbitrate=1000:vpass=2 -oac copy -o movie.avi -chapter 1-8
  1. divx will be movie.avi.

Rip DVD generic

modo I

mencoder /dev/dvd-hdd -o CINEMA_STRANGE.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4

modo II ~15 Min.

mencoder dvd://1 -ovc frameno -o frameno.avi -oac mp3lame -lameopts vbr=3 -alang es -chapter 1-8

~100 Min.

mencoder dvd://1  -ovc lavc -lavcopts vcodec=mpeg4:vhq:v4mv:vbitrate=1130:vpass=1 -oac copy -o movie.avi -chapter 1-8 
mencoder dvd://1  -ovc lavc -lavcopts vcodec=mpeg4:vhq:v4mv:vbitrate=1130:vpass=2 -oac copy -o movie.avi -chapter 1-8 

DVD 4:3

mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:576 \
-srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video -ofps 25 \
-o /fileout.mpg /filein.avi

PAL Widescreen

mencoder -of mpeg -mpegopts format=dvd:vaspect=16/9:vframerate=25 -srate 48000 \
-ofps 25 -ovc lavc -oac lavc -lavcopts \
codec=mpeg2video:vrc_buf_size=1835:keyint=15:vrc_maxrate=9800:vbitrate=4900:aspect=16/9:acodec=ac3:abitrate=192 \
-o /fileout.mpeg2  /filein.mpg

PAL Fullscreen

mencoder -of mpeg -mpegopts format=dvd:vaspect=4/3:vframerate=25 -srate 48000 \
-ofps 25 -ovc lavc -oac lavc -lavcopts \
codec=mpeg2video:vrc_buf_size=1835:keyint=15:vrc_maxrate=9800:vbitrate=4900:aspect=4/3:acodec=ac3:abitrate=192 \
-o /fileout.mpeg2  /filein.mpg

Encode DVD title #2, only selected chapters:

mencoder dvd://2 -chapter 10-15 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4

Encode DVD title #2, resizing to 640x480:

mencoder dvd://2 -vf scale=640:480 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4

Encode DVD title #2, resizing to 512xHHH (keep aspect ratio):

mencoder dvd://2 -vf scale -zoom -xy 512 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4

The same, but with bitrate set to 1800kbit and optimized macroblocks:

mencoder dvd://2 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4:mbd=1:vbitrate=1800

The same, but with MJPEG compression:

mencoder dvd://2 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mjpeg:mbd=1:vbitrate=1800



Filters

Scale

mencoder video.mpg -oav copy -ovc copy -vf scale=120:100 -o scaled.mpg

Crop

mplayer -vf crop=470:350:5:100 "$fileee"

==== tagliare un video dal secondo minuto (120) fino a 20 secondi dopo

mencoder  -ss 120 -endpos 15 video.avi -o video_tagliato.avi -ovc lavc

Tagliare solo i primi 30 min (1800 sec.)

mencoder -endpos 1800 rec-CUATRO-20070213-01:30.avi -o /mirror160/_video/__Temp/rec-CUATRO-20070213-01:30_tagliato.avi -ovc copy -oac copy

Television/Camera

Registrare dal DVB (Digital Video Broadcasting)

  • Satellite o digitale terrestre.
mencoder dvb://CUATRO  -ovc copy -oac copy -o Film.avi

Non ricordo...

mplayer -vo mpegpes -ao mpegpes -vop lavc=5000:25,expand=688:576:-1:-1:1,scale=688:563   -cache 8192 -slave -nolirc  -subpos 80 -sub-bg-color 0 -sub-bg-alpha 255 -quiet

Guardo la webcam con mplayer

mplayer tv:// -tv driver=v4l:width=640:height=480:outfmt=rgb24:device=/dev/video0:noaudio -flip

Registro la webcam con mencoder...

mencoder tv:// -tv driver=v4l:width=640:height=480:outfmt=rgb24:device=/dev/video0:noaudio -flip -o camed.avi -ovc lavc

Oppure

mencoder  tv:// -tv driver=v4l:width=320:height=240:fps=15:outfmt=rgb24:device=/dev/video0:alsa:forceaudio -flip -ofps 11.44 -ovc lavc -lavcopts vcodec=rv10 -oac pcm -noskip -o prova.avi

Images...

cacciare un frame con ffmpeg verso jpg - estrazione 1° frame in jpg

estrarre il 1° frame

ffmpeg -i <file sorgente> -ss 00:00:00 -t 0.04 -f mjpeg <outputfile.jpg>

Generate gif89a (-gif animation) mplayer from a video

mplayer mov03331.mpg -loop 0 -vo gif89a:fps=15.0:output=caffe1.gif

Network

Save a stream

mplayer http://mplayer.hq/example.avi -dumpstream -dumpfile dumpato.avi

Grabando ,cortando y comprimiendo un stream de tv3

mplayer "mms://directe.3alacarta.tvcatalunya.com/reflector:60738?auth=db.bWbEd.dWc5b.asaRazb4daaCcmcPdfaU-bgZTm9-8-vga-KFlmE-r8qcl7ram6o6phj6rgmllkpjp7r7j9l9r8q7l6ramapkqkkjr9mllkpjqksikmmnslrimjsGnwpkqkkjsImqlo&aifp=fhgt&WMCache=0" -dumpstream -dumpfile dumpato.avi
mencoder  -ss 826.5  dumpato.avi -o dumpato_tagliato.avi -ovc copy -oac copy

mencoder  -endpos 108  dumpato_tagliato.avi -o dumpato_montato.avi
mencoder  dumpato_montato.avi -o dumpato_copresv.avi  -oac copy  -ovc lavc -of mpeg -lavcopts vcodec=mpeg2video -ofps 1

Fare il dumpo di un stream (TV da internet per esempio) in XVID

mencoder mms://sream
-ovc xvid  -xvidencopts bitrate=1150 -vf scale=640:480 -oac mp3lame -o fileout.avi

...In DV

mencoder timegousbyconloli.avi -ovc libdv -vf scale=720:576 -oac pcm -o timegousbyconlolippp.avi

Ascoltare l'audio di mplayer in un host remoto: Vedi ESOUND

  • faccio partire il server audio di rete su elwood:
[xunil@elwood ~]$ esd -tcp -port 9876 -public &
[1] 3849
- accepting connections on port 9876
  • Apro il video (uno stream in questo caso) specificando host e porta del server audio
[xunil@zombie ~]$ mplayer -ao esd:elwood:9876 mms://rntlivewm.rai.it/_rn24_live_
  • così vedo il vido su zombie e sento l'audio su elwood, cioè vedo dalla cucina e sento dalla camera da letto, non proprio comodo:
  • allora trorno in camera, da elwood, e faccio:
[xunil@elwood ~]$ ssh -X zombie mplayer -ao esd:elwood:9876 mms://rntlivewm.rai.it/_rn24_live_
  • adesso la situazione è strana, una persona normale, sana non noterebbe differenza tra "fare doppio click" sul video o

Mandare l'audio su un altro host (elwood)

mplayer -ao esd:elwood:9876  r24-24luglio.avi



Motion JPEG audio PCM

il "2> /dev/null" serve per 'buttare' lo standard error, nel caso qualcosa non funzioni, rimuoverlo dal comando.

mencoder video.avi -oac pcm -ovc lavc -lavcopts vcodec=mjpeg -o MJPEG_video.avi 2> /dev/null

Motion PNG (MPNG)

mencoder mf://*.png -mf w=800:h=600:fps=25:type=png -ovc copy -oac copy -o output.avi

Motion TGA (MTGA)

mencoder mf://*.tga -mf w=800:h=600:fps=25:type=tga -ovc copy -oac copy -o output.avi



Theora

Convert TO theora

  • Examples: (from ffmpeg2theora help)
ffmpeg2theora videoclip.avi (will write output to videoclip.ogv)
ffmpeg2theora videoclip.avi --subtitles subtitles.srt (same, with subtitles)
cat something.dv | ffmpeg2theora -f dv -o output.ogv -
  • Encode a series of images:
ffmpeg2theora frame%06d.png -o output.ogv
  • Live streaming from V4L Device:
ffmpeg2theora /dev/video0 -f video4linux --inputfps 15 -x 160 -y 128 -o - \
| oggfwd icast2server 8000 password /theora.ogv
  • Live encoding from a DV camcorder (needs a fast machine):
dvgrab - | ffmpeg2theora -f dv -x 352 -y 288 -o output.ogv -
  • Live encoding and streaming to icecast server:
 dvgrab --format raw - \
  | ffmpeg2theora -f dv -x 160 -y 128 -o /dev/stdout - \
  | oggfwd icast2server 8000 password /theora.ogv


Informazioni mandando in Play da MPLAYER

Eseguendo il comando che segue , le opzioni '-v -identify' ci posso dare delle informazioni molto utili del video che mandiamo in PLAY:

 mplayer -v -identify -aspect 4:3 /root/Desktop/Prova03.avi  

EXAMPLES OF MENCODER USAGE (from ~$ man mencoder)

  • Encode all *.jpg files in the current directory:
mencoder "mf://*.jpg" -mf fps=25 -o output.avi -ovc lavc -lavcopts vcodec=mpeg4
  • Encode from a tuner (specify a format with -vf format):
mencoder -tv driver=v4l:width=640:height=480 tv:// -o tv.avi -ovc rawnuv


MPEG2 M2S MPEGII

http://www.mplayerhq.hu/DOCS/HTML/en/index.html http://forum.doom9.org/archive/index.php/t-110761.html

  • mencoder

OPZIONI DEMUXER/FLUSSO (STREAM)

-pvr <opzione1:opzione2:...> (solo PVR)
Questa  opzione  imposta varie proprietà di codifica per il modulo di cattura PVR.  Deve essere usata con schede di codifica MPEG via hardware supp-
portate dal driver V4L2.  Le schede Hauppauge WinTV PVR-150/250/350/500 e tutte quelle basate su IVTV sono conosciute come schede  di  cattura  PVR.
Attenzione che solamente il kernel Linux 2.6.18 o maggiore è capace di gestire il flusso MPEG attraverso lo strato V4L2.  Per la cattura hardware di
un flusso MPEG e la visione attraverso MPlayer/MEncoder, usa ’pvr://’ come URL del filmato.
fmt=<valore>
 Seleziona un formato MPEG per la codifica:
  ps:    MPEG-2 Program Stream (default)
  ts:    MPEG-2 Transport Stream
  mpeg1: MPEG-1 System Stream
  vcd:   flusso compatibile Video CD
  svcd:  flusso compatibile Super Video CD
  dvd:   flusso compatibile DVD

TS (Transport Stream)

mencoder -of lavf -lavfopts format=mpegts \
-lavcopts vcodec=mpeg2video:acodec=mp2:abitrate=224:vbitrate=3200 -o test2_mpegts_1109.m2t \
-ovc lavc -oac lavc /export/data/mediaroot/video/mid/1109.mp4

PES (Packetized Elementary Stream)

DV

From Mpeg DVD (vob)

ffmpeg -i /mnt/win/linux/dvd_da_convertire/kidd-pivot-01.MPG -target dv /media/LACIE/temp/kidd-pivot-01.dv

3pg Mobile Phones

  • Nokia XpressMusic, display:320x240

mpeg4 libamr_nb

ffmpeg -i "$video" -s 320x240 -r 14.99 -vcodec mpeg4 -ac 1 -ar 8000 -acodec libamr_nb -b 80k -ab 10.2k -y $out

mpeg4 libamr_wb (va a scatti l'audio)

ffmpeg -i "$video" -s 320x240 -r 14.99 -vcodec mpeg4 -ac 1 -ar 8000 -acodec libamr_nb -b 224k -ab 12.2k 

mpeg4 libamr_wb (va a scatti l'audio)

ffmpeg -i "$video" -s 320x240 -r 14.99 -vcodec mpeg4 -ac 1 -ar 16000 -acodec libamr_wb -b 100k -ab 18.25k -y  
ffmpeg -i "$video" -s 320x240 -r 14.99 -vcodec mpeg4 -ac 1 -ar 16000 -acodec libamr_wb -b 80k -ab 12.65k -y 

h263p mp3 (non letto da cell Nokia per via dell'audio mp3)

ffmpeg -i "$video" -s qcif    -r 20    -vcodec h263p -acodec mp3 -ar 22050 -b 128k -ab 32k -y $out

H.264 (x264)

http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-x264.html

http://en.wikipedia.org/wiki/X264

http://en.wikipedia.org/wiki/H.264

Very high quality

subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b	6fps	0dB

High quality

subq=5:8x8dct:frameref=2:bframes=3:b_pyramid:weight_b	13fps	-0.89dB

Fast

subq=4:bframes=2:b_pyramid:weight_b	17fps	-1.48dB
mencoder -v -o video.264
level_idc=41:bframes=3:frameref=2:nopsnr:nossim:pass=1:threads=auto
mencoder $ifile -of avi -vf scale=352:288 -ovc x264 -x264encopts bitrate=1000:subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b:threads=auto -o Desktop/test2641.avi

mencoder $ifile -of avi -ovc x264 -x264encopts bitrate=3000:subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b:threads=auto -o Desktop/test2641.avi
mencoder $ifile -of avi -ovc x264 -x264encopts bitrate=500:subq=5:8x8dct:frameref=2:bframes=3:b_pyramid:weight_b:threads=auto -o Desktop/test2641.avi

AVID

ffmpeg -i ../hi/1906.dv -vcodec libx264 -b 4096000 -t 10 -subq 6 -acodec libfaac -ar 48000 -ab 128000 -ac 2 -f mp4  1906_ffmpeg_Afaac_Vx264.mp4
ffmpeg -i ../hi/1906.dv -vcodec libx264 -b 4096000 -t 10 -subq 6 -acodec libfaac -ac 2 -f mp4  1906_ffmpeg_Afaac_Vx264.mp4

Working with PIPEs

  • esempio da omf file di avid
mkfifo videopipe

Aprire nuova shell:

cat videopipe | ffmpeg -i - -target dv output.dv

Toranre alla vecchia shell:

mencoder <filevideo.omf> -ovc copy -oac pcm -o videopipe

Quando i due hanno terminato il play e l'encoding:

unlink videopipe 
  • reccare e encodare DV
dvgrab --autosplit --format raw -|ffmpeg -f dv -i - -target vcd f.mpg
  • Encode from a pipe:
rar p test-SVCD.rar | mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=800 -ofps 24 -

Flash FLV

encode in flv (avi to flv) (mpg to flv) ffmpeg

ffmpeg -y -i dumpato2.avi -acodec mp3 -f flv dumpato2.flv
video_directory/ # for clip in ls ./*.* ; do ffmpeg -y -i "$clip" -acodec mp3 -f flv /scratch/`echo "$clip"|sed -e s@' '@'_'@g`; done

Problem -> Solution

Encoding

  • convertendo in x264 con RedHat 5.2 il video in uscita risulta corrotto
    • is the x264 library that updatig casuses the problem