Skip to content

Instantly share code, notes, and snippets.

@neingeist
Last active November 11, 2023 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neingeist/33d38cbffee78dc65ce60bcaa3bf5e7b to your computer and use it in GitHub Desktop.
Save neingeist/33d38cbffee78dc65ce60bcaa3bf5e7b to your computer and use it in GitHub Desktop.
ffmpeg cheat sheet

Set audio language tag

E.g. for the first audio track (a:0). This example also resets the title of the audio track.

ffmpeg -i Godzilla.vs..Megalon.1973.1080p.mp4 \
    -c copy \
    \
    -metadata:s:a:0 language=jpn \
    -metadata:s:a:0 title="" \
    \
    OUTPUT.mp4
  • The :s here is for per-stream metadata
  • Language code is in ISO 639-2, so "the three letter language codes".
  • Best to get the language code using ffprobe, because ffmpeg would just ignore a wrong code

Remove title

ffmpeg -i Example_Video.mkv -metadata title= -c copy out.mkv

Remove subtitle tracks

To remove all subtitle tracks:

ffmpeg -i "in.mkv" -c copy -sn "out.mkv"

Remove tracks, selected by metadata

It's all Greek to me. Use something like this:

#!/bin/bash
# Remove the czech stuff...
#
# this reads from in/ and writes to out/. best to investigate using ffprobe, to
# get the metadata values exactly right.

set -e  # stop on error

mkdir -p out/

for in_ in "in/"*.mkv; do

  out="out/${in_#in/}"  # remove in/ prefix + add out/
  out_tmp="$(mktemp "out/tmp-XXXXX-${in_#in/}")"

  # for the ffmpeg options, see comments at the end.
  ffmpeg \
    -i "$in_" \
    \
    -map 0 \
    \
    -map -0:a:m:language:ces \
    -map -0:a:m:language:hun \
    \
    -map -0:s:m:language:ces \
    -map -0:s:m:language:hun \
    -map -0:s:m:language:ukr \
    \
    -c copy \
    \
    -metadata title="" \
    -metadata DESCRIPTION="" \
    \
    -metadata:s:a:m:language:deu title="" \
    -metadata:s:a:m:language:eng title="" \
    -metadata:s:a:m:language:fra title="French (original)" \
    \
    -metadata:s:s:m:title:'němčina'            title='' \
    -metadata:s:s:m:title:'angličtina'         title='' \
    -metadata:s:s:m:title:'angličtina [CC]'    title='English [CC]' \
    -metadata:s:s:m:title:'francouzština [CC]' title='French [CC]' \
    \
    -y \
    "$out_tmp"
  mv "$out_tmp" "$out"

done

# -map 0
# selects all streams (wouldn't pick up all streams otherwise)
#
# -map -0:a:m:language:ces
# deselects audio track ("a") in czech language. for subtitles, it's "s"
#
# -metadata ...
# sets/resets metadata for the whole file or specific streams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment