Some useful FFmpeg commands and scripts. | Rick's Tosefta

Rick's Tosefta

Some useful FFmpeg commands and scripts.

Snehith,

FFmpeg is a free and open-source framework for handling audio and video files. It supports a wide range of formats and codecs, and offers tools for encoding, decoding, and streaming multimedia files.

FFmpeg supports formats like AV1, VP8, and Opus, ensuring your content is freely usable and FFmpeg’s documentation makes it easy to integrate its functionality into your projects. FFmpeg is licensed under the LGPL license, promoting software freedom.

We start here, by ensuring our content to be free and open source coding format.

For Videos: I prefer Webm and Opus, as they are modern and efficient.

For Audio: I prefer only Opus, it has best bitrate and latency combinations compared with other audio formats.

Convert all videos in the directory to WebM,

Now some useful commands,

Convert input.mp4 to output.avi (basic format change).

Convert with variable frame rate (useful for audio/video sync).

Copy all video and audio streams from input to output.

Extract a segment from 1:30 to 2:00.

Extract the first 60 seconds.

ffplay input.mp4

Play input.mp4 (basic player).

Video Manipulation:

Resize to 640x480.

Crop a region (w=width, h=height, x=left, y=top).

Adjust brightness (example).

Set Sample Aspect Ratio (SAR) to 1.

Deinterlace a video (remove interlacing artifacts).

Audio Manipulation:

Copy audio stream to AAC (no video).

Encode audio to MP3 at 128kbps.

Encode audio to AAC at 128kbps.

Increase audio volume by 2dB.

Subtitle Handling:

Burn in subtitles (if present).

Copy subtitles from input to output.

Advanced & Optimization:

Encode video with x264 (good quality/size).

Encode video with x265 (better compression, slower).

Use 4 threads for faster encoding.

Stream copy (fastest, no re-encoding).

Extract audio only, no video.

Stream Manipulation:

Select specific video and audio streams.

No subtitles, no audio.

Force MP3 output.

Combining & Splitting:

Concatenate multiple files from a list.

Extract a segment and copy the stream.

Extract a segment from 0:00:00 to 0:00:10.

Note:

There is a ALOT more ffmpeg can do, and this list of commands is all I can remember and used sometime in the past. So this list is not exhaustive and I may add few more in the future.

Tags: Tech