GithubHelp home page GithubHelp logo

hyw-dev / afi-forwarddeduplicate Goto Github PK

View Code? Open in Web Editor NEW
36.0 2.0 1.0 173 KB

Efficient Deduplicate for Anime Video Frame Interpolation

License: MIT License

Python 100.00%
animation anime deduplicate gmfss rife slomo smooth vfi video-frame-interpolation

afi-forwarddeduplicate's Introduction

📖AFI-ForwardDeduplicate

Efficient Deduplicate for Anime Video Frame Interpolation

When performing frame interpolation on anime footage, conventional de-duplicate approach such as locating duplicate frames and removal, time remapping, have many drawbacks, like losing textures of background, failure to correctly handle multiple characters drawn in different cadence in a single scene. Therefore, they cannot be applied in production effectively. However, with the advancement of video frame interpolation technology based on AI, it is proved feasible to repeatedly update the original frames to obtain high quality interpolated output of anime. This project proposes a novel anime deduplication method based on a decent VFI algorithm of GMFSS. It does not require additional procedure of processing the frame sequence or deep neural networks, and produces smooth, high quality output by removing duplicate frames in anime adequately.

ezgif com-video-to-gif

Online Colab demo for AFI-ForwardDeduplicate: [Colab]

👀Demos Videos

🔧Dependencies

  • ffmpeg
  • same as GMFSS
  • download the weights and unzip it, put them to ./weights/

⚡Usage

  • normalize the source video to 24000/1001 fps by following command using ffmpeg (If the INPUT video framerate is around 23.976, skip this step.)

    ffmpeg -i INPUT -crf 16 -r 24000/1001 -preset slow -c:v libx265 -x265-params profile=main10 -c:a copy OUTPUT
  • open the video and check out it's max consistent deduplication counts, (3 -> on Three, 2 -> on Two, 0 -> AUTO) (If the INPUT video framerate is around 23.976, skip this step.)

  • run the follwing command to finish interpolation (N_FORWARD = max_consistent_deduplication_counts - 1) (Under the most circumstances, -nf 0 can automatically determine an appropriate n_forward value)

    python interpolate_video_forward.py -i [VIDEO] -o [OUTPUTDIR] -nf [N_FORWARD] -t [TIMES] -m [MODEL_TYPE] -s -st 12 -scale [SCALE] -stf -c -half
    # or use the following command to export video at any frame rate
    python interpolate_video_forward_anyfps.py -i [VIDEO] -o [OUTPUTDIR] -nf [N_FORWARD] -fps [OUTPUT_FPS] -m [MODEL_TYPE] -s -st 12 -scale [SCALE] -stf -c
  • run the follwing command or custom command to merge the output frames with the audio of source video

    ffmpeg -r [24000/1001 * TIMES] -i [OUTPUTDIR]/%09d.png -i [VIDEO] -map 0:v -map 1:a -crf 16 -preset slow -c:v libx265 -x265-params profile=main10 -c:a copy [FINAL_OUTPUT]
    # or use the following command to export video at any frame rate
    ffmpeg -r [OUTPUT_FPS] -i [OUTPUTDIR]/%09d.png -i [VIDEO] -map 0:v -map 1:a -crf 16 -preset slow -c:v libx265 -x265-params profile=main10 -c:a copy [FINAL_OUTPUT]

example(smooth a 23.976fps video with on three and interpolate it to 60fps):

ffmpeg -i E:/Myvideo/01_src.mkv -crf 16 -r 24000/1001 -preset slow -c:v libx265 -x265-params profile=main10 -c:a copy E:/Myvideo/01.mkv

python interpolate_video_forward_anyfps.py -i E:/MyVideo/01.mkv -o E:/frame_seq_output -nf 2 -fps 60 -m gmfss -s -st 12 -scale 1.0 -stf -c

ffmpeg -r 60 -i E:/frame_seq_output/%09d.png -i E:/MyVideo/01.mkv -map 0:v -map 1:a -crf 16 -preset slow -c:v libx265 -x265-params profile=main10 -c:a copy E:/final_output/01.mkv

todo list

  • Efficiency optimization (No significant efficiency gains and increased risk of vram overflow.)
  • Attempt to accurately determine transition even in the queue_input (The implementation code is too complex, and it's effect is not obvious to improve)
  • Improve the smoothness By reducing transition frames to one frame and allocate them to the end of the scene
  • Explain why this method is effective and write a guidence on how to support other vfi algorithms
  • Implement any framerate support for ForwardDeduplicate (smooth interpolation method)

limitations

The "n_forward" parameter acts like the number of times the algorithm performs Spatiotemporal TTA (Spatiotemporal Test Time Augmentation) operations. Performing too many TTA operations may further improve smoothness and interpolation performance but lead to blurriness.

This method will change the animation rhythm to a certain extent

Projects that use AFI-ForwardDeduplicate

SVFI(commercial software)

🤗 Acknowledgement

Thanks for Q8sh2ing implement the Online Colab Demo.

Reference

SpatiotemporalResampling GMFSS Practical-RIFE

afi-forwarddeduplicate's People

Contributors

hyw-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

q8sh2ing

afi-forwarddeduplicate's Issues

Increase Processing Speed Possible?

Using GPU to covert and combine frames
ffmpeg -i in.mkv -crf 16 -r 24000/1001-preset slow -c:v hevc_nvenc -profile:v main10 -c:a copy out.mkv

ffmpeg -r 60 -thread_queue_size 5120 -i /O/%09d.png -i out.mkv -map 0:v -map 1:a -map 1:s -preset slow -gpu 0 -c:v hevc_nvenc -profile:v main10 -c:a copy output.mkv

Parallelize Frame Reading:
Use multiple threads to read and resize frames concurrently.

Use PyTorch DataLoader:
Utilize torch.utils.data.DataLoader for batch processing and to handle data loading efficiently.

Batch Inference:
Ensure inference is performed on batches of frames instead of one frame at a time.

Can this increase speed,My vram is not fully used
Rife is fast but gmfss is very slow

ImportError: cannot import name 'startupinfo' from 'skvideo.utils'

i am currently running the code on colab and this error pop-out during inference

/content/GMFSS_Fortuna/AFI-ForwardDeduplicate
Traceback (most recent call last):
File "/content/GMFSS_Fortuna/AFI-ForwardDeduplicate/interpolate_video_forward.py", line 66, in
scene_detection = SvfiTransitionDetection(save, 4,
File "/content/GMFSS_Fortuna/AFI-ForwardDeduplicate/Utils_scdet/scdet.py", line 239, in init
from Utils_scdet.utils import Tools
File "/content/GMFSS_Fortuna/AFI-ForwardDeduplicate/Utils_scdet/utils.py", line 26, in
from skvideo.utils import startupinfo
ImportError: cannot import name 'startupinfo' from 'skvideo.utils' (/usr/local/lib/python3.10/dist-packages/skvideo/utils/init.py)

.
below are the packages installed
Requirement already satisfied: scikit-video in /usr/local/lib/python3.10/dist-packages (1.1.11)
Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from scikit-video) (1.23.5)
Requirement already satisfied: pillow in /usr/local/lib/python3.10/dist-packages (from scikit-video) (9.4.0)
Requirement already satisfied: scipy in /usr/local/lib/python3.10/dist-packages (from scikit-video) (1.11.3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.