Ajouter les metadonnées dans le nom du fichier vidéo

C'est bien pratique d'avoir les attributs des vidéo dans le nom du fichier comme l'encodeur, la taille d'image etc. Cela vous permet d'estimer le vidéo sans l'avoir téléchargé.

Sous Linux (Ubuntu) il est possible développer un script :
- installez MPlayer si il n'est pas encore dans votre système
- créer le ficher *.sh (le texte est ci-dessous) et changer le nom du répertoire dont les vidéos sont stockés
- lancez le script
- ce script vous génère un autre script qui contient les commandes pour renommer vos fichiers en rajoutant les informations sous le format [Video "encodeur" "taille d'image" "fréquence" "bitrate"]

#!/bin/sh
#
# Shell script to add or replace metadata in video file name
# GPL (c) 2011, Serguei TARASSOV, st@arbinada.com
#
# Set "files_root_dir" variable to root directory where video files are stored
# This script will proceed it recursively
# and will create another script "video_files_rename.sh" in current directory
# that contains all commands to rename your video files
# Check it and run like $bash video_files_rename.sh
# You should also install "mplayer" package if it is not installed yet
#
 
files_root_dir="/home/user name/some videos"
 
function process_recursive() {
   for f in *
   do
      if [ -d "$f" ]; then
         cd "$f"
         echo "Processing subdirectory $f"
         process_recursive
         cd ..
         continue
      fi
 
      echo
      echo "Processing $f"
      file_ext=${f##*.}
      file_name=${f%.*}
      # Remove old information
      new_file_name=$(echo $file_name | sed -e 's/\(.*\)\.\[Video.*\]$/\1/')
      mplayer -vo null -ao null -frames 0 -identify "$f" 2>/dev/null 1>"$info_file"
      video_format=$(cat "$info_file" | grep 'ID_VIDEO_FORMAT=' | sed -e 's/ID_VIDEO_FORMAT=//g' -e 's/0x10000001/MPEG1/' -e 's/0x10000002/MPEG2/')
      if test "$video_format" != ""; then
         video_width=$(cat "$info_file" | grep 'ID_VIDEO_WIDTH=' | sed -e 's/ID_VIDEO_WIDTH=//g')
         video_height=$(cat "$info_file" | grep 'ID_VIDEO_HEIGHT=' | sed -e 's/ID_VIDEO_HEIGHT=//g')
         video_fps=$(cat "$info_file" | grep 'ID_VIDEO_FPS=' | sed -e 's/ID_VIDEO_FPS=//g' | sed -e 's/\.000$//g')
         video_bitrate=$(cat "$info_file" | grep 'ID_VIDEO_BITRATE=' | sed -e 's/ID_VIDEO_BITRATE=//g')
         len=${#video_bitrate}; len=$[$len-3]
         if [ $len -gt 0 ]; then
            video_bitrate=" "${video_bitrate:0:$len}"kbps"
         else
            video_bitrate=""
         fi
         video_properties="[Video "$video_format" "$video_width"x"$video_height" "$video_fps"fps"$video_bitrate"]"
         file_dir=$(pwd)
         if test "$file_name" = "$new_file_name.$video_properties"; then
            echo "No changes required"
         else
            files_processed=$[$files_processed+1]
            old_file="$file_dir"/"$f"
            new_file="$file_dir"/"$new_file_name"."$video_properties"."$file_ext"
            echo "mv -T" \""$old_file"\" \""$new_file"\" >> "$batch_name"
         fi
      else
         echo "Warning: cannot proccess. Probably \"$f\" is not a video file"
      fi
   done
}
 
files_processed=0
curr_dir=$(pwd)
batch_name=$curr_dir"/video_files_rename.sh"
info_file=$curr_dir"/video_metadata.txt"
echo "#!/bin/sh" > $batch_name
echo "echo \"Renaming files...\"" >> $batch_name
cd "$files_root_dir"
process_recursive
rm "$info_file"
echo
if [ $files_processed -gt 0 ]; then
   echo $files_processed "file(s) to process. Check and run" $batch_name
else
   echo "All files are OK. There are no files to rename"
fi
exit 0