Skip to content

Commit

Permalink
update ffmpeg output return to resolve error
Browse files Browse the repository at this point in the history
  • Loading branch information
bumblehead committed Mar 28, 2024
1 parent 4cfcb72 commit d254d05
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions thu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""

Expand All @@ -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
}

Expand Down Expand Up @@ -758,18 +762,14 @@ 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")
vid_frame_ss=$(($vid_duration_ss / 5))
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" \
Expand Down

0 comments on commit d254d05

Please sign in to comment.