hzwer / Practical-RIFE

We are developing more practical approach for users based on RIFE.
MIT License
505 stars 56 forks source link

How to avoid RIFE from Re-encoding output to MPEG codec #71

Open AxmanaleX opened 1 month ago

AxmanaleX commented 1 month ago

First off, I apologize for my poor English. I'm not very fluent, and I hope my question isn't too naive. I don't know much about how RIFE really works.

Let's say I want to interpolate a video that uses the H.264 codec. After the interpolation process, the video ends up using the MPEG-4 codec. This not only changes the codec from H.264 but also affects the bitrate and quality. I was wondering if it's possible to choose a different codec instead of MPEG, as well as adjust output parameters like CRF, etc. (By the way, I'm using Practical RIFE on Google Colab.)

This is the command I'm currently using

!python3 inference_video.py --multi=3 --video=video.mp4

AIManifest commented 1 month ago

Hey my friend,

Just based on reading the documentation, it would appear that inference_video.py uses cv2 to write the frames to the video. There are a few things I've seen: cv2.VideoWriter_fourcc(*'avc1'), this would need to be installed using apt instead of pip --> pip uninstall opencv-python sudo apt install build-essential cmake git python3-dev python3-numpy \ libavcodec-dev libavformat-dev libswscale-dev \ libgstreamer-plugins-base1.0-dev \ libgstreamer1.0-dev libgtk-3-dev \ libpng-dev libjpeg-dev libopenexr-dev libtiff-dev libwebp-dev \ libopencv-dev x264 libx264-dev libssl-dev ffmpeg python -m pip install --no-binary opencv-python opencv-python

From here you can change the line 116 in inference_video.py from fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v') to cv2.VideoWriter_fourcc(*'avc1'). As for crf options, I haven't found a solid solution for that yet, but this is a good start and hopefully is helpful!