Media directory

This guide aims at getting a media directory of a large movie collection on a Debian linux server. We want to get the movie title, audio language, subtitle language, duration, and video resolution.

  1. Find the requested information from a file:
    ffmpeg -i <file>.mkv 2>&1 | grep Audio
    ffmpeg -i <file>.mkv 2>&1 | grep Subtitle
    ffmpeg -i <file>.mkv 2>&1 | grep Duration
    ffmpeg -i <file>.mkv 2>&1 | grep Video
  2. Create a batch file which extracts the required information:
    
    
  3. Create a batch file “mkvextract” which extracts all required information into format “movie name; audio languages; subtitle languages; video resolution; movie duration”
    echo $(basename "$1") | tr -d '\n'
    echo -n ";"
    ffmpeg -i "$1" 2>&1 | grep -P '(?<=\()(.*?)(?=\): Audio)' -o | tr '\n' ' ' | xargs | tr -d '\n'
    echo -n ";"
    ffmpeg -i "$1" 2>&1 | grep -P '(?<=\()(.*?)(?=\): Subtitle)' -o | tr '\n' ' ' | xargs | tr -d '\n'
    echo -n ";"
    ffmpeg -i "$1" 2>&1 | grep -e Video | grep -P '\b\d*x\d*\b' -o | tr '\n' ' ' | xargs | tr -d '\n'
    echo -n ";"
    ffmpeg -i "$1" 2>&1 | grep -P '(?<=Duration: )(.*?)(?=[\.,])' -o | tr '\n' ' ' | xargs | tr -d '\n'
    echo
    exit 0
  4. Run the find command on the directory to analyze:
    find . -name *.mkv -exec /path/to/batch/mkvextract {} \;