简体   繁体   中英

Is there a way to use NVDEC and NVENC using fluent-ffmpeg?

I am trying to transcode videos to multiple resolutions using ffmpeg and node.js.

I can run this from the commandline to transcode a video to 720p: ffmpeg -vsync 0 -hwaccel cuvid -hwaccel_device 0 -c:v h264_cuvid -i input.mp4 -vf scale_npp=-1:720 -c:a copy -c:v h264_nvenc -b:v 5M output2.mp4

I am also able to transcode using the cpu using the following code with the fluent-ffmpeg library for node.js

function transcodeToRes(path, shortSide, bitrate, videoID, portrait) {
    return new Promise((res, rej) => {
        let resolution = portrait ? "?x" + shortSide : shortSide + "x?";
        let localSavePath = savePath + videoID + "/" + shortSide + ".mp4";

        ffmpeg()
            .input(path)
            .native()
            .audioCodec('aac')
            .audioBitrate(128)
            .audioChannels(2)
            .videoCodec('libx264')
            .videoBitrate(bitrate)
            .size(resolution)
            .keepDAR()
            .save(localSavePath)
            .on('error', (err) => {
                rej(err);
            })
            .on('end', () => {
                res();
            });
    })
}```

I figured it out, here is the new code that works if anyone else is having the same issue

ffmpeg()
        .input("/home/yom/test/Kent_4K_Landscape.mp4")
        .inputOption([
            "-vsync 0",
            "-hwaccel cuvid",
            "-hwaccel_device 0",
            "-c:v h264_cuvid"
        ])
        .videoCodec("h264_nvenc")
        .videoFilter("scale_npp=-1:720")
        .native()
        .audioCodec('aac')
        .audioBitrate(128)
        .audioChannels(2)
        .videoBitrate(5000)
        .save("/home/yom/test/out.mp4")
        .on('error', (err) => {
            console.log(err)
        })
        .on('end', () => {
            console.log("done")
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM