-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Encoder improvements #127
Encoder improvements #127
Conversation
Hello. Thanks for the patch. |
If a computer has less cores than 6, will it automatically choose the right number? Or would it be better to set |
Setting the value to |
.github/RELEASE/subs2srs.conf
Outdated
# Perform loudness normalization. | ||
# Parameter explanation can be found e.g. at: | ||
# https://auphonic.com/blog/2013/01/07/loudness-targets-mobile-audio-podcasts-radio-tv/ | ||
# https://auphonic.com/blog/2019/08/19/dynamic-range-processing/ | ||
loudnorm=yes | ||
loudnorm_target=-16 | ||
loudnorm_range=11 | ||
loudnorm_peak=-1.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the new config parameters, the users will have to update their config files. For example, I have previously set loudnorm parameters using ffmpeg_audio_args
, and now I get audio files with different loudness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disabled two-pass loudnorm
by default and brought back the custom filter. Added scary warnings that filter must be removed before enabling two-pass loudnorm
.
Loudness will be the same if target, range and peak are set to the same parameters that previously were in ffmpeg_audio_args
.
cfg_mgr.lua
Outdated
-- Animated webp images can only have .webp extension. | ||
-- The user has no choice on this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lost the comment here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this comment meant that there is only one animation format, compared to three formats for still pictures. Since I've added support for another animation format, I've removed the comment.
If the comment was actually supposed to state that WebP animations come with and only with .webp
extensions, well, it's kinda obvious.
encoder.lua
Outdated
local function rescale_quality(quality, min_q, max_q) | ||
local scaled = min_q + (max_q - min_q) * quality / 100 | ||
-- Round to the nearest integer that's better in quality. | ||
if min_q > max_q then | ||
return math.floor(scaled) | ||
end | ||
return math.ceil(scaled) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function was previously named quality_to_crf but with the new name it's hard to understand what it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to fit_quality_percentage_to_range
. JPEG function was also renamed since qscale
is not CRF: https://stackoverflow.com/a/40673522. AVIF and JPEF constants were moved inside their respective functions.
encoder.lua
Outdated
'-vf', string.format("scale='min(%d,iw)':'min(%d,ih)':flags=sinc+accurate_rnd", | ||
self.config.snapshot_width, self.config.snapshot_height), | ||
'-frames:v', '1', | ||
table.unpack(encoder_args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using table.unpack() crashes mpvacious.
attempt to call field 'unpack' (a nil value)
Use h.unpack() instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better be commented somewhere.
use h.unpack() to avoid crashing mpvacious
|
end | ||
|
||
mpv.make_audio_args = function(source_path, output_path, start_timestamp, end_timestamp) | ||
mpv.make_audio_args = function(source_path, output_path, | ||
start_timestamp, end_timestamp, args_consumer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's possible to unwind these callbacks (e.g. args_consumer) to make the code more readable. Especially considering that lua doesn't have static typing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two possible ways to do that:
- Replace
mp.command_native_async
withmp.command_native
. Can block the execution for considerable time (see the timings in the head), but may not be a problem if the rest of MPV remains responsive. Have no idea how MPV handles a single blocked Lua script. - Rewrite using Lua coroutines. Never worked with these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant is you could make the args table first, and then execute the args without passing the function that executes them into the function that makes the args.
Alright. The name is confusing apparently. |
…y and scale functions
|
Images:
The code no longer passes the options encoders doesn't expect to see: AVIF gets only AVIF-specific parameters, WEBP – only WEBP-specific ones etc.
Added support for animated AVIFs.
AVIF encoder's
cpu-used
is set to 6 compared to the default of 1. On my machine, values below 6 become increasing slower without much of an improvement when it comes to file size.FFmpeg CRF 15 (high quality) 937×400 still images: 3 MB per 10k images in exchange for 1.5 to 3 times slower encoding.
FFmpeg CRF 32 (medium quality) 937×400 2 seconds animations: 1 MB per 100 images is more noticable, but the encoding time becomes obscene very very quickly.
Still image scaling now uses
sinc
, which is the best downscaling algorithm: https://stackoverflow.com/a/6171860. Animated images still use Lanczos.Image scaling now uses accurate rounding.
min()
s in scaling filter prevent image upscaling.JPEG's quality is now correctly mapped into the range 2–31.
Image aspect ratio preserving scaling now uses -1 instead of -2. According to FFmpeg docs, -n scale is here to ‘make sure that the calculated dimension is divisible by n.’ I don't quite understand while divisibility by 2 was needed in the first place.
Audio:
loudnorm
now has a proper two-pass implementation.dual_mono
is now enabled to account for mono downmixing: https://ffmpeg.org/ffmpeg-filters.html#loudnorm.Miscellanea:
append_user_audio_args
no longer moves the last argument on every insert.libaom-av1
support is now checked.