Difference between revisions of "Ffmpeg-examples"

From wikipost
Jump to navigationJump to search
Line 24: Line 24:
 
Video bitrate:
 
Video bitrate:
 
    
 
    
   rule of thumb: divide your target size (in bits) by the video length (in seconds)
+
   Rule of thumb: divide your target size (in bits) by the video length (in seconds)
   example: for a 6 second video to be 10MBytes, use (10,000,000 / 6) = 1.6M
+
   Example 1: for a 6 second video to be 10MBytes, use (10,000,000 / 6) = 1.6M
  
    -vb 1000k
+
      -vb 1600k
 +
 
 +
  Example 2: for a 30 minute video to be 400MB, use (400,000,000 / 1,800) = 222,222 = 222k
 +
 +
      -vb 222k
  
 
   Note: lower CRF (Constant Rate Factor) equals higher quality (and larger files)
 
   Note: lower CRF (Constant Rate Factor) equals higher quality (and larger files)

Revision as of 18:13, 8 August 2020

Bunch of ffmpeg examples on one page


ffmpeg -y -i INFILE.mp4 -vcodec mpeg4 -vb 200k -acodec libvo_aacenc -ac 1 -ab 94000 -ar 16000 OUTFILE.mp4



ffmpeg -y -i INFILE.mp4 -c:v libx264 -crf 23  -vb 200k -c:a copy OUTFILE.mp4


truncate without re-encoding

ffmpeg -y -i INFILE.mpg -ss mm:ss -t mm:ss -c copy OUTFILE.mp4




convert jpg images to video:
ffmpeg -r 1/0.1 -f concat   -i filelist.txt -r 25 -c:v libx264 -pix_fmt yuv420p -y  OUTFILE.mp4
(where filelist.txt contains the list of image file names, e.g. img001.jpg, img002.jpg)


Video bitrate:
  
   Rule of thumb: divide your target size (in bits) by the video length (in seconds)
   Example 1: for a 6 second video to be 10MBytes, use (10,000,000 / 6) = 1.6M

       -vb 1600k

   Example 2: for a 30 minute video to be 400MB, use (400,000,000 / 1,800) = 222,222 = 222k
 
       -vb 222k

   Note: lower CRF (Constant Rate Factor) equals higher quality (and larger files)
   (max bitrate over wifi around 1Mbps)


Audio codecs and options:

 -acodec libvo_aacenc -ac 1 -ab 94000 -ar 16000 
 -acodec aac -ac 2 -ab 128k
 -acodec copy
 -an


Time selection:

    -ss = start-time offset (0 = begin, 5:00 = after 5 minutes)
    -t  = duration (1:00 = one minute, 1:45:00 = 1 hour and 45 minutes)

    -ss 2:23
    -ss 1:49 -t 1:58:02
    -t 2:15:06


Screen resolution:

     -s 1280x720


Resize and Crop options:

   Resize: -vf scale=iw*2:ih

      -vf "setsar=1/0.75" // Set the pixel sample aspect ratio.
      -vf "setdar=64:27"  // Set the frame display aspect ratio.


   Scale by percentage:

      -vf scale=iw/2:-1


   Crop: -vf crop=<width>:<height>:<from t/b>:<from l/r>

      -vf crop=680:440:300:50


keyframes:

      -force_key_frames 1