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

ffmpeg这部分操作可以考虑用gpu加速 #75

Open
Denghongyuan opened this issue Aug 14, 2024 · 6 comments
Open

ffmpeg这部分操作可以考虑用gpu加速 #75

Denghongyuan opened this issue Aug 14, 2024 · 6 comments

Comments

@Denghongyuan
Copy link

使用gpu加速ffmpeg可以提升好几倍的视频处理速度
未加速
image

已加速
image

@warmshao
Copy link
Owner

使用gpu加速ffmpeg可以提升好几倍的视频处理速度 未加速 image

已加速 image

赞👍欢迎提pr

@yuananf
Copy link

yuananf commented Aug 14, 2024

可以考虑使用torchaudio的StreamWriter, StreamReader,写起来更优雅一些

@Denghongyuan
Copy link
Author

可以考虑使用torchaudio的StreamWriter, StreamReader,写起来更优雅一些

作者使用ffmpeg的主要目的是把源视频的音频合并到输出视频中,torchaudio对视频的处理能力貌似不如ffmpeg

@yuananf
Copy link

yuananf commented Aug 14, 2024

可以考虑使用torchaudio的StreamWriter, StreamReader,写起来更优雅一些

作者使用ffmpeg的主要目的是把源视频的音频合并到输出视频中,torchaudio对视频的处理能力貌似不如ffmpeg

目前可以替代掉opencv写无音频的视频,合并音频可以再加上out_stream.write_audio_chunk

ffmpeg gpu合并音频我试过了,还是觉得有点慢,要几百毫秒

from torchaudio.io import StreamWriter

def write_video(out_path, video_frames, fps, h, w):
    out_stream = StreamWriter(out_path)
    cuda_conf = {
        "encoder": "h264_nvenc",  # Use CUDA HW decoder
        "encoder_format": "rgb0",
        "encoder_option": {"gpu": "0"},
        "hw_accel": "cuda:0",
        "frame_rate": fps,
        "height": h,
        "width": w,
    }
    out_stream.add_video_stream(**cuda_conf)
    with out_stream.open():
        out_stream.write_video_chunk(0, torch.vstack(video_frames))

@warmshao
Copy link
Owner

还是觉得有点慢,要几百毫秒

这个会快多少?

@yuananf
Copy link

yuananf commented Aug 19, 2024

还是觉得有点慢,要几百毫秒

这个会快多少?

单独计算写视频的时间没有快多少,但是由于结果不需要从cuda转到cpu,推理速度变化从22it/s => 26it/s

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

3 participants