bmf icon indicating copy to clipboard operation
bmf copied to clipboard

cpp copy module can't work with gpu transcoding

Open Jie-Fang opened this issue 1 year ago • 2 comments

Module: test/c_module

def test():
    input_video_path = xxx
    output_path = xxxx
    video = bmf.graph().decode({
            "input_path": input_video_path,
            "video_params": {
                "hwaccel": "cuda",
            }
        })["video"]

    video2 = video.c_module('cpp_copy_module',
                            "../../test/c_module/libcopy_module.so", # use your path
                            "copy_module:CopyModule")
        
    (bmf.encode(
        video2,
        video["audio"],
        {
            "output_path": output_path,
            "video_params": {
                "codec": "h264_nvenc",
                "pix_fmt": "cuda",
            }
        }).run())

The output video isn't encoded normally. There're green and red area in the pictures.

But with CPU decoding and GPU encoding, the results are good.

def test():
    input_video_path = xxx
    output_path = xxxx
    video = bmf.graph().decode({
            "input_path": input_video_path,
        })["video"]

    video2 = video.c_module('cpp_copy_module',
                            "../../test/c_module/libcopy_module.so", # use your path
                            "copy_module:CopyModule")
        
    (bmf.encode(
        video2,
        video["audio"],
        {
            "output_path": output_path,
            "video_params": {
                "codec": "h264_nvenc",
            }
        }).run())

Jie-Fang avatar Sep 05 '23 13:09 Jie-Fang

I found this issue when I tried to write a cpp module where the decoded NV12 frames will be converted to RGB, then the RGB frames are converted to NV12 again. The output video is similar as the results I describe above. So, I suspect there're some issues in the c_modules cooperating with gpu decoding.

Jie-Fang avatar Sep 05 '23 13:09 Jie-Fang

"tried to write a cpp module where the decoded NV12 frames will be converted to RGB, then the RGB frames are converted to NV12 again", so if you don't use this module but just copy_module, the issue still exist?

sfeiwong avatar Sep 06 '23 03:09 sfeiwong