• Shaarli
  • Tag cloud
  • Picture wall
  • Daily
  • RSS
  • Login
4251 shaares
 
Filters
3 results tagged ffmpeg

Basic syntax for re-encoding a video file did take me some time to memorize, but... | Hacker News

QRCode

Basic syntax for re-encoding a video file did take me some time to memorize, but isn't in fact too hard:

ffmpeg <Input file(s)> <Codec(s)> <MAPping of streams> <Video Filters> output_file
  • input file: -i, can be repeated for multiple input files, like so:
  ffmpeg -i file1.mp4 -i file2.mkv

If there is more than one input file then some mapping is needed to decide what goes out in the output file.

  • codec: -c:x where x is the type of codec (v: video, a: audio or s:subtitles), followed by its name, like so:
    -c:v libx265

I usually never set the audio codec as the guesses made by ffmpeg, based on output file type, are always right (in my experience), but deciding the video codec is useful, and so is the subtitles codec, as not all containers (file formats) support all codecs; mkv is the most flexible for subtitles codecs.

  • mapping of streams: -map ::, like so:
    -map 0:v:0 -map 1:a:1 -map 1:a:0 -map 1:s:4

Map tells ffmpeg what stream from the input files to put in the output file. The first number is the position of the input file in the command, so if we're following the same example as above, '0' would be 'file1.mp4' and '1' would be 'file2.mkv'. The parameter in the middle is the stream type (v for video, a for audio, s for subtitles). The last number is the position of the stream IN THE INPUT FILE (NOT in the output file).

The position of the stream in the output file is determined by the position of the map command in the command line, so for example in the command above we are inverting the position of the audio streams (taken from 'file2.mkv'), as audio stream 1 will be in first position in the output file, and audio stream 0 (the first in the second input file) will be in second position in the output file.
This map thing is for me the most counter-intuitive because it's unusual for a CLI to be order-dependent. But, well, it is.

  • video filters: -vf
    Video filters can be extremely complex and I don't pretend to know how to use them by heart. But one simple video filter that I use often is 'scale', for resizing a video:
    -vf scale=:
    width and height can be exact values in pixels, or one of them can be '-1' and then ffmpeg computes it based on the current aspect ratio and the other provided value, like this for example:
    -vf scale=320:-1

This doesn't always work because the computed value should be an even integer; if it's not, ffmpeg will raise an error and tell you why; then you can replace the -1 with the nearest even integer (I wonder why it can't do that by itself, but apparently, it can't).
And that's about it! ffmpeg options are immense, but this gets me through 90% of my video encoding needs, without looking at a manual or ask an LLM. (The only other options I use often are -ss and -t for start time and duration, to time-crop a video.)

https://news.ycombinator.com/item?id=42708088
February 3, 2025 at 2:09:11 PM EST *
ffmpeg video
FILLER

FFmpeg By Example

QRCode

Explore the depth of FFmpeg with Examples

https://ffmpegbyexample.com/
January 23, 2025 at 9:19:35 AM EST *
ffmpeg video
FILLER

In praise of ffmpeg

QRCode

ffmpeg has been described as the Swiss army knife of multimedia. It incorporates hundreds of video, audio, and image decoders and encoders, muxers and demuxers, filters and devices. It provides a CLI and a set of libraries for working with its tools, and is the core component of many video and audio players as a result (including my preferred multimedia player, mpv). If you want to do almost anything with multimedia files — re-encode them, re-mux them, live stream it, whatever — ffmpeg can handle it with ease.

https://drewdevault.com/2022/10/12/In-praise-of-ffmpeg.html
October 24, 2022 at 11:07:38 AM EDT *
ffmpeg video
FILLER
Shaarli · The personal, minimalist, super fast, database-free, bookmarking service by the Shaarli community · Documentation
Fold Fold all Expand Expand all Are you sure you want to delete this link? Are you sure you want to delete this tag? The personal, minimalist, super fast, database-free, bookmarking service by the Shaarli community