Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

General: added fallback for broken ffprobe return #6189

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Changes from 2 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
42 changes: 36 additions & 6 deletions openpype/lib/transcoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,12 +1227,8 @@ def get_rescaled_command_arguments(
target_par = target_par or 1.0
input_par = 1.0

# ffmpeg command
input_file_metadata = get_ffprobe_data(input_path, logger=log)
stream = input_file_metadata["streams"][0]
input_width = int(stream["width"])
input_height = int(stream["height"])
stream_input_par = stream.get("sample_aspect_ratio")
input_height, input_width, stream_input_par = _get_image_dimensions(
application, input_path, log)
if stream_input_par:
input_par = (
float(stream_input_par.split(":")[0])
Expand Down Expand Up @@ -1345,6 +1341,40 @@ def get_rescaled_command_arguments(
return command_args


def _get_image_dimensions(application, input_path, log):
"""Uses 'ffprobe' first and then 'oiiotool' if available to get dim.

Args:
application (str): "oiiotool"|"ffmpeg"
input_path (str): path to image file
log (Optional[logging.Logger]): Logger used for logging.
Returns:
(tuple) (int, int, dict) - (height, width, sample_aspect_ratio)
Raises:
RuntimeError if image dimensions couldn't be parsed out.
"""
# ffmpeg command
input_file_metadata = get_ffprobe_data(input_path, logger=log)
stream = input_file_metadata["streams"][0]
input_width = int(stream["width"])
input_height = int(stream["height"])
kalisp marked this conversation as resolved.
Show resolved Hide resolved

# fallback for weird files with width=0, height=0
if (input_width == 0 or input_height == 0) and application == "oiiotool":
# Load info about file from oiio tool
input_info = get_oiio_info_for_input(input_path, logger=log)
iLLiCiTiT marked this conversation as resolved.
Show resolved Hide resolved
if input_info:
input_width = int(input_info["width"])
input_height = int(input_info["height"])

if input_width == 0 or input_height == 0:
raise RuntimeError("Couldn't read {} either "
"with ffprobe or oiiotool".format(input_path))

stream_input_par = stream.get("sample_aspect_ratio")
return input_height, input_width, stream_input_par


def convert_color_values(application, color_value):
"""Get color mapping for ffmpeg and oiiotool.
Args:
Expand Down
Loading