Skip to content

fix: Data levels issues #209

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

Merged
merged 4 commits into from
Aug 24, 2022
Merged
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
1 change: 1 addition & 0 deletions proxima/queuer/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def get_resolve_proxy_jobs(media_pool_items):
"file_name": cp["File Name"],
"file_path": cp["File Path"],
"duration": cp["Duration"],
"data_level": cp["Data Level"],
"resolution": str(cp["Resolution"]).split("x"),
"frames": int(cp["Frames"]),
"fps": float(cp["FPS"]),
Expand Down
2 changes: 1 addition & 1 deletion proxima/worker/ffmpeg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def frac_to_dec(fraction: str):
return float(f)


def get_media_info(file):
def ffprobe(file):
"""Get media info from file using ffprobe"""

cmd = f'ffprobe -v quiet -print_format json -show_format -show_streams "{file}"'
Expand Down
2 changes: 1 addition & 1 deletion proxima/worker/launch_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def main(workers: int = 0):
launch_workers(prompt_worker_amount(cpu_cores), queue_name)

print(f"[green]Done![/]")
core.app_exit(0, 5)
core.app_exit(0, 2)


if __name__ == "__main__":
Expand Down
23 changes: 21 additions & 2 deletions proxima/worker/tasks/encode/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,46 @@ def encode_proxy(self, job):
ps = job["proxy_settings"]

ffmpeg_command = [
# INPUT
"ffmpeg",
"-y", # Never prompt!
*ps["misc_args"], # User global settings
*ps["misc_args"],
"-i",
job["file_path"],
# VIDEO
"-c:v",
ps["codec"],
"-profile:v",
ps["profile"],
"-vsync",
"-1", # Necessary to match VFR
# TODO: Format this better
# It's hard to format this. Every arg behind the -vf flag
# should be separated by a literal comma and NO SPACES to string them together as per ffmpeg syntax.
# Any optional args must provide their own literal commas so as not to leave them stray
# if disabled... Inline functions here are also confusing and "magical".
# But we don't want to run them queuer side, only on final queueables.
# labels: enhancement
# VIDEO FILTERS
"-vf",
f"scale=-2:{int(job['proxy_settings']['vertical_res'])},"
f"scale={utils.get_input_level(job)}:out_range=limited, "
f"{utils.get_flip(job)}"
f"format={ps['pix_fmt']}",
f"format={ps['pix_fmt']}"
if ps["pix_fmt"]
else "",
# AUDIO
"-c:a",
ps["audio_codec"],
"-ar",
ps["audio_samplerate"],
# TIMECODE
"-timecode",
job["start_tc"],
# FLAGS
"-movflags",
"+write_colr",
# OUTPUT
output_path,
]

Expand Down
34 changes: 34 additions & 0 deletions proxima/worker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from ..app.utils import core
from ..settings.manager import SettingsManager
from ..worker.ffmpeg.utils import ffprobe

core.install_rich_tracebacks()

Expand Down Expand Up @@ -68,6 +69,39 @@ def get_queue():
return file.read()


def get_input_level(job):
"""
Match Resolve's set data levels ("Auto", "Full" or "Video")

Uses ffprobe to probe file for levels if Resolve data levels are set to Auto.
"""

def probe_for_input_range(job):
"""
Probe file with ffprobe for colour range
and map to ffmpeg 'in_range' value ("full" or "limited")
"""

input = job["file_path"]
info = ffprobe(file=input)["streams"][0]
color_data = {k: v for k, v in info.items() if "color" in k}
logger.debug(f"[magenta]Probed color data:\n{color_data}")

switch = {
"pc": "in_range=full",
"tv": "in_range=limited",
}
return switch[info["color_range"]]

switch = {
"Auto": probe_for_input_range(job),
"Full": "in_range=full",
"Video": "in_range=limited",
}

return switch[job["data_level"]]


def get_flip(job):

flip = str()
Expand Down
2 changes: 1 addition & 1 deletion version_constraint_key
Original file line number Diff line number Diff line change
@@ -1 +1 @@
constantly-cool-corgi
annually-awaited-akita