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

Commit

Permalink
General: added fallback for broken ffprobe return (#6189)
Browse files Browse the repository at this point in the history
* OP-8090 - added fallback for ffprobe issue

Customer provided .exr returned width and height equal to 0 which caused error in extract_thumbnail. This tries to use oiiotool to get metadata about file, in our case it read it correctly.

* OP-8090 - extract logic

`get_rescaled_command_arguments` is long enough right now, new method is better testable too.

* Update openpype/lib/transcoding.py

Co-authored-by: Jakub Trllo <[email protected]>

---------

Co-authored-by: Jakub Trllo <[email protected]>
  • Loading branch information
kalisp and iLLiCiTiT authored Feb 5, 2024
1 parent 2f714fd commit ed339ed
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 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,48 @@ 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)
input_width = input_height = 0
stream = next(
(
s for s in input_file_metadata["streams"]
if s.get("codec_type") == "video"
),
{}
)
if stream:
input_width = int(stream["width"])
input_height = int(stream["height"])

# 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)
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

0 comments on commit ed339ed

Please sign in to comment.