What is ffmpeg ? And how to resize your video ?

About

ffmpeg 1) is a command line to record, convert and stream audio and video.

This is the simple tool to manipulate and convert any video.

How to install it ?

You can download it or install it via your package manager.

Example on linux ubuntu with apt

sudo apt install ffmpeg

Operation

How to get video/image information ?

To get information about your video, you would use the ffrpobe utility (installed with ffmped)

ffprobe video.mp4

Example of output where you can see the aspect ratio of 1920×1080

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : Video Gifts
    artist          : Gerard nico
    encoder         : Lavf58.29.100
    keywords        : Video-Gifts
  Duration: 00:00:39.27, start: 0.000000, bitrate: 3067 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 2933 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : Core Media Video
      timecode        : 00:00:00;00
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
    Stream #0:2(eng): Data: none (tmcd / 0x64636D74)
    Metadata:
      handler_name    : Core Media Video
      timecode        : 00:00:00;00

How to convert the format ?

from mp4 to avi

The command is pretty simple

ffmpeg -i input.mp4 output.avi

from mov to mp4

The command may also add more information such as the codec

ffmpeg -i {in-video}.mov -vcodec h264 -acodec aac {out-video}.mp4

How to scale / resize to a lower dimension

In this example, we show you how to preserve aspect ratio which is almost what you want.

Example:

  • video
ffmpeg -i output.mp4 -vf scale=960:-1 output_960.mp4
  • A image
ffmpeg -i input.jpg -vf scale=320:-1 output_320.png

How to extract the images of a video (ie frame) ?

  • To encode a movie to frame (single pictures) sampled (every n frames) 2)
ffmpeg -i movie.mpg movie%d.jpg
  • Extract the first 20 frames
ffmpeg -i input.mp4 -vframes 20 output_image_%03d.jpg
  • To extract the 30 frame
ffmpeg -i input.mp4 -vf "select=eq(n\,30)" -vframes 1 output_image.jpg

Powered by ComboStrap