2023-08-27, 10:50 PM
(2023-08-27, 05:17 AM)TheDreadPirate Wrote: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 -vf yadif=1 -c:a copy -c:s copy -ss $startTime -to $endTime "$file-chapter-$begin-$end.mkv"
done
done
All I did here was add de-interlacing with yadif; the recommended mode is 1, which is "send field" and will double the framerate for content. This can be problematic for films, so you can run mode 0 (which is one frame only and should preserve framerate). You can also try the auto leveling filter if you're interested, but I've never played with it before and my understanding is that what it does is just stretch luminance levels in the input media. Some folks also recommend decomb when ripping DVDs (which is how Handbrake generally recommends doing deinterlacing).
Jellyfin 10.10.0 LSIO Docker | Ubuntu 24.04 LTS | i7-13700K | Arc A380 6 GB | 64 GB RAM | 79 TB Storage