Skip to content

Instantly share code, notes, and snippets.

@zipizap
Last active August 25, 2015 21:01
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 zipizap/9c29ceb6718616e831a9 to your computer and use it in GitHub Desktop.
Save zipizap/9c29ceb6718616e831a9 to your computer and use it in GitHub Desktop.
Show container/audio-codec/video-codec of media files (using ffmpeg -i)
#!/bin/bash
[ $# -lt 1 ] && { echo "Usage: $0 <myvideofile>"; exit 1; }
TMP_FILE=$(mktemp)
echo -e "MEDIA_FILE"\\t"EXTENSION"\\t"CONTAINER"\\t"AUDIO_CODEC"\\t"VIDEO_CODEC"
for MEDIA_FILE in "$@"; do
[[ -f $MEDIA_FILE ]] || continue
ffmpeg -i $MEDIA_FILE &> $TMP_FILE
BASE_FILENAME=$(basename "$MEDIA_FILE")
# MOV_0295.mp4
EXTENSION="${BASE_FILENAME##*.}"
# mp4
CONTAINER=$(cat $TMP_FILE | egrep '^Input #0' | sed 's/^Input #., \(.*\), from .*$/\1/g')
# mov,mp4,m4a,3gp,3g2,mj2
AUDIO_CODEC=$(cat $TMP_FILE | grep Stream | grep Audio: | sed 's/^.* Audio: \([^,]\+\),.*$/\1/g')
# aac
VIDEO_CODEC=$(cat $TMP_FILE | grep Stream | grep Video: | sed 's/^.* Video: \([^,]\+\),.*$/\1/g')
# h264 (Constrained Baseline)
echo -e "$MEDIA_FILE"\\t"$EXTENSION"\\t"$CONTAINER"\\t"$AUDIO_CODEC"\\t"$VIDEO_CODEC"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment