MARCH 25, 2024

I export videos from Descript, which has embedded subtitles, and Descript doesn't have a way to export subtitles by chapter markers; it only exports them for an entire composition.

Here's a command that extracts the embedded subtitles from a given video—and supports any format supported by FFmpeg, such as MP4, MOV, or MKV.

ffmpeg -i video.mp4 -map 0:s:0

Here's what each part of the command does.

  • -i video.mp4 - the input file.
  • map 0:s:0: - maps the first subtitle track found in the video. (You can change the last digit to extract a different track, e.g., 0:s:1 for the second subtitle track.)
  • - the output file name and format, e.g, SRT or VTT.

If you found this useful, let me know!

SEPTEMBER 16, 2021

When trying to stitch several videos together with FFmpeg with the following command.

ffmpeg -f concat -i list.txt -c:v copy concat.mp4

I came across this error.

[concat @ 0x7fca4281b800] Unsafe file name '2021-09-16'
list.txt: Operation not permitted

The issue, which I've been able to fix manually other times, is that there's an unsafe character one or more input video names, the space.

As it turns out, we only need to turn off this safety measure for FFmpeg to skip this check, passing the -safe 0 flag in our command.

ffmpeg -f concat -safe 0 -i list.txt -c:v copy concat.mp4

Hope that helps!

MARCH 5, 2021

This script re-encodes the seconds between second 25 and 45 of an video from mov to mp4; rotates the frames 180 (the hflip,vflip flags flip all pixels vertically and horizontally); removes the audio (with the -an flag); and speeds up the video (i.e., skips frames, with the flag setpts=0.05*PTS, which you could adjust to have more frames, for instance, as setpts=0.1*PTS).

ffmpeg -ss 00:00:25 -to 00:00:45 \
       -i "" \
       -an -filter:v "hflip,vflip,setpts=0.05*PTS" \

APRIL 11, 2020

Many platforms—among which are Google PageSpeed or ImgIX—recommend serving animated assets over video formats as opposed to GIF animations. GIFs are heavy, and data transfer can be reduced somewhere between two and twenty times (when using the webm format) and, on top of that, videos can be streamed.

From GIF to MP4

ffmpeg -i animation.gif animation.mp4

From GIF to webm

ffmpeg -i animation.gif -c vp9 -b:v 0 -crf 12 my-animation.webm
  • crf · The range of the CRF scale is 0–51, where 0 is lossless, 23 is the default, and 51 is worst quality possible. A lower value generally leads to higher quality, and a subjectively sane range is 17–28. Consider 17 or 18 to be visually lossless or nearly so; it should look the same or nearly the same as the input but it isn't technically lossless. The range is exponential, so increasing the CRF value +6 results in roughly half the bitrate / file size, while -6 leads to roughly twice the bitrate. Choose the highest CRF value that still provides an acceptable quality. If the output looks good, then try a higher value. If it looks bad, choose a lower value.
  • b:v maximum bit rate allowed. Higher means better quality.

Want to see older publications? Visit the archive.

Listen to Getting Simple .