Difference between revisions of "Encoding from command line"

From Alessandro's Wiki
 
(38 intermediate revisions by 2 users not shown)
Line 1: Line 1:
elwood _musicali # for a in ls ./*.* ; do ffmpeg -y -i "$a" -acodec mp3 -f flv /scratch/`echo "$a"|sed -e s@' '@'_'@g`; done
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 ==
== Quick commands to Encode/Decode Multimedia files ==
 
http://www.ffmpeg.org/libavfilter.html
=== DVD ===
=== DVD ===
==== Rip DVD to DivX ====
==== Rip DVD to DivX ====
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
ffmpeg -i  inputfile.mov  -acodec mp2 -ar 44100 -ac 2 -ab 112000 -vcodec mjpeg -qscale 2  output.mpg
----


=== Filters ===
=== Filters ===
==== Crop a video ====
 
* to add filters to ffmpeg or mencoder, use the option '''-vf'''
 
==== Scale ====
* with '''mencoder'''
mencoder video.mpg -oav copy -ovc copy -vf scale=120:100 -o scaled.mpg
 
* with '''ffmpeg'''
ffmpeg -i <file> -vf scale=<x>:<y> <file-cropped>
 
# x and y are pixel values
# If value is 0, the input size is used
# If value is -1, maintains the aspect ratio
#: this can brake the process having the proportional side size not divisible by 2 (x264 codecs)
# default is 0.
 
===== '''"not divisible by 2"''' (x264 issue) =====
 
* trying to upscale a video from ''854x480 [PAR 1:1 DAR 427:240]'' to -vf scale=-1:720 , got this message:
 
'' width or height not divisible by 2 (1281x720)''
 
* I'm running periodically a [http://videotecahelp.webhop.net script] encoding clips for a [http://videotecahelp.webhop.net video server], using multiple formats for every clip and scaling them respectively to x:360 , x:480 , x:720 , the common " -vf scale:-1:360 " gives "not divisible by 2" error for some input/output sizes, the solution has been found with a formula:
 
 
<syntaxhighlight lang="php" >
 
scale=ceil(a*480)+mod(ceil(a*480)\,2):480
 
</syntaxhighlight>
 
 
* in words: scale the height is proportionally to the new width plus the rest of the division by two of the proportional size. That means that, for example we take a '''480 x 352''' video and we scale it to 360, the new width (without my formula) would have been 491 (giving the codec an error) the formula divides it by 2 and ad adds the rest ( '''''1''''' ) to the output width.
 
 
* these are the calculations I've made to reach the solution:
 
<syntaxhighlight lang="php" >
a = 320 / 240 = 1,3333
scale=ceil(a*XXX):XXX
 
1080 * 1,3333 = 1439,8  ceil = 1440
720 * 1,3333  = 959,9999 ceil = 960
480 * 1,3333  = 639,9    ceil = 640
360 * 1,3333  = 479,9    ceil = 480   
 
 
a = 352 / 288 = 1,2222
scale=ceil(a*XXX):XXX
 
1080 * 1,2222 = 1,319    ceil = 1320
720 * 1,2222  = 879,9999 ceil = 880
480 * 1,2222  = 586,6    ceil = 587  ERR
360 * 1,2222  = 439,9    ceil = 440   
 
a = 480 / 352 = 1,3636
scale=ceil(a*XXX):XXX
 
1080 * 1,3636 = 1472,6  ceil = 1473  ERR
720 * 1,3636  = 981,7  ceil = 982
480 * 1,3636  = 654,5  ceil = 655    ERR
360 * 1,3636  = 490,8  ceil = 491    ERR
 
a = 480 / 264 = 1,8181
scale=ceil(a*XXX):XXX
 
1080 * 1,8181 = 1963,5  ceil = 1964 
720 * 1,8181  = 1309,03 ceil = 1310
480 * 1,8181  = 872,6  ceil = 873    ERR
360 * 1,8181  = 654,51  ceil = 655    ERR
 
 
# final expression:
scale=ceil(a*480)+mod(ceil(a*480)\,2):480
</syntaxhighlight>
 
==== 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 '''20''' 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 47: Line 141:
* Satellite o digitale terrestre.
* Satellite o digitale terrestre.
  mencoder dvb://CUATRO  -ovc copy -oac copy -o Film.avi
  mencoder dvb://CUATRO  -ovc copy -oac copy -o Film.avi
==== Non ricordo...====
==== MPEG PES...====
  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
  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 ====
==== Guardo la webcam con mplayer ====
* '''v4l2'''
mplayer -cache 128 -tv driver=v4l2:width=800:height=480:outfmt=i420:device=/dev/video0 -vo xv tv://
* '''v4l'''
  mplayer tv:// -tv driver=v4l:width=640:height=480:outfmt=rgb24:device=/dev/video0:noaudio -flip
  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
==== recording webcam (old Video4Linux 1) with mencoder...====
Oppure
* good quality
  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=640:height=480:outfmt=rgb24:device=/dev/video0:noaudio -flip \
-o camed.avi -ovc lavc
* or less
  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... ===
==== cacciare un frame con ffmpeg verso jpg - estrazione 1° frame in jpg====
==== extract a frame in JPEG ====
estrarre il 1° frame
* 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
==== create a video from image ====
ffmpeg -loop_input -vframes <number_of_frames> -i <input_image> <output_video>
ffmpeg -i INPUT.jpg -an -vcodec libx264 -coder 1 -flags +loop -cmp +chroma -subq 10 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -flags2 +dct8x8 -trellis 2 -partitions +parti8x8+parti4x4 -crf 24 -threads 0 -r 25 -g 25 -y OUTPUT.mp4


=== Network ===
=== Network ===
Line 65: Line 179:
  mplayer http://mplayer.hq/example.avi -dumpstream -dumpfile dumpato.avi
  mplayer http://mplayer.hq/example.avi -dumpstream -dumpfile dumpato.avi
==== Grabando ,cortando y comprimiendo un stream de tv3====
==== 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
  mplayer "mms://directe.3alacarta.tvcatalunya.com/reflector:60738?aifp=fhgt&WMCache=0" -dumpstream -dumpfile dumpato.avi


  mencoder  -ss 826.5  dumpato.avi -o dumpato_tagliato.avi -ovc copy -oac copy
  mencoder  -ss 826.5  dumpato.avi -o dumpato_tagliato.avi -ovc copy -oac copy
Line 73: Line 187:
  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 207:
  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 223:




==== 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
=== WebM ===
==== ...In qualità DV ====
* /usr/share/ffmpeg/libvpx-720p.ffpreset
  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
  vcodec=libvpx
  mencoder  -ss '''120''' -endpos '''15''' video.avi -o video_tagliato.avi -ovc lavc
  g=120
==== Tagliare solo i primi 30 min (1800 sec.)====
  rc_lookahead=16
mencoder -endpos 1800 rec-CUATRO-20070213-01:30.avi -o /mirror160/_video/__Temp/rec-CUATRO-20070213-01:30_tagliato.avi -ovc copy -oac copy
  level=216
che prestazioni!
  profile=0
  Pos:1494.0s 37349f ( 9%) 1469.33fps Trem:   4min 10447mb  A-V:0.040 [5154:128]
  qmax=42
  qmin=10
  vb=2M
* ignored unless using -pass 2
  maxrate=24M
  minrate=100k
 
 
  ffmpeg -i input.mp4 -s 1280x720 -vpre libvpx-720p -b 3900k -pass 1 -an -f webm -y output.webm
ffmpeg -i input.mp4 -s 1280x720 -vpre libvpx-720p -b 3900k -pass 2 -acodec libvorbis -ab 128k -f webm -y output.webm
 
 
  ffmpeg -pass 1 -passlogfile pr7.webm -qmin 5 -qmax 51 -i master/879.m2t -vcodec libvpx -b:v 104800 -s 320x200 -an -f webm -y NUL
ffmpeg -pass 2 -passlogfile pr7.webm -qmin 5 -qmax 51 -i master/879.m2t -vcodec libvpx -b:v 104800 -s 320x200 -acodec libvorbis -ac 1 -b:a 64k -y  video/pr7.webm
 
ffmpeg  -i master/743.MTS -s 360x240  -vpre libvpx-360p -pass 1 -passlogfile  log743_7.webm -qmin 5 -qmax 51  -b:v 500k -an -f webm -y video/743_7.webm
  ffmpeg  -i master/743.MTS -s 360x240  -vpre libvpx-360p -pass 1 -passlogfile log743_7.webm -qmin 5 -qmax 51  -b:v 500k -acodec libvorbis -ac 1 -b:a 96k -f webm -y video/743_7.webm


=== Theora ===
=== Theora ===
Line 140: Line 275:
   | 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 282:


==== 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 -


 
=== MPEG2 M2S MPEGII ===
=== MPEG 2 ===
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 318:
==== 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 347:
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 357:


  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
   
   
  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=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


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 391:
  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 -
 
----
 
===  Flash FLV ===
==== encode in flv (avi to flv) (mpg to flv) ffmpeg ====
ffmpeg -y -i dumpato2.avi -acodec mp3 -f flv dumpato2.flv


=== parametri FFmpeg ===
video_directory/ # for clip in ls ./*.* ; do ffmpeg -y -i "$clip" -acodec mp3 -f flv /scratch/`echo "$clip"|sed -e s@' '@'_'@g`; done
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:
=== mp3 ===
  -b bitrate          set video bitrate (in kbit/s)
  -vframes number    set the number of video frames to record
  -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:
==== all aiff in a directory to mp3 ====
  -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:
for file in *.aiff ; do ffmpeg -i "$file" -f mp3 -ab 320000 -ar 48000 "$file.mp3" ; done
  -aframes number    set the number of audio frames to record
rename .aiff.mp3 .mp3 *.aiff.mp3
  -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:
=== Problem -> Solution ===
  -atag fourcc/tag    force audio tag/fourcc


  Subtitle options:
==== Encoding ====
  -scodec codec      force subtitle codec ('copy' to copy stream)
* convertendo in x264 con RedHat 5.2 il video in uscita risulta corrotto
  -newsubtitle        add a new subtitle stream to the current output stream
** is the x264 library that updatig casuses the problem
  -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:
  -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 ====
== bit rate ==
* convertendo in x264 con RedHat 5.2 il video in uscita risulta corrotto
* values can be specified using '''''1'''M''''' or ''1024'''K''''' or '''''1 048 576'''''
** '''-b'''  ''1024'''K'''''
** '''-minrate''' 800K
** '''-maxrate''' 1400K
** '''-bufsize''' 120K
 
== Troubleshooting ==
=== cannot open shared object file: No such file or directory ===
 
ldd `which ffmpeg`
        libavdevice.so.52 => not found
        libavfilter.so.1 => not found
        libavformat.so.52 => not found
        libavcodec.so.52 => not found
        libswscale.so.0 => not found
        libavcore.so.0 => not found
        libavutil.so.50 => not found
        libm.so.6 => /lib/libm.so.6 (0x006c3000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x007e9000)
        libc.so.6 => /lib/libc.so.6 (0x00575000)
        /lib/ld-linux.so.2 (0x00557000)
 
find /usr/local/lib/ | grep -E "libavdevice.so.52|libavfilter.so.1|libavcodec.so.52|libavcore.so.0"
 
lddconfig
 
== FFmpeg Math expresisons ==
 
* very powerful "under the hood" part of this software:
 
* using expresisons in ''scale'' filter: [[MPLAYER_MENCODER#.22not_divisible_by_2.22]]
 
 
=== from ffmpeg documentation ===
 
* item E, PI, PHI
** the corresponding mathematical approximated values for e (euler number), pi (greek PI), phi (golden ratio)
 
* ''in_w, in_h'' the input width and heigth
 
* ''iw, ih same as @var{in_w} and @var{in_h}
 
* ''out_w, out_h'' the output (cropped) width and heigth
** ''ow, oh'' same as @var{out_w} and @var{out_h}
 
* ''a'' input display aspect ratio, same as @var{iw} / @var{ih}
 
* ''hsub, vsub'' horizontal and vertical chroma subsample values.
** For example for the pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1.
 
* If the input image format is different from the format requested by the next filter,
** the scale filter will convert the input to the ratio of the input image.
* default value of @var{width} and @var{height} is 0.
 
* '''Some examples follow:''
 
* scale the input to 2x
scale=2*iw:2*ih
same as
scale=2*in_w:2*in_h
 
* scale the input to half size
scale=iw/2:ih/2
 
* increase the width, and set the height to the same size
scale=3/2*iw:ow
 
* seek for Greek harmony
scale=iw:1/PHI*iw
scale=ih*PHI:ih
* increase the height, and set the width to 3/2 of the height
scale=3/2*oh:3/5*ih
 
* increase the size, but make the size a multiple of the chroma
scale="trunc(3/2*iw/hsub)*hsub:trunc(3/2*ih/vsub)*vsub"
 
* increase the width to a maximum of 500 pixels, keep the same input aspect ratio
scale='min(500\, iw*3/2):-1'
 
 
http://ffmpeg.mplayerhq.hu/ffmpeg.html
 
 
When evaluating an arithmetic expression, FFmpeg uses an internal formula evaluator, implemented through the `libavutil/eval.h' interface.
 
An expression may contain unary, binary operators, constants, and functions.
 
Two expressions expr1 and expr2 can be combined to form another expression "expr1;expr2".
 
expr1 and expr2 are evaluated in turn, and the new expression evaluates to the value of expr2.
 
The following binary operators are available: +, -, *, /, ^.
 
The following unary operators are available: +, -.
 
The following functions are available:
<pre>
 
`sinh(x)'
`cosh(x)'
`tanh(x)'
`sin(x)'
`cos(x)'
`tan(x)'
`atan(x)'
`asin(x)'
`acos(x)'
`exp(x)'
`log(x)'
`abs(x)'
`squish(x)'
`gauss(x)'
`isnan(x)'
    Return 1.0 if x is NAN, 0.0 otherwise.
`mod(x, y)'
`max(x, y)'
`min(x, y)'
`eq(x, y)'
`gte(x, y)'
`gt(x, y)'
`lte(x, y)'
`lt(x, y)'
</pre>
* `st(var, expr)'
**    Allow to store the value of the expression expr in an internal variable. var specifies the number of the variable where to store the value, and it is a value ranging from 0 to 9. The function returns the value stored in the internal variable.
* `ld(var)'
**    Allow to load the value of the internal variable with number var, which was previosly stored with st(var, expr). The function returns the loaded value.
*`while(cond, expr)'
**    Evaluate expression expr while the expression cond is non-zero, and returns the value of the last expr evaluation, or NAN if cond was always false.
*`ceil(expr)'
**    Round the value of expression expr upwards to the nearest integer. For example, "ceil(1.5)" is "2.0".
*`floor(expr)'
**    Round the value of expression expr downwards to the nearest integer. For example, "floor(-1.5)" is "-2.0".
*`trunc(expr)'
**    Round the value of expression expr towards zero to the nearest integer. For example, "trunc(-1.5)" is "-1.0".
*`sqrt(expr)'
**    Compute the square root of expr. This is equivalent to "(expr)^.5".
*`not(expr)'
**    Return 1.0 if expr is zero, 0.0 otherwise.
*`pow(x, y)'
**    Compute the power of x elevated y, it is equivalent to "(x)^(y)".
 
* works like AND
 
+ works like OR
 
<syntaxhighlight lang="php" >
if A then B else C
</syntaxhighlight>
is equivalent to
<syntaxhighlight lang="php" >
A*B + not(A)*C
</syntaxhighlight>

Latest revision as of 17:31, 2 June 2012

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

http://www.ffmpeg.org/libavfilter.html

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
ffmpeg -i  inputfile.mov  -acodec mp2 -ar 44100 -ac 2 -ab 112000 -vcodec mjpeg -qscale 2  output.mpg

Filters

  • to add filters to ffmpeg or mencoder, use the option -vf

Scale

  • with mencoder
mencoder video.mpg -oav copy -ovc copy -vf scale=120:100 -o scaled.mpg
  • with ffmpeg
ffmpeg -i <file> -vf scale=<x>:<y> <file-cropped>
  1. x and y are pixel values
  2. If value is 0, the input size is used
  3. If value is -1, maintains the aspect ratio
    this can brake the process having the proportional side size not divisible by 2 (x264 codecs)
  4. default is 0.
"not divisible by 2" (x264 issue)
  • trying to upscale a video from 854x480 [PAR 1:1 DAR 427:240] to -vf scale=-1:720 , got this message:

width or height not divisible by 2 (1281x720)

  • I'm running periodically a script encoding clips for a video server, using multiple formats for every clip and scaling them respectively to x:360 , x:480 , x:720 , the common " -vf scale:-1:360 " gives "not divisible by 2" error for some input/output sizes, the solution has been found with a formula:


 scale=ceil(a*480)+mod(ceil(a*480)\,2):480


  • in words: scale the height is proportionally to the new width plus the rest of the division by two of the proportional size. That means that, for example we take a 480 x 352 video and we scale it to 360, the new width (without my formula) would have been 491 (giving the codec an error) the formula divides it by 2 and ad adds the rest ( 1 ) to the output width.


  • these are the calculations I've made to reach the solution:
 a = 320 / 240 = 1,3333 
 scale=ceil(a*XXX):XXX

 1080 * 1,3333 = 1439,8   ceil = 1440
 720 * 1,3333  = 959,9999 ceil = 960
 480 * 1,3333  = 639,9    ceil = 640 
 360 * 1,3333  = 479,9    ceil = 480    


 a = 352 / 288 = 1,2222 
 scale=ceil(a*XXX):XXX

 1080 * 1,2222 = 1,319    ceil = 1320
 720 * 1,2222  = 879,9999 ceil = 880
 480 * 1,2222  = 586,6    ceil = 587   ERR
 360 * 1,2222  = 439,9    ceil = 440    

 a = 480 / 352 = 1,3636
 scale=ceil(a*XXX):XXX

 1080 * 1,3636 = 1472,6  ceil = 1473   ERR
 720 * 1,3636  = 981,7   ceil = 982
 480 * 1,3636  = 654,5   ceil = 655    ERR
 360 * 1,3636  = 490,8   ceil = 491    ERR

 a = 480 / 264 = 1,8181
 scale=ceil(a*XXX):XXX

 1080 * 1,8181 = 1963,5  ceil = 1964  
 720 * 1,8181  = 1309,03 ceil = 1310
 480 * 1,8181  = 872,6   ceil = 873    ERR
 360 * 1,8181  = 654,51  ceil = 655    ERR


 # final expression:
 scale=ceil(a*480)+mod(ceil(a*480)\,2):480

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 20 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

MPEG PES...

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

  • v4l2
mplayer -cache 128 -tv driver=v4l2:width=800:height=480:outfmt=i420:device=/dev/video0 -vo xv tv://
  • v4l
mplayer tv:// -tv driver=v4l:width=640:height=480:outfmt=rgb24:device=/dev/video0:noaudio -flip

recording webcam (old Video4Linux 1) with mencoder...

  • good quality
mencoder tv:// -tv driver=v4l:width=640:height=480:outfmt=rgb24:device=/dev/video0:noaudio -flip \
-o camed.avi -ovc lavc
  • or less
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...

extract a frame in JPEG

  • 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

create a video from image

ffmpeg -loop_input -vframes <number_of_frames> -i <input_image> <output_video>


ffmpeg -i INPUT.jpg -an -vcodec libx264 -coder 1 -flags +loop -cmp +chroma -subq 10 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -flags2 +dct8x8 -trellis 2 -partitions +parti8x8+parti4x4 -crf 24 -threads 0 -r 25 -g 25 -y OUTPUT.mp4

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?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



WebM

  • /usr/share/ffmpeg/libvpx-720p.ffpreset
 vcodec=libvpx
 g=120
 rc_lookahead=16
 level=216
 profile=0
 qmax=42
 qmin=10
 vb=2M
  • ignored unless using -pass 2
 maxrate=24M
 minrate=100k


ffmpeg -i input.mp4 -s 1280x720 -vpre libvpx-720p -b 3900k -pass 1 -an -f webm -y output.webm
ffmpeg -i input.mp4 -s 1280x720 -vpre libvpx-720p -b 3900k -pass 2 -acodec libvorbis -ab 128k -f webm -y output.webm


ffmpeg -pass 1 -passlogfile pr7.webm -qmin 5 -qmax 51 -i master/879.m2t -vcodec libvpx -b:v 104800 -s 320x200 -an -f webm -y NUL
ffmpeg -pass 2 -passlogfile pr7.webm -qmin 5 -qmax 51 -i master/879.m2t -vcodec libvpx -b:v 104800 -s 320x200 -acodec libvorbis -ac 1 -b:a 64k -y  video/pr7.webm
ffmpeg  -i master/743.MTS -s 360x240  -vpre libvpx-360p -pass 1 -passlogfile  log743_7.webm -qmin 5 -qmax 51  -b:v 500k -an -f webm -y video/743_7.webm
ffmpeg  -i master/743.MTS -s 360x240  -vpre libvpx-360p -pass 1 -passlogfile  log743_7.webm -qmin 5 -qmax 51  -b:v 500k -acodec libvorbis -ac 1 -b:a 96k -f webm -y video/743_7.webm

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

mp3

all aiff in a directory to mp3

for file in *.aiff ; do ffmpeg -i "$file" -f mp3 -ab 320000 -ar 48000 "$file.mp3" ; done
rename .aiff.mp3 .mp3 *.aiff.mp3

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



bit rate

  • values can be specified using 1M or 1024K or 1 048 576
    • -b 1024K
    • -minrate 800K
    • -maxrate 1400K
    • -bufsize 120K

Troubleshooting

cannot open shared object file: No such file or directory

ldd `which ffmpeg`
       libavdevice.so.52 => not found
       libavfilter.so.1 => not found
       libavformat.so.52 => not found
       libavcodec.so.52 => not found
       libswscale.so.0 => not found
       libavcore.so.0 => not found
       libavutil.so.50 => not found
       libm.so.6 => /lib/libm.so.6 (0x006c3000)
       libpthread.so.0 => /lib/libpthread.so.0 (0x007e9000)
       libc.so.6 => /lib/libc.so.6 (0x00575000)
       /lib/ld-linux.so.2 (0x00557000)
find /usr/local/lib/ | grep -E "libavdevice.so.52|libavfilter.so.1|libavcodec.so.52|libavcore.so.0"
lddconfig

FFmpeg Math expresisons

  • very powerful "under the hood" part of this software:


from ffmpeg documentation

  • item E, PI, PHI
    • the corresponding mathematical approximated values for e (euler number), pi (greek PI), phi (golden ratio)
  • in_w, in_h the input width and heigth
  • iw, ih same as @var{in_w} and @var{in_h}
  • out_w, out_h the output (cropped) width and heigth
    • ow, oh same as @var{out_w} and @var{out_h}
  • a input display aspect ratio, same as @var{iw} / @var{ih}
  • hsub, vsub horizontal and vertical chroma subsample values.
    • For example for the pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1.
  • If the input image format is different from the format requested by the next filter,
    • the scale filter will convert the input to the ratio of the input image.
  • default value of @var{width} and @var{height} is 0.
  • 'Some examples follow:
  • scale the input to 2x
scale=2*iw:2*ih

same as

scale=2*in_w:2*in_h
  • scale the input to half size
scale=iw/2:ih/2
  • increase the width, and set the height to the same size
scale=3/2*iw:ow
  • seek for Greek harmony
scale=iw:1/PHI*iw
scale=ih*PHI:ih

  • increase the height, and set the width to 3/2 of the height
scale=3/2*oh:3/5*ih
  • increase the size, but make the size a multiple of the chroma
scale="trunc(3/2*iw/hsub)*hsub:trunc(3/2*ih/vsub)*vsub"
  • increase the width to a maximum of 500 pixels, keep the same input aspect ratio
scale='min(500\, iw*3/2):-1'


http://ffmpeg.mplayerhq.hu/ffmpeg.html


When evaluating an arithmetic expression, FFmpeg uses an internal formula evaluator, implemented through the `libavutil/eval.h' interface.

An expression may contain unary, binary operators, constants, and functions.

Two expressions expr1 and expr2 can be combined to form another expression "expr1;expr2".

expr1 and expr2 are evaluated in turn, and the new expression evaluates to the value of expr2.

The following binary operators are available: +, -, *, /, ^.

The following unary operators are available: +, -.

The following functions are available:


`sinh(x)'
`cosh(x)'
`tanh(x)'
`sin(x)'
`cos(x)'
`tan(x)'
`atan(x)'
`asin(x)'
`acos(x)'
`exp(x)'
`log(x)'
`abs(x)'
`squish(x)'
`gauss(x)'
`isnan(x)'
    Return 1.0 if x is NAN, 0.0 otherwise. 
`mod(x, y)'
`max(x, y)'
`min(x, y)'
`eq(x, y)'
`gte(x, y)'
`gt(x, y)'
`lte(x, y)'
`lt(x, y)'
  • `st(var, expr)'
    • Allow to store the value of the expression expr in an internal variable. var specifies the number of the variable where to store the value, and it is a value ranging from 0 to 9. The function returns the value stored in the internal variable.
  • `ld(var)'
    • Allow to load the value of the internal variable with number var, which was previosly stored with st(var, expr). The function returns the loaded value.
  • `while(cond, expr)'
    • Evaluate expression expr while the expression cond is non-zero, and returns the value of the last expr evaluation, or NAN if cond was always false.
  • `ceil(expr)'
    • Round the value of expression expr upwards to the nearest integer. For example, "ceil(1.5)" is "2.0".
  • `floor(expr)'
    • Round the value of expression expr downwards to the nearest integer. For example, "floor(-1.5)" is "-2.0".
  • `trunc(expr)'
    • Round the value of expression expr towards zero to the nearest integer. For example, "trunc(-1.5)" is "-1.0".
  • `sqrt(expr)'
    • Compute the square root of expr. This is equivalent to "(expr)^.5".
  • `not(expr)'
    • Return 1.0 if expr is zero, 0.0 otherwise.
  • `pow(x, y)'
    • Compute the power of x elevated y, it is equivalent to "(x)^(y)".
* works like AND
+ works like OR
if A then B else C

is equivalent to

A*B + not(A)*C