我正在尝试使用 ffmpeg 和 node.js 将视频转码为多种分辨率。
我可以从命令行运行此命令将视频转码为 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
我还可以使用 CPU 进行转码,使用以下代码和用于 Node.js 的 Fluent-ffmpeg 库
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) …Run Code Online (Sandbox Code Playgroud)