nihui / rife-ncnn-vulkan

RIFE, Real-Time Intermediate Flow Estimation for Video Frame Interpolation implemented with ncnn library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Please provide script to interpolate video in one line

yusing opened this issue · comments

I've written a template python script.

import sys
import os
import re
import shutil
if len(sys.argv) < 2:
    print("Usage: python3 start.py <filename>")
    exit(1)
video = sys.argv[1]
if not os.path.exists(video):
    print("File not found: " + video)
    exit(1)

print('Getting fps of video...')
try:
    output = os.popen(f'ffprobe -v quiet -show_streams -select_streams v:0 "{video}"').read()
    matches = re.search(r'r_frame_rate\=(\d+)\/(\d+)', output, re.MULTILINE)
    a = int(matches.group(1))
    b = int(matches.group(2))
    fps = a / b
    print(f'FPS: {fps}')
except Exception as e:
    print(f'Error getting fps: {e}')
    exit(1)
    
if 'encodeonly' not in sys.argv:
    try:
        if os.path.exists('input_frames'):
            shutil.rmtree('input_frames')
        if os.path.exists('output_frames'):
            shutil.rmtree('output_frames')
        os.makedirs('input_frames')
        os.makedirs('output_frames')
    except Exception as e:
        print(f'Error cleaning/creating input and output frames directories: {e}')
        exit(1)
    print('Extracting audio...')
    if os.system(f'ffmpeg -y -i "{video}" -vn -acodec copy audio.m4a') != 0:
        print('Error extracting audio')
        exit(1)
    print('Decoding all frames...')
    if os.system(f'ffmpeg -i "{video}" input_frames/frame%08d.png') != 0:
        print('Error decoding frames')
        exit(1)
    print('Interpolating 2x frames...')
    if os.system(f'rife-ncnn-vulkan -i input_frames -o output_frames') != 0:
        print('Error interpolating frames')
        exit(1)
print('Encoding video...')
if os.system(f'ffmpeg -y -hwaccel cuda -hwaccel_output_format cuda -framerate {fps * 2} -i output_frames/%08d.png -i audio.m4a -c:a copy -c:v h264_nvenc -strict -2 -pix_fmt yuv420p output.mkv') != 0:
    print('Error encoding video')
    exit(1)

To use:
python3 start.py video.mp4

或許你可以改良一下然後push到你的repostory裡:)

There are already many tools to do so.
Video2x
SVFI
anime2x
Waifu2x-Extension-GUI
And the first three software are written in Python. :)

And of course Flowframes ;)

fu*king no just use vapoursynth okay?

fu*king no just use vapoursynth okay?

Ya let’s be toxic mate.