diff --git a/scripts/extract.sh b/scripts/extract.sh index f221537..5b9312f 100644 --- a/scripts/extract.sh +++ b/scripts/extract.sh @@ -52,6 +52,22 @@ function extract_chapters () echo "DUMMY" } +function extract_framedurations () # $1: stream index +{ + local FileIndex=0 + echo "ffconcat version 1.0" > "$FrameDurationList" + while read Line + do + if echo "$Line" | grep -qF 'pts_time='; then + ((FileIndex++)) + printf "file \'./$(basename $FramesUpscaledDir)/%06d.png\'\n" "$FileIndex" >> "$FrameDurationList" + echo "inpoint $(echo "$Line" | grep -Po '\d+\.\d+')" >> "$FrameDurationList" + elif echo "$Line" | grep -qF 'duration_time='; then + echo "duration $(echo "$Line" | grep -Po '\d+\.\d+')" >> "$FrameDurationList" + fi + done < <(ffprobe -v quiet -show_entries packet=pts_time,duration_time -select_streams "$Index" "$InputFile") +} + if [[ -z "$1" ]]; then echo "You must specify the video file" exit "$PARAMETER_ERROR" @@ -89,6 +105,7 @@ do case "$Type" in video ) + extract_framedurations "$Index" ffmpeg -hide_banner -i "$InputFile" -map "0:$Index" -c:v copy "$VideoDir/$Index.$Extension" if [[ "$?" != 0 ]]; then exit "$EXTRACT_AUDIO_ERROR"; fi ;; audio ) diff --git a/scripts/frames.sh b/scripts/frames.sh index 3548668..03eb138 100644 --- a/scripts/frames.sh +++ b/scripts/frames.sh @@ -23,8 +23,8 @@ if ! [[ -r "$InputFile" ]]; then fi rm -rf "$FramesDir"; mkdir -p "$FramesDir" - -ffmpeg -hide_banner -i "$InputFile" -r "$(framerate)" -f image2 "$FramesDir/%06d.png" +# passthrough +ffmpeg -hide_banner -i "$InputFile" -r "$(framerate)" -f image2 -vsync vfr "$FramesDir/%06d.png" if [[ "$?" != 0 ]]; then exit "$CONVERT_TO_FRAMES_ERROR" diff --git a/scripts/video.sh b/scripts/video.sh index 637d308..13e5898 100644 --- a/scripts/video.sh +++ b/scripts/video.sh @@ -56,12 +56,20 @@ rm -rf "$VideoUpscaledDir"; mkdir -p "$VideoUpscaledDir" VideoUpscaled="$VideoUpscaledDir/video.mp4" +# -f "image2" \ +# -framerate "$(framerate)" \ +# -i "$FramesUpscaledDir/%06d.png" \ +# -r "$(framerate)" \ +# -vf fps="$(framerate)" \ +# + ffmpeg \ -hide_banner \ - -f "image2" \ - -framerate "$(framerate)" \ - -i "$FramesUpscaledDir/%06d.png" \ - -r "$(framerate)" \ + -f "concat" \ + -safe 0 \ + -i "$FrameDurationList" \ + -vsync vfr \ + -r "42" \ -vcodec "$VideoCodec" \ -preset "$Preset" \ -pix_fmt "$PixelFormat" \ diff --git a/video2d-2x b/video2d-2x index 88942c5..9036643 100644 --- a/video2d-2x +++ b/video2d-2x @@ -42,6 +42,7 @@ readonly VideoUpscaledDir="${VideoDir}_upscaled" readonly FormatJson="$OutputDir/format.json" readonly StreamsJson="$OutputDir/streams.json" readonly ChaptersJson="$OutputDir/chapters.json" +readonly FrameDurationList="$OutputDir/frameduration.list" readonly RangesList="$OutputDir/ranges.list"