I'm trying to create a script, which should read a video folder and create a list of video files to be processed by ffprobe to identify the codec. Videos NOT processed with a specific codec (in this case HEVC) should be put in new list for further processing by ffmpeg.
I created a very rudimentary script, but hit a brick wall at a point where the variable ffprobe_input needs to be changed in order to be passed as the next input for ffprobe.
Also, even if this part of the script was working, I'm puzzled as to how to create the filtered list of files after the ffprobe processing, since the only output is a single word, ex: hevc or x264.
The actual script is below, alongside with my notes, which should be more descriptive, also in the notes are some of the ways I tried to make things work.
This is the intended use of the script: ./script.sh -p /path\ to\ videos
#!/bin/bash
#Read path (-p) input and exit on error.
while getopts p: flag
do
case "${flag}" in
p) vpath=${OPTARG};;
*) echo "usage: $0 [-p]" >&2
exit 1 ;;
esac
done
#Now we echo the path for neatness
echo -e "Selected root video path: $vpath";
#Check if the path is valid. The path must be escaped. Cd into the folder and execute: printf "%q\n" "$(pwd)"
[ -d "$vpath" ] && echo "Directory $vpath exists." || echo "Error: Directory $vpath does not exist. Tip: make sure the spaces are escaped in folder names, ex: ===video\ folder===."
#Prepare a list of video files with full escaped paths,ready for ffprobe/ffmpeg input.
find "$vpath" -type f ( -iname ".mkv" -o -iname ".mp4" -o -iname "*.avi" ) | sed 's/ /\ /g' >> full_list.txt
#read the total number of lines from full_list.txt
nrl_total="$(wc -l full_list.txt | grep -Eo "[0-9]{0,7}")"
echo -e "There are a total of $nrl_total videos for further processing."
#read line number and pass to $ffprobe_input
nrl=($(seq 1 "$nrl_total"))
nrl={1..$nrl_total..1}
for $nlr in {1..$nrl_total..1}; do
nrl=({1..$nrl_total..1})
filename='full_list.txt'
nrl=1
while read line; do
echo "$nrl"
nrl=$((n+1))
#done < $filename
#ffprobe_input="$(sed -n 1p full_list.txt)" Use line number in "p" attribute, ex: 1p.
ffprobe_input="$(sed -n 1p full_list.txt)"
ffprobe_input="$(sed -n "$nrl"p full_list.txt)"
#Now pass the input to ffprobe to determine if the videos are HEVC or not. Output is single word, ex: hevc or x264.
eval ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 -i "$ffprobe_input"
done < $filename
rm full_list.txt
full_list.txt, and runffprobeonce for each line and store the results with the filenames? – ilkkachu Nov 25 '21 at 12:32full_list.txtand based onffprobeoutput to create anon_hevc.txtlist to be passed in the same fashion toffmpeg. – neckfreak Nov 25 '21 at 12:35