2023-08-27, 05:17 AM
Here is my progress. I added functionality to split files if there is a known chapter count per episode. USUALLY the same. Also accepts "all" for movies and such or if the MKVs came off the disc as 1 episode per file.
No deinterlacing or cropping. I am leaning towards letting clients do the deinterlacing for my content going forward. Still need to get cropping working.
No deinterlacing or cropping. I am leaning towards letting clients do the deinterlacing for my content going forward. Still need to get cropping working.
Code:
#!/bin/bash
chaptersEpisode=$1
if [ -z "$chaptersEpisode" ]; then
echo "Chapters per episode was not provided"
exit 1
fi
ls *.mkv | while read file; do
sudo /usr/lib/jellyfin-ffmpeg/ffprobe -i $file -print_format json -show_chapters -loglevel error > chapters.json
rawChapters=$(jq .chapters[].start_time chapters.json | wc -l)
totalChapters=$(echo $(($rawChapters - 1)) | bc)
i=0
startStop=""
if [ "$chaptersEpisode" == "all" ]; then
startStop="0:$totalChapters"
else
while [ $i -lt $totalChapters ]; do
first=$i
last=$(echo $(($i + $chaptersEpisode - 1)) | bc)
startStop=$(echo "$startStop $first:$last")
i=$(echo $(($i + $chaptersEpisode)) | bc)
done
fi
for chapter in `echo $startStop` ; do
begin=$(echo $chapter | awk -F ':' '{print $1}')
end=$(echo $chapter | awk -F ':' '{print $2}')
startTime=$(jq .chapters[$begin].start_time chapters.json | sed 's/\"//g')
endTime=$(jq .chapters[$end].start_time chapters.json | sed 's/\"//g')
sudo /usr/lib/jellyfin-ffmpeg/ffmpeg -init_hw_device vaapi=va:,driver=iHD,kernel_driver=i915 \
-init_hw_device qsv=qs@va -filter_hw_device qs -hwaccel qsv -hwaccel_output_format qsv \
-i $file -map 0:v -map 0:a -map 0:s -map_chapters 0 -c:v hevc_qsv -profile main \
-preset slow -cq 26 -pix_fmt yuv420p -c:a copy -c:s copy -ss $startTime -to $endTime "$file-chapter-$begin-$end.mkv"
done
done