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:
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.
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.
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.
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.
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.
- 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! 🎥🔊📸