Please provide script to interpolate video in one line
yusing opened this issue · comments
Yuzerion commented
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 commented
There are already many tools to do so.
Video2x
SVFI
anime2x
Waifu2x-Extension-GUI
And the first three software are written in Python. :)
N00MKRAD commented
And of course Flowframes ;)
李四 commented
fu*king no just use vapoursynth okay?
Yuzerion commented
fu*king no just use vapoursynth okay?
Ya let’s be toxic mate.