From wikipost
Revision as of 20:37, 26 November 2020 by Admin (talk | contribs)
Jump to navigationJump to search

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

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>:<offset from left>:<offset from top>

      -vf crop=680:440:300:50


         Remove black horizontal bars at the top and bottom.

         The original video is 652x480 (width x height) but black bars only leave a useful video with an area of 652x326 pixels.
         Since the top and bottom bars are each 77 pixels in height, we offset the area by 77 pixels from the top.

         ffmpeg -y -i inputfile.mp4 -vf crop=652:326:0:77 outfile.mp4


      -force_key_frames 1