Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please provide script to interpolate video in one line #49

Open
yusing opened this issue Jul 12, 2022 · 4 comments
Open

Please provide script to interpolate video in one line #49

yusing opened this issue Jul 12, 2022 · 4 comments

Comments

@yusing
Copy link

yusing commented Jul 12, 2022

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裡:)

@ArchieMeng
Copy link

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

@n00mkrad
Copy link

n00mkrad commented Aug 2, 2022

And of course Flowframes ;)

@L4cache
Copy link

L4cache commented Aug 25, 2022

fu*king no just use vapoursynth okay?

@yusing
Copy link
Author

yusing commented Aug 25, 2022

fu*king no just use vapoursynth okay?

Ya let’s be toxic mate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants