Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add qscale option for ffmpeg to control thumbnail quality #56

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Nick.Plugin.Jellyscrub/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public PluginConfiguration() {}
/// </summary>
public HashSet<int> WidthResolutions { get; set; } = new HashSet<int> { 320 };

/// <summary>
/// FFmpeg qscale value.
/// The lower the value, the better the quality
/// </summary>
public int QscaleValue { get; set; } = 0;

/// <summary>
/// Set the number of threads to be used by ffmpeg.
/// -1 = use default from jellyfin
Expand Down
17 changes: 17 additions & 0 deletions Nick.Plugin.Jellyscrub/Configuration/configPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@
<div class="fieldDescription"><strong>Note:</strong> Do not include spaces after commas.</div>
</div>

<div class="inputContainer">
<select is="emby-select" id="qscaleValue" name="Thumbnail Quality" label="Thumbnail Quality">
<option id="opt0" value=0>Disabled</option>
<option id="opt2" value=2>2</option>
<option id="opt3" value=3>3</option>
<option id="opt4" value=4>4</option>
<option id="opt5" value=5>5</option>
<option id="opt6" value=6>6</option>
</select>
<div class="fieldDescription">This setting controls the thumbnail quality by passing a value <strong>between 2 and 6</strong> to the "-qscale" argument of ffmpeg.</div>
<div class="fieldDescription">By default this setting will not be used which roughly equals a "-qscale" value of 2.</div>
<div class="fieldDescription">A higher value means lower quality and a lower value means higher quality.</div>
<div class="fieldDescription">If you want the .bif files to take up less space, try setting a value of 3 or higher.</div>
</div>

<div class="inputContainer">
<select is="emby-select" id="processPriority" name="Process Priority" label="Process Priority">
<!--<option id="optPriorityRealtime" value="Realtime">Realtime</option>-->
Expand Down Expand Up @@ -153,6 +168,7 @@
// page.querySelector('#chkStyleTrickplayContainer').checked = config.StyleTrickplayContainer;
page.querySelector('#intervalInput').value = config.Interval;
page.querySelector('#resolutionInput').value = fromIntArray(config.WidthResolutions);
page.querySelector('#qscaleValue').value = config.QscaleValue;
page.querySelector('#processPriority').value = config.ProcessPriority;
page.querySelector('#processThreads').value = config.ProcessThreads;

Expand All @@ -176,6 +192,7 @@
// config.StyleTrickplayContainer = page.querySelector('#chkStyleTrickplayContainer').checked;
config.Interval = Math.max(0, form.querySelector('#intervalInput').value);
config.WidthResolutions = toIntArray(form.querySelector('#resolutionInput').value);
config.QscaleValue= form.querySelector('#qscaleValue').value;
config.ProcessPriority = form.querySelector('#processPriority').value;
config.ProcessThreads = form.querySelector('#processThreads').value;

Expand Down
12 changes: 11 additions & 1 deletion Nick.Plugin.Jellyscrub/Drawing/OldMediaEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class OldMediaEncoder

private string _ffmpegPath;
private int _threads;
private int _qscaleValue;
private readonly PluginConfiguration _config;

public OldMediaEncoder(
Expand All @@ -44,6 +45,7 @@ public OldMediaEncoder(

_config = JellyscrubPlugin.Instance!.Configuration;
var configThreads = _config.ProcessThreads;
var configQscaleValue = _config.QscaleValue;

var encodingConfig = _configurationManager.GetEncodingOptions();
_ffmpegPath = _mediaEncoder.EncoderPath;
Expand All @@ -55,6 +57,7 @@ public OldMediaEncoder(
}

_threads = configThreads == -1 ? EncodingHelper.GetNumberOfThreads(null, encodingConfig, null) : configThreads;
_qscaleValue = configQscaleValue;
}

public async Task ExtractVideoImagesOnInterval(
Expand Down Expand Up @@ -87,7 +90,14 @@ public async Task ExtractVideoImagesOnInterval(
Directory.CreateDirectory(targetDirectory);
var outputPath = Path.Combine(targetDirectory, filenamePrefix + "%08d.jpg");

var args = string.Format(CultureInfo.InvariantCulture, "-threads {3} -i {0} -threads {4} -v quiet {2} -f image2 \"{1}\"", inputArgument, outputPath, vf, _threads, _threads);
var args = string.Format(CultureInfo.InvariantCulture, "-threads {2} -i {0} -threads {2} -v quiet {1} -f image2", inputArgument, vf, _threads);

if (_qscaleValue != 0)
{
args = args + " " + string.Format(CultureInfo.InvariantCulture, "-qscale:v {0}", _qscaleValue);
}

args = args + " " + string.Format(CultureInfo.InvariantCulture, "\"{0}\"", outputPath);

if (!string.IsNullOrWhiteSpace(container))
{
Expand Down