Skip to content

Commit 3b0995c

Browse files
authored
Merge pull request #4 from yajrendrag/pr-comskip
[comskip] 0.0.10
2 parents b9fbbf3 + 5d485d4 commit 3b0995c

7 files changed

Lines changed: 136 additions & 31 deletions

File tree

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11

2+
**<span style="color:#56adda">0.0.10</span>**
3+
- changed init.d to install the plugin by building from github - installs the latest version with ffmpeg compatibility fixes
4+
- expands use_hw option to be used for either nvidia or intel QSV GPUs
5+
- auto detects GPU
6+
- falls back to CPU based decode if use_hw is selected and plugin determines no GPU or no useable GPU was found
7+
28
**<span style="color:#56adda">0.0.9</span>**
39
- add mimetype override and comskip command line arg to support ts files
410
- add parse_progress to display estimated time of completion

comchap/comchap

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ deletetxt=true
3131
verbose=false
3232
lockfile=""
3333
workdir=""
34-
usehw=false
34+
usecuvid=false
35+
useqsv=false
3536

3637
while [[ $# -gt 0 ]]
3738
do
@@ -49,8 +50,12 @@ case $key in
4950
verbose=true
5051
shift
5152
;;
52-
--use-hw)
53-
usehw=true
53+
--cuvid)
54+
usecuvid=true
55+
shift
56+
;;
57+
--qsv)
58+
useqsv=true
5459
shift
5560
;;
5661
--ffmpeg=*)
@@ -78,15 +83,15 @@ case $key in
7883
exit 1
7984
;;
8085
*)
81-
if [ -z $infile ]; then
82-
infile=$1
86+
if [ -z "$infile" ]; then
87+
infile="$1"
8388
if [ ! -f "$infile" ]; then
8489
echo "Inputfile '$infile' doesn't exist. Please check."
8590
exit 1
8691
fi
8792
else
88-
if [ -z $outfile ]; then
89-
outfile=$1
93+
if [ -z "$outfile" ]; then
94+
outfile="$1"
9095
else
9196
echo "Error: too many parameters. Inputfile and Outputfile already defined. Please check your command."
9297
exit 1
@@ -156,18 +161,24 @@ fi
156161

157162
infile_ext="${infile##*.}"
158163
if [ ! -f "$edlfile" ]; then
159-
if [ "$usehw" == false ]; then
164+
if [ "$useqsv" == false ] && [ "$usecuvid" == false ]; then
160165
if [ "$infile_ext" != 'ts' ]; then
161166
$comskipPath --ini="$comskipini" "$infile"
162167
else
163168
$comskipPath -t --ini="$comskipini" "$infile"
164169
fi
165-
else
170+
elif [ "$usecuvid" == true ]; then
166171
if [ "$infile_ext" != 'ts' ]; then
167172
$comskipPath --cuvid --ini="$comskipini" "$infile"
168173
else
169174
$comskipPath -t --cuvid --ini="$comskipini" "$infile"
170175
fi
176+
else
177+
if [ "$infile_ext" != 'ts' ]; then
178+
$comskipPath --qsv --ini="$comskipini" "$infile"
179+
else
180+
$comskipPath -t --qsv --ini="$comskipini" "$infile"
181+
fi
171182
fi
172183

173184
if [ ! -f "$edlfile" ] ; then

comchap/comcut

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ deletelogo=true
3030
deletetxt=true
3131
lockfile=""
3232
workdir=""
33-
usehw=false
33+
usecuvid=false
34+
useqsv=false
3435

3536
while [[ $# -gt 0 ]]
3637
do
@@ -44,8 +45,12 @@ case $key in
4445
deletemeta=false
4546
shift
4647
;;
47-
--use-hw)
48-
usehw=true
48+
--cuvid)
49+
usecuvid=true
50+
shift
51+
;;
52+
--qsv)
53+
useqsv=true
4954
shift
5055
;;
5156
--ffmpeg=*)
@@ -74,14 +79,14 @@ case $key in
7479
;;
7580
*)
7681
if [ -z "$infile" ]; then
77-
infile=$1
82+
infile="$1"
7883
if [ ! -f "$infile" ]; then
7984
echo "Inputfile '$infile' doesn't exist. Please check."
8085
exit 1
8186
fi
8287
else
8388
if [ -z "$outfile" ]; then
84-
outfile=$1
89+
outfile="$1"
8590
else
8691
echo "Error: too many parameters. Inputfile and Outputfile already defined. Please check your command."
8792
exit 1
@@ -144,17 +149,23 @@ fi
144149

145150
infile_ext="${infile##*.}"
146151
if [ ! -f "$edlfile" ]; then
147-
if [ "$usehw" == false ]; then
152+
if [ "$useqsv" == false ] && [ "$usecuvid" == false ]; then
153+
if [ "$infile_ext" != 'ts' ]; then
154+
$comskipPath --ini="$comskipini" "$infile"
155+
else
156+
$comskipPath -t --ini="$comskipini" "$infile"
157+
fi
158+
elif [ "$usecuvid" == true ]; then
148159
if [ "$infile_ext" != 'ts' ]; then
149-
$comskipPath $comskipoutput --ini="$comskipini" "$infile"
160+
$comskipPath --cuvid --ini="$comskipini" "$infile"
150161
else
151-
$comskipPath -t $comskipoutput --ini="$comskipini" "$infile"
162+
$comskipPath -t --cuvid --ini="$comskipini" "$infile"
152163
fi
153164
else
154165
if [ "$infile_ext" != 'ts' ]; then
155-
$comskipPath $comskipoutput --cuvid --ini="$comskipini" "$infile"
166+
$comskipPath --qsv --ini="$comskipini" "$infile"
156167
else
157-
$comskipPath $comskipoutput -t --cuvid --ini="$comskipini" "$infile"
168+
$comskipPath -t --qsv --ini="$comskipini" "$infile"
158169
fi
159170
fi
160171
fi

description.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@ Chapters are still added to the resulting file.
7474
</div>
7575

7676
#### <span style="color:blue">Use hardware acceleration for commercial detection</span>
77-
Uses hardware acceleration for commercial detection - compatible only with Nvidia cuvid currently.
78-
Do not select if you do not have a compatible Nvidia GPU.
77+
Uses hardware acceleration for commercial detection - compatible with nvidia and QSV GPUs.
78+
Autodetects specific GPU installed and will fallback to no hardware acceleration if no useable GPU was found.
79+
Prefers nvidia if both nvidia and qsv GPUs are found.

info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
"on_postprocessor_task_results":1
1515
},
1616
"tags": "video,pvr,library file test",
17-
"version": "0.0.9"
17+
"version": "0.0.10"
1818
}

init.d/install-comskip.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@
55
# File Created: 28 September 2021, 8:03 AM
66
# Author: josh5
77
# -----
8-
# Last Modified: 28 September 2021, 8:03 AM
8+
# Last Modified: 04 December 2025, 6:15 PM
99
# Modified By: josh5
1010
# -
1111

1212
# Script is executed by the Unmanic container on startup to auto-install dependencies
1313

14-
if ! command -v comskip &> /dev/null; then
14+
if ! command -v comskip &> /dev/null || [[ $(( $(comskip 2>&1 | head -1 | awk '{ print $2 }' | tr -d ',' | awk -F'.' '{print $2}') )) < 83 ]]; then
1515
echo "**** Installing Comskip ****"
16-
apt-get update
17-
apt-get install -y comskip
16+
/usr/bin/apt-get update
17+
/usr/bin/apt-get install -y autoconf libtool pkg-config make libswscale-dev libavformat-dev libavcodec-dev libavutil-dev libargtable2-dev
18+
cd /root
19+
wget https://github.com/erikkaashoek/Comskip/archive/refs/heads/master.zip
20+
wait $!
21+
unzip master.zip
22+
cd Comskip-master
23+
./autogen.sh
24+
./configure --disable-dependency-tracking
25+
make
26+
cp -a /root/Comskip-master/comskip /usr/local/bin/comskip
1827
else
19-
echo "**** Comskip already installed ****"
28+
echo "**** Comskip already installed ****"
2029
fi

plugin.py

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import os
2828
import stat
2929
import re
30+
import subprocess
31+
from pathlib import Path
32+
3033
from configparser import NoSectionError, NoOptionError
3134

3235
from unmanic.libs.unplugins.settings import PluginSettings
@@ -202,6 +205,43 @@ def comskip_config_file(settings):
202205

203206
return comskip_config_file
204207

208+
def get_render_vendor():
209+
render_root= Path('/dev/dri')
210+
render_dev = [render_device for render_device in render_root.glob("render*")]
211+
#if render_dev is not empty, render devices were found
212+
213+
render_names = [dev.name for dev in render_dev]
214+
for rdev in render_names:
215+
if os.path.exists(os.path.join("/sys/class/drm", render_names[0], "device/vendor")):
216+
vendor = Path(os.path.join("/sys/class/drm", render_names[0], "device/vendor"))
217+
vendor_text = vendor.read_text()
218+
if "0x8086" in vendor_text:
219+
return rdev
220+
return ""
221+
222+
def get_gpu():
223+
command = '[[ $(compgen -G /dev/nvidia*) != "" ]] && [[ $(command -v nvidia-smi) != "" ]] && echo "nvidia_gpu_and_driver_installed"'
224+
result = subprocess.run (["bash", "-c", command], capture_output=True, text=True, check=False)
225+
if "nvidia_gpu_and_driver_installed" in result.stdout:
226+
logger.info(f"nvidia GPU detected in container and driver installed")
227+
decoder = "--cuvid"
228+
else:
229+
logger.info(f"nvidia GPU not detected in container or driver not installed")
230+
decoder = ""
231+
232+
if get_render_vendor() == '':
233+
logger.info(f"QSV capable GPU not detected in container")
234+
else:
235+
command = '[[ $(vainfo --display drm --device "$INTEL_NODE" 2>/dev/null) ]] && echo "intel driver installed"'
236+
result = subprocess.run (["bash", "-c", command], capture_output=True, text=True, check=False)
237+
if "intel driver installed" in result.stdout:
238+
logger.info(f"QSV GPU driver detected as installed in container")
239+
if decoder == "--cuvid":
240+
decoder += "+ --qsv"
241+
else:
242+
decoder = "--qsv"
243+
# if cuvid nor qsv is detected, decoder should be "" here
244+
return decoder
205245

206246
def build_comskip_args(abspath, settings):
207247
config_file = comskip_config_file(settings)
@@ -210,15 +250,24 @@ def build_comskip_args(abspath, settings):
210250
file_ext = os.path.splitext(abspath)[1]
211251
use_hw = settings.get_setting('use_hw')
212252
comskip_args = ['comskip','--ini={}'.format(config_file),'--output={}'.format(file_dirname),'--output-filename={}'.format(file_sans_ext),abspath]
253+
if use_hw:
254+
decoder = get_gpu()
255+
if decoder == "--cuvid + --qsv":
256+
logger.info(f"Can use either cuvid or qsv - picking cuvid")
257+
decoder == '--cuvid'
258+
elif decoder == "":
259+
use_hw = False
260+
logger.info(f"h/w decoding was configured but no nvidia or qsv decoder was found - falling back to cpu based decoding")
261+
213262
if (not use_hw) & (file_ext == '.ts'):
214263
comskip_args.insert(1, '-t')
215264

216265
if use_hw & (file_ext != '.ts'):
217-
comskip_args.insert(1, '--cuvid')
266+
comskip_args.insert(1, decoder)
218267

219268
if use_hw & (file_ext == '.ts'):
220269
comskip_args.insert(1, '-t')
221-
comskip_args.insert(2, '--cuvid')
270+
comskip_args.insert(2, decoder)
222271

223272
return comskip_args
224273

@@ -230,6 +279,15 @@ def build_comchap_args(abspath, file_out, settings):
230279
st = os.stat(comchap_path)
231280
os.chmod(comchap_path, st.st_mode | stat.S_IEXEC)
232281
use_hw = settings.get_setting('use_hw')
282+
if use_hw:
283+
decoder = get_gpu()
284+
if decoder == "--cuvid + --qsv":
285+
logger.info(f"For comchap - can use either cuvid or qsv - picking cuvid")
286+
decoder == '--cuvid'
287+
elif decoder == "":
288+
use_hw = False
289+
logger.info(f"for comchap - h/w decoding was configured but no nvidia or qsv decoder was found - falling back to cpu based decoding")
290+
233291
if not use_hw:
234292
args = [
235293
comchap_path,
@@ -244,7 +302,7 @@ def build_comchap_args(abspath, file_out, settings):
244302
args = [
245303
comchap_path,
246304
'--comskip-ini={}'.format(config_file),
247-
'--use-hw',
305+
decoder,
248306
'--keep-edl',
249307
'--keep-meta',
250308
'--verbose',
@@ -261,6 +319,15 @@ def build_comcut_args(abspath, file_out, settings):
261319
st = os.stat(comcut_path)
262320
os.chmod(comcut_path, st.st_mode | stat.S_IEXEC)
263321
use_hw = settings.get_setting('use_hw')
322+
if use_hw:
323+
decoder = get_gpu()
324+
if decoder == "--cuvid + --qsv":
325+
logger.info(f"For comcut - can use either cuvid or qsv - picking cuvid")
326+
decoder == '--cuvid'
327+
elif decoder == "":
328+
use_hw = False
329+
logger.info(f"for comcut - h/w decoding was configured but no nvidia or qsv decoder was found - falling back to cpu based decoding")
330+
264331
if not use_hw:
265332
args = [
266333
comcut_path,
@@ -274,7 +341,7 @@ def build_comcut_args(abspath, file_out, settings):
274341
args = [
275342
comcut_path,
276343
'--comskip-ini={}'.format(config_file),
277-
'--use-hw',
344+
decoder,
278345
'--keep-edl',
279346
'--keep-meta',
280347
abspath,

0 commit comments

Comments
 (0)