Skip to main content

ffmpeg

    1. How to split video into 30 seconds chunks. This example creates 3 segments from the beginning of video starting at time 0 seconds of original video. i.e. <30s><30s><30s><... long big chunk>.

      Code:
      ffmpeg -ss 00:00:30 -vsync 0 -t 00:00:30 -i webcam_2012-03-18_00_33_58.mp4 -vcodec copy -acodec copy sub_video1.mp4
      
      ffmpeg -ss 00:01:00 -vsync 0 -t 00:00:30 -i webcam_2012-03-18_00_33_58.mp4 -vcodec copy -acodec copy sub_video2.mp4
      
      ffmpeg -ss 00:01:30 -vsync 0 -t 00:00:30 -i webcam_2012-03-18_00_33_58.mp4 -vcodec copy -acodec copy sub_video3.mp4
      


    1. How to extract a still JPEG image from a video at the 20 second spot.

      Code:
      ffmpeg -i webcam_2012-03-18_00_33_58.mp4 -r 0.1 -t 20 image%3d.jpg
      


    1. Here are some other examples to save you time:

      19-FFmpeg commands for all needs

    2. Good articles and examples here:

      FFMpeg – The swiss army knife of Internet streaming – part I

      FFMpeg – The swiss army knife of Internet streaming – part II

      FFMpeg – The swiss army knife of Internet streaming – part III

      FFMpeg – The swiss army knife of Internet streaming – part IV

    3. Screencasting: How to capture your desktop screen and audio.
      Nice examples here.

    4. How to overlay text on the video at a specific window position.

      Code:
      ffmpeg -i sub_video3.mp4 -vf \
             drawtext="fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf: \
      text='Text to write is this one, overlaid':fontsize=20:fontcolor=red:x=100:y=100" \ with_text3.mp4


    1. How to grab audio from your desktop/laptop microphone.

      Code:
      ffmpeg -f alsa -ac 2 -i pulse mic_test.mp3
      


    1. Two examples that overlays text over video which timestamps the output video to start at the specified time (timecode).
      Code:
      #Begin at 1:00
      
      ffmpeg -y -i in_video.mp4 \
             -vf "drawtext=fontcolor=white: fontsize=16: \
                           fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf: \
                           box=1:boxcolor=black@0.3:x=50:y=20: \
                           timecode='00\\:01\\:00\\;02':rate=30000/1001" \
              out.mp4
      
      #Begin at 3:59, with a specified codec
      
      ffmpeg -i in_video.mp4 \
             -vf "drawtext=fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf: \
                           x=10: y=20: fontsize=32: boxcolor=black@0.5:box=1: \
                           rate=30000/1001:timecode='00\\:03\\:59\\;27'" \
              -r 30000/1001 \
              -vcodec mpeg4 \
              nostra_timecode.mp4 


    1. A example that overlays text over video which shows updating timestamps on the output video.
      Code:
      ffmpeg -i video.mp4 -vf drawtext="fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf: \
      text='%T %D': x=10: y=10: fontsize=24: fontcolor=black" \
      -vcodec libx264 -preset fast -crf 34 -threads 0 \
      strftime.mp4


    1. A example that overlays text over an mjpeg input stream generated with mjpeg_streamer from a usb webcam.
      Code:
      ffmpeg -fflags +genpts -t 600 -f mjpeg -r 8 -s 640x480 \
             -i  http://localhost:8080/?action=stream -vcodec mpeg4 \
             -vf drawtext="fontfile=/usr/share/fonts/TTF/mitra.ttf:x=70:y=455: \
                          text='\%H\:\%M\:\%S | \%a \%d/\%b/\%Y | S500ATV | camera 0': \
                          fontcolor=0xFFFFFFFF:fontsize=18: \
                          shadowcolor=0x000000EE:shadowx=1:shadowy=1" \
             -b 1500000 -r 8 \
             video_file.avi
      


    1. If you want to add subtitles to a video file (in_video.avi) with audio to a new output video with subtitles. Note that since video had audio we are not passing the audio file we just map audio to the 2nd (0:1) component of the output. Input had 2 components, 0 and 1. Output has three (3) components, 0, 1, and 2. So, we are mapping the 1st input component to the 1st and 2nd output components (0:0) and (0:1). We also map the 2nd input component to the 3rd out put component (1:2).
      Code:
      ffmpeg -i in_video.avi     -c:v libx264 -vpre ipod640 -s 480x240 -b 256k -map 0:0 \
                                 -c:a libfaac -ar 48000 -ab 128k -ac 2 -map 0:1 \
             -i in_subtitles.srt -c:s copy -map 1:2
             out_video_with_titles.m4v
      
      #That is, follow this type of command format:
      
      ffmpeg -i Input_1.avi -c:v copy -map 0:0 \
             -i Input_2.wav -c:a copy -map 1:1 \
             -i Input_3.srt -c:s copy -map 2:2
             Output.mp4
      
      


  1. ffmpeg: the mother of all command-lines
    Nice complex command explained!