Skip to content

Commit da37feb

Browse files
committed
Fix bug where intermittently HW accelerated config was reverted to CPU encoding on its own
1 parent 20c3138 commit da37feb

9 files changed

Lines changed: 75 additions & 23 deletions

File tree

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
**<span style="color:#56adda">0.1.13</span>**
2+
- Fix bug where intermittently HW accelerated config was reverted to CPU encoding on its own
3+
14
**<span style="color:#56adda">0.1.12</span>**
25
- Improved handling for HDR content with new helper tools for detecting and parsing metadata.
36
- Removed the look-ahead feature from QSV's HEVC and AV1 encoders (not supported).

info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
"on_worker_process": 1
1313
},
1414
"tags": "video,ffmpeg",
15-
"version": "0.1.12"
15+
"version": "0.1.13"
1616
}

lib/encoders/libsvtav1.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,16 @@ def __set_default_option(self, select_options, key, default_option=None):
167167
available_options.append(option.get('value'))
168168
if not default_option:
169169
default_option = option.get('value')
170-
if self.settings.get_setting(key) not in available_options:
171-
self.settings.set_setting(key, default_option)
170+
current_value = self.settings.get_setting(key)
171+
if not getattr(self.settings, 'apply_default_fallbacks', True):
172+
return current_value
173+
if current_value not in available_options:
174+
# Update in-memory setting for display only.
175+
# IMPORTANT: do not persist settings from plugin.
176+
# Only the Unmanic API calls should persist to JSON file.
177+
self.settings.settings_configured[key] = default_option
178+
return default_option
179+
return current_value
172180

173181
def get_preset_form_settings(self):
174182
values = {

lib/encoders/libx.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,16 @@ def __set_default_option(self, select_options, key, default_option=None):
201201
available_options.append(option.get('value'))
202202
if not default_option:
203203
default_option = option.get('value')
204-
if self.settings.get_setting(key) not in available_options:
205-
self.settings.set_setting(key, default_option)
204+
current_value = self.settings.get_setting(key)
205+
if not getattr(self.settings, 'apply_default_fallbacks', True):
206+
return current_value
207+
if current_value not in available_options:
208+
# Update in-memory setting for display only.
209+
# IMPORTANT: do not persist settings from plugin.
210+
# Only the Unmanic API calls should persist to JSON file.
211+
self.settings.settings_configured[key] = default_option
212+
return default_option
213+
return current_value
206214

207215
def get_preset_form_settings(self):
208216
values = {

lib/encoders/nvenc.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,16 @@ def __set_default_option(self, select_options, key, default_option=None):
323323
available_options.append(option.get('value'))
324324
if not default_option:
325325
default_option = option.get('value')
326-
if self.settings.get_setting(key) not in available_options:
327-
self.settings.set_setting(key, default_option)
326+
current_value = self.settings.get_setting(key)
327+
if not getattr(self.settings, 'apply_default_fallbacks', True):
328+
return current_value
329+
if current_value not in available_options:
330+
# Update in-memory setting for display only.
331+
# IMPORTANT: do not persist settings from plugin.
332+
# Only the Unmanic API calls should persist to JSON file.
333+
self.settings.settings_configured[key] = default_option
334+
return default_option
335+
return current_value
328336

329337
def get_nvenc_device_form_settings(self):
330338
values = {

lib/encoders/qsv.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,16 @@ def __set_default_option(self, select_options, key, default_option=None):
271271
available_options.append(option.get('value'))
272272
if not default_option:
273273
default_option = option.get('value')
274-
if self.settings.get_setting(key) not in available_options:
275-
self.settings.set_setting(key, default_option)
274+
current_value = self.settings.get_setting(key)
275+
if not getattr(self.settings, 'apply_default_fallbacks', True):
276+
return current_value
277+
if current_value not in available_options:
278+
# Update in-memory setting for display only.
279+
# IMPORTANT: do not persist settings from plugin.
280+
# Only the Unmanic API calls should persist to JSON file.
281+
self.settings.settings_configured[key] = default_option
282+
return default_option
283+
return current_value
276284

277285
def get_qsv_decoding_method_form_settings(self):
278286
values = {

lib/encoders/vaapi.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,16 @@ def __set_default_option(self, select_options, key, default_option=None):
315315
available_options.append(option.get('value'))
316316
if not default_option:
317317
default_option = option.get('value')
318-
if self.settings.get_setting(key) not in available_options:
319-
self.settings.set_setting(key, default_option)
318+
current_value = self.settings.get_setting(key)
319+
if not getattr(self.settings, 'apply_default_fallbacks', True):
320+
return current_value
321+
if current_value not in available_options:
322+
# Update in-memory setting for display only.
323+
# IMPORTANT: do not persist settings from plugin.
324+
# Only the Unmanic API calls should persist to JSON file.
325+
self.settings.settings_configured[key] = default_option
326+
return default_option
327+
return current_value
320328

321329
def get_vaapi_device_form_settings(self):
322330
values = {

lib/global_settings.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,16 @@ def __set_default_option(self, select_options, key, default_option=None):
9494
available_options.append(option.get("value"))
9595
if not default_option:
9696
default_option = option.get("value")
97-
if self.settings.get_setting(key) not in available_options:
98-
self.settings.set_setting(key, default_option)
97+
current_value = self.settings.get_setting(key)
98+
if not getattr(self.settings, 'apply_default_fallbacks', True):
99+
return current_value
100+
if current_value not in available_options:
101+
# Update in-memory setting for display only.
102+
# IMPORTANT: do not persist settings from plugin.
103+
# Only the Unmanic API calls should persist to JSON file.
104+
self.settings.settings_configured[key] = default_option
105+
return default_option
106+
return current_value
99107

100108
def get_mode_form_settings(self):
101109
return {

plugin.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131
- Add support for source bitrate matching on basic mode
3232
"""
3333

34-
import logging
3534
import os
36-
35+
import logging
3736
from video_transcoder.lib import plugin_stream_mapper, tools
3837
from video_transcoder.lib.ffmpeg import Parser, Probe
3938
from video_transcoder.lib.global_settings import GlobalSettings
@@ -42,9 +41,9 @@
4241
from video_transcoder.lib.encoders.vaapi import VaapiEncoder
4342
from video_transcoder.lib.encoders.nvenc import NvencEncoder
4443
from video_transcoder.lib.encoders.libsvtav1 import LibsvtAv1Encoder
45-
46-
from unmanic.libs.unplugins.settings import PluginSettings
4744
from unmanic.libs.directoryinfo import UnmanicDirectoryInfo
45+
from unmanic.libs.unplugins.settings import PluginSettings
46+
4847

4948
# Configure plugin logger
5049
logger = logging.getLogger("Unmanic.Plugin.video_transcoder")
@@ -53,6 +52,8 @@
5352
class Settings(PluginSettings):
5453

5554
def __init__(self, *args, **kwargs):
55+
# Add optional flag to disable default fallback logic. This should be set for the plugin runner calls
56+
self.apply_default_fallbacks = kwargs.pop('apply_default_fallbacks', True)
5657
super(Settings, self).__init__(*args, **kwargs)
5758
self.settings = self.__build_settings_object()
5859
self.global_settings = GlobalSettings(self)
@@ -181,8 +182,8 @@ def on_library_management_file_test(data):
181182
182183
"""
183184

184-
# Get settings
185-
settings = Settings(library_id=data.get('library_id'))
185+
# Get settings (do not persist defaults during worker/library execution)
186+
settings = Settings(library_id=data.get('library_id'), apply_default_fallbacks=False)
186187

187188
# Get the path to the file
188189
abspath = data.get('path')
@@ -233,8 +234,8 @@ def on_worker_process(data):
233234
data['exec_command'] = []
234235
data['repeat'] = False
235236

236-
# Get settings
237-
settings = Settings(library_id=data.get('library_id'))
237+
# Get settings (do not persist defaults during worker execution)
238+
settings = Settings(library_id=data.get('library_id'), apply_default_fallbacks=False)
238239

239240
# Get the path to the file
240241
abspath = data.get('file_in')
@@ -308,8 +309,8 @@ def on_postprocessor_task_results(data):
308309
:param data:
309310
:return:
310311
"""
311-
# Get settings
312-
settings = Settings(library_id=data.get('library_id'))
312+
# Get settings (do not persist defaults during post-processing)
313+
settings = Settings(library_id=data.get('library_id'), apply_default_fallbacks=False)
313314

314315
# Get the original file's absolute path
315316
original_source_path = data.get('source_data', {}).get('abspath')

0 commit comments

Comments
 (0)