Ffmpeg-examples

From wikipost
Jump to navigation Jump 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)

or

ffmpeg -framerate 10  -pattern_type glob -i '*.jpg' -s 1280x720 -c:v libx264 -crf 23 out.avi



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

       for example, to remove the first 10 seconds of a 1.5 hour movie:

            ffmpeg -i infile.mp4 -ss 0:10 -t 1:30:00 -c copy outfile.mp4


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

      example:

         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




Joining multiple videos:

   - create a text file containing a list of the videos you wish to join
     Syntax: file <filename>

     Example:
      
       file /path/to/file/video1.mp4
       file /path/to/file/video2.mp4
       file /path/to/file/video3.mp4

   - join (concatenate) command:

       ffmpeg -f concat -i myvideolist.txt -c copy allvideos.mp4


   if you need to join multiple videos with differing bitrates/fps then you will need to re-encode them all to the same format first.

       Something like:

            ffmpeg -i video1.mp4 -filter:v fps=30 -vcodec libx264 -c:a copy video1_reencoded.mp4


  





keyframes:

      -force_key_frames 1