From d254d050f3adf910541090dbba0e808a77ccda8a Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 28 Mar 2024 12:30:13 -0700 Subject: [PATCH] update ffmpeg output return to resolve error --- thu.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/thu.sh b/thu.sh index f8603fe..f809322 100755 --- a/thu.sh +++ b/thu.sh @@ -627,6 +627,14 @@ img_wh_get () { fi } +video_info_ffmpeg () { + if [[ -z "$is_cmd_ffmpeg" ]]; then + fail "$msg_cmd_not_found_ffmpeg" + fi + + ffmpeg -i "$1" 2>&1 +} + video_duration_ffmpeg_parse_ss () { duration_match="" @@ -637,17 +645,13 @@ video_duration_ffmpeg_parse_ss () { fi done < <(printf '%s\n' "$1") - if [[ -z "$duration_match" ]]; then - fail "video duration could not detected" - fi - IFS=" " read -r HOURS MINUTES SECONDS <<< "${duration_match//:/ }" duration_ss=$((10#$HOURS * 3600 + 10#$MINUTES * 60 + 10#$SECONDS)) if [[ "$duration_ss" =~ $numint_re ]]; then printf '%s\n' "$duration_ss" else - fail "video duration could not detected: $1" + fail "video duration could not be detected: $1" fi } @@ -758,7 +762,7 @@ thumb_create_from_epub () { thumb_create_from_video () { vid_path=$1 vid_wh_max=$2 - vid_ffmpeg_output=$(ffmpeg -i "$1" 2>&1) + vid_ffmpeg_output=$(video_info_ffmpeg "$1") vid_duration_ss=$(video_duration_ffmpeg_parse_ss "$vid_ffmpeg_output") vid_wh_native=$(video_resolution_ffmpeg_parse "$vid_ffmpeg_output") vid_wh_scaled=$(wh_scaled_get "$vid_wh_native" "$vid_wh_max") @@ -766,10 +770,6 @@ thumb_create_from_video () { vid_thumb_path=$( cachedir_path_get "$cachedir" "video" "$vid_wh_scaled" ".png") - if [[ -z "$is_cmd_ffmpeg" ]]; then - fail "$msg_cmd_not_found_ffmpeg"; - fi - ffmpeg \ -ss "$vid_frame_ss" \ -i "$vid_path" \