First commit.

This commit is contained in:
2023-03-15 11:18:37 +01:00
commit 5992d41d52
18 changed files with 2036 additions and 0 deletions

View File

@ -0,0 +1,24 @@
# video-tools
## Use case
I bought a machine named Vero 4K+, running OSMC, to read my video library on my TV. It works fine on a number of files, but was struggling on some others, when no hardware decoder was available. I [found this thread](https://discourse.osmc.tv/t/ff-h264-dropping-and-skipping-frames/37459) that gave a first hint. I then decided to made a quick list of all the format of my files, to be able to test them. That's how this little project started.
## Set up
* On a Linux machine with apt: `sudo apt install -y ffmpeg mediainfo`
* If you are on Windows, you can:
* [install WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
* install Debian/Ubuntu/etc and type in: `sudo apt install -y ffmpeg mediainfo`
* If you access a networked drive, you can access it like this for example:
* `sudo mkdir /mnt/multimedia`
* `sudo mount -t drvfs //Vero/Multimedia /mnt/multimedia/` (this need to be done at each reboot)
## video-info.sh
video-info.sh generates a CSV file with the format, the format profile, and the codec ID. It can be opened with any spreadsheet software. If it is interrupted, an option to resume the operation is available, so that it is possible to launch it multiple time on huge video libraries.
It generates a file named `videoinfo-date_hour.csv` in the folder where the videos are located.
By default, only the following file extensions are taken into account: `mkv`, `mp4`, and `avi`. You can easily add more by modifying the script. You can know which file extensions you have in your library by typing the following command (more [on this thread](https://stackoverflow.com/questions/1842254/how-can-i-find-all-of-the-distinct-file-extensions-in-a-folder-hierarchy)):
`find . -type f | sed -e 's/.*\.//' | sed -e 's/.*\///' | sort | uniq -c | sort -rn`

View File

@ -0,0 +1,90 @@
#/bin/sh
CURRENT_DATE=$(date +%Y%m%d_%H%M)
bold=$(tput bold)
normal=$(tput sgr0)
# $1 = video file / $2 = result file
get_mediainfo() {
echo "Processing $1..."
echo -ne "\"$1\", " >> $2
mediainfo --Inform="Video;%Format%, %Format_Profile%, %CodecID%" "$1" >> $2
}
gather_data() {
echo "Gathering data..."
RESULT_PATH=./$1/videoinfo-"$CURRENT_DATE".csv
PWD=$(pwd $1)/$1
echo $PWD >> $RESULT_PATH
echo 'File, Format, Format Profile, Codec ID' >> $RESULT_PATH
find $1 -type f \( -iname \*.mkv -o -iname \*.mp4 -o -iname \*.avi \) | while read file;
do
get_mediainfo "$(pwd $1)/$file" $RESULT_PATH
done
echo "Finished! Result file is located at ${bold}$RESULT_PATH${normal}."
}
gather_data_continue() {
echo "Continue gather data of file ${bold}$1${normal}..."
LAST_LINE=$(tail -n 1 $1)
LAST_FILE=$(echo $LAST_LINE | sed 's/^\"\(.*\)\".*$/\1/g')
# where to find the files...
FIRST_LINE=$(head -n 1 $1)
# remove last line of file (might print error on WSL, hence the error suppression)
sed -i '$d' $1 2>/dev/null
FOUND_FILE=0
find $FIRST_LINE -type f \( -iname \*.mkv -o -iname \*.mp4 -o -iname \*.avi \) | while read file;
do
if [[ $file == $LAST_FILE ]]; then
FOUND_FILE=1
fi
if [[ $FOUND_FILE == 1 ]]; then
get_mediainfo "$file" $1
fi
done
echo "Finished! Result file is located at ${bold}$1${normal}."
}
continue_gather() {
if [[ $1 == "" ]]; then
echo "No input file. Please input CSV file generated by this program."
elif [[ -f $1 ]]; then
gather_data_continue $1
else
echo "File ${bold}$1${normal} does not exist."
fi
}
show_usage() {
echo -e "This tool generates a CSV file with useful video data\n"
echo -e "Options:"
echo -e "./video-info.sh [-h, --help]"
echo -e "\t\tDisplays help and usage.\n"
echo -e "./video-info.sh DIRECTORY"
echo -e "\t\tCreates a CSV file from all the video files from the directory.\n"
echo -e "./video-info.sh [-c, --continue] FILE"
echo -e "\t\tIf the gathering was interrupted, use this option to resume."
echo -e "\t\tTakes the incompletely generated CSV file as a parameter.\n"
echo -e "There are some limitations as this is a pretty simple tool. If you have any issue,"
echo -e "please read the README file."
}
if [[ $1 == "" ]] || [[ $1 == "--help" ]] || [[ $1 == "-h" ]]; then
show_usage
exit
elif [[ $1 == "-c" ]] || [[ $1 == "--continue" ]]; then
continue_gather $2
else
if [[ -d $1 ]]; then
gather_data $1
else
echo -e "Directory ${bold}$1${normal} does not exist. Showing usage...\n"
show_usage
fi
fi