Coder Social home page Coder Social logo

ffmpeg-inference-python's Introduction

ffmpeg-inference-python: image enhancement model inference workflow on video using ffmpeg-python

Overview

当前图像/视频增强算法的官方代码往往不包含在视频文件上的推理,我们试图建立一个简单的框架,可以快速验证各种图像增强算法(包括超分、去噪、纹理色彩增强、超帧、sdr2hdr等)在视频上的效果。

ffmpeg具有强大的功能,但编写ffmpeg filter比较耗时,而ffmpeg-python使得我们可以经过简单改写算法代码,就可以完成视频推理。

Dependencies

ffmpeg with x264/x265 (or other encoder you need) support

Required Python packages: numpy ffmpeg-python

pip install ffmpeg-python

Quickstart

继承video_infer创建新类,并重写单帧推理函数 def forward(self, x), 注意x为ffmpeg的解除的yuv帧,尺寸为[3, h, w]

demo 1

将彩色视频转为黑白视频

from ffmpeg_infer import video_infer
class gray_video_infer(video_infer):
    def __init__(self, in_path, out_path, encode_params,  model=None, scale=1, in_pix_fmt="yuv444p", out_pix_fmt="yuv444p"):
        super(gray_video_infer, self).__init__(in_path, out_path, encode_params,  model, scale, in_pix_fmt, out_pix_fmt)

    def forward(self, x):
        y = x.copy()
        y[1, :, :] = 128
        y[2, :, :] = 128
        return y

in_path = "input.mp4"
out_path = "gray.mp4"
encode_params = ("libx264", "x264opts", "qp=12:bframes=3") # 输出视频编码参数
gray = gray_video_infer(in_path, out_path, encode_params, out_pix_fmt="yuv444p")
gray.infer()
del gray

ffmpeg-inference-python's People

Contributors

yinnhao avatar

Stargazers

 avatar

Watchers

 avatar

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.