Common Uses of 'ffmpeg' Command in Linux

November 24, 2023 by
Common Uses of 'ffmpeg' Command in Linux
Hamed Mohammadi
| No comments yet

FFmpeg is a powerful command-line utility for handling audio, video, and other multimedia files in Linux. It’s widely used for tasks like video scaling, format transcoding, basic editing, standards compliance, and video post-production effects. Let’s explore some common use cases and commands:

  1. Get Video File Information: To retrieve information about a video file (e.g., video.mp4), use the following command:

    $ ffmpeg -i video.mp4 -hide_banner
    

    The -hide_banner option suppresses additional copyright information displayed by FFmpeg. This command provides details such as resolution, codec, duration, and more.

  2. Split a Video into Images: To convert a video into a sequence of images, use:

    $ ffmpeg -i video.mp4 image%d.jpg
    

    This generates image files named image1.jpg, image2.jpg, and so on.

  3. Convert Images into a Video: If you have a set of images (e.g., image1.jpg, image2.jpg, etc.), you can create a video from them:

    $ ffmpeg -i image%d.jpg -framerate 30 -c:v libx264 -pix_fmt yuv420p output.mp4
    

    Adjust the frame rate (-framerate) and codec (-c:v) as needed.

  4. Extract Audio from a Video: To save audio from a video file (e.g., video1.avi) as an MP3 file:

    $ ffmpeg -i video1.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 audio.mp3
    

    Explanation:

    • -vn: Disable video stream.
    • -ar 44100: Set audio sample rate to 44.1 kHz.
    • -ac 2: Use stereo audio.
    • -ab 192: Set audio bitrate to 192 kb/s.
  5. Decrease Video Sizes: FFmpeg can compress videos to reduce file size. For example:

    $ ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium output.mp4
    

    Adjust the CRF value (lower values mean better quality but larger files) and the preset according to your needs.

  6. ffmpeg: While ffmpeg is primarily for video and audio manipulation, it can also handle image conversions. Here's the command to convert a PNG file (image.png) to JPG (image.jpg) using ffmpeg:
    $ ffmpeg -i image.png image.jpg

    Batch Conversion: If you want to convert multiple PNG files in a directory, you can use a loop or the ls and xargs commands. Here's an example using a loop:

    for image in *.png; do  ffmpeg "$image" "${image%.png}.jpg" done

Remember to explore more options and experiment with FFmpeg to unleash its full potential! 🎥🔊📸

Common Uses of 'ffmpeg' Command in Linux
Hamed Mohammadi November 24, 2023
Share this post
Tags
Archive

Please visit our blog at:

https://zehabsd.com/blog

A platform for Flash Stories:

https://readflashy.com

A platform for Persian Literature Lovers:

https://sarayesokhan.com

Sign in to leave a comment