3 ms·
Personally I use a shell script to do it automatically for me... with "file": #!/bin/bash # Usage: fix-extensions <media file(s)> # Renames the fil
by amiga386 2y ago
Personally I use a shell script to do it automatically for me... with "file":
#!/bin/bash
# Usage: fix-extensions <media file(s)>
# Renames the files to consistent file extensions based on content
for file in "$@"; do
[ -f "$file" ] || continue
dir=$(dirname "$file")
name=$(basename "$file")
prefix="${name%.*}"
ext="${name##*.}"
magic=$(file -b "$file")
newext=""
case "$magic" in
*"Apple QuickTime movie"*) newext=mov;;
"ISO Media, Apple iTunes Video"*) newext=mp4;;
"ISO Media, MP4"*) newext=mp4;;
"ISO Media, MPEG-4 (.MP4)"*) newext=mp4;;
"Macromedia Flash data"*) newext=swf;;
"Macromedia Flash Video") newext=flv;;
"Matroska data") newext=mkv;;
"Microsoft ASF"*) newext=wmv;;
"MPEG sequence"*) newext=mpeg;;
"Ogg data, OGM video"*) newext=ogm;;
"RealMedia file") newext=rm;;
"RIFF "*" data, AVI,"*) newext=avi;;
"WebM") newext=webm;;
esac
if [ -z "$newext" ]; then
echo >&2 "$file: not renaming, unknown extension for type '$magic'"
elif [ "$ext" != "$newext" ]; then
mv -v "$file" "$dir/$prefix.$newext"
fi
done