Calling Handbrake from within a Bash script, I am unable to process more than one file from a given folder. Using a While loop, Handbrake simply exits after processing the first file.
To be clear, the encoding process works as expected for the first file. The script simply terminates after that point. The only errors that appear in the Handbrake output are the typical errors associated with scanning for and not finding Bluray or DVD content.
My preference was to leverage HandBrake's Queue functionality but it seems said functionality is either missing from HandBrakeCLI or is present in a separate binary of which I am unaware.
HandBrake version (e.g., 1.0.0):
HandBrake 1.2.1
HandBrake Log Snippet
Code: Select all
username@video-proc:~$ ./convertHand.sh
Converting /home/username/Converted/Family Guy-Quagmires Dad.mpg to .MP4...
Cannot load libnvidia-encode.so.1
Cannot load libnvidia-encode.so.1
Cannot load libnvidia-encode.so.1
Cannot load libnvidia-encode.so.1
[05:22:13] hb_init: starting libhb thread
[05:22:13] thread 7f40736b1700 started ("libhb")
HandBrake 1.2.1 (2019021900) - Linux x86_64 - https://handbrake.fr
4 CPUs detected
Opening /home/username/Converted...
[05:22:13] CPU: Intel(R) Core(TM) i3-6100U CPU @ 2.30GHz
[05:22:13] - Intel microarchitecture Skylake
[05:22:13] - logical processor count: 4
........
x264 [info]: frame I:263 Avg QP:14.70 size: 72240
x264 [info]: frame P:11377 Avg QP:17.63 size: 12984
x264 [info]: frame B:32201 Avg QP:23.46 size: 1758
x264 [info]: consecutive B-frames: 1.2% 1.7% 2.3% 94.8%
x264 [info]: mb I I16..4: 5.8% 57.1% 37.2%
x264 [info]: mb P I16..4: 0.7% 3.2% 1.3% P16..4: 39.7% 16.9% 13.8% 0.0% 0.0% skip:24.3%
x264 [info]: mb B I16..4: 0.0% 0.2% 0.1% B16..8: 26.2% 4.3% 1.4% direct: 1.7% skip:66.0% L0:37.9% L1:53.0% BI: 9.1%
x264 [info]: 8x8 transform intra:59.4% inter:43.5%
x264 [info]: direct mvs spatial:100.0% temporal:0.0%
x264 [info]: coded y,uvDC,uvAC intra: 77.4% 87.0% 76.0% inter: 10.7% 15.6% 6.4%
x264 [info]: i16 v,h,dc,p: 53% 24% 8% 15%
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 12% 13% 7% 10% 11% 9% 10% 11%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 17% 12% 8% 8% 12% 12% 10% 10% 11%
x264 [info]: i8c dc,h,v,p: 41% 23% 23% 13%
x264 [info]: Weighted P-Frames: Y:1.6% UV:1.5%
x264 [info]: ref P L0: 63.8% 8.8% 16.6% 5.5% 5.3% 0.1% 0.0%
x264 [info]: ref B L0: 84.2% 11.2% 3.6% 1.0%
x264 [info]: ref B L1: 93.2% 6.8%
x264 [info]: kb/s:1220.65
[06:01:35] mux: track 0, 43841 frames, 223303107 bytes, 1220.63 kbps, fifo 4096
[06:01:35] mux: track 1, 68582 frames, 29261452 bytes, 159.95 kbps, fifo 4096
[06:01:35] mux: track 2, 45721 frames, 46817714 bytes, 255.92 kbps, fifo 4096
[06:01:35] libhb: work result = 0
Encode done!
HandBrake has exited.
Ubuntu 18.04 LTS
Code Snippets
This while loop leverages a txt file containing a list of file paths and names for all files to be processed.
Contents of text file
Code: Select all
/home/username/Converted/Family Guy-Quagmires Dad.mpg
/home/username/Converted/Daniel Tigers Neighborhood-The Class Votes; The Neighborhood Votes.mpg
/home/username/Converted/Sesame Street-How to Build a Dinosaur.mpg
/home/username/Converted/Daniel Tigers Neighborhood-Daniels Allergy; Allergies at School.mpg
/home/username/Converted/Last Man Standing-The Wolf Returns.mpg
While Loop
Code: Select all
homeDir="/home/username"
finalDir="/home/username/Complete"
comcutOutputFolder="/home/username/Converted"
touch handBrakeFiles.txt
find "$comcutOutputFolder" -ctime -1 -print | grep .mpg > handBrakeFiles.txt
while read line; do
echo "Converting $line to .MP4..."
handName=$(basename "$line" .mpg)
HandBrakeCLI --preset "HQ 480p30 Surround" -i "$line" -o "$finalDir"/"$handName".mp4
done < handBrakeFiles.txt