fluent-ffmpeg无法获得一致的音频比特率

时间:2020-09-20 21:11:41

标签: javascript video ffmpeg electron fluent-ffmpeg

我正在开发一个电子应用程序,该应用程序运行ffmpeg命令以将音频文件+图像文件组合为视频文件。我使用的是我写的fluent-ffmpeg命令,该命令有效,但是即使我在命令中指定了320kbps,输出的视频文件也始终具有较低的音频比特率。

我已经使用下面记录的mp3 / flac / wav文件运行了多个测试;使用我的fluent-ffmpeg命令,如下所示:

ffmpeg()
            .input(imgPath)
            .loop()
            .addInputOption('-framerate 2')
            .input(audioPath)
            .videoCodec('libx264')
            .audioCodec('aac')
            //.audioCodec('copy')
            .audioBitrate('320k')
            .videoBitrate('8000k', true)
            .size('1920x1080')
            .outputOptions([
                '-preset medium',
                '-tune stillimage',
                '-crf 18',
                '-b:a 320k',
                '-pix_fmt yuv420p',
                '-shortest'
            ])

            .on('progress', function (progress) {
                document.getElementById(updateInfoLocation).innerText = `Generating Video: ${Math.round(progress.percent)}%`
                console.info(`vid() Processing : ${progress.percent} % done`);
            })
            .on('codecData', function (data) {
                console.log('vid() codecData=', data);
            })
            .on('end', function () {
                document.getElementById(updateInfoLocation).innerText = `Video generated.`
                console.log('vid()  file has been converted succesfully; resolve() promise');
                resolve();
            })
            .on('error', function (err) {
                document.getElementById(updateInfoLocation).innerText = `Error generating video.`
                console.log('vid() an error happened: ' + err.message, ', reject()');
                reject(err);
            })
            .output(vidOutput).run()

1)320bkps mp3文件

  • imgPath = C:\ Users \ marti \ Documents \ projects \ mp3 audio \ img.jpg
  • audioPath = C:\ Users \ marti \ Documents \ projects \ mp3 audio \ 08。奇怪-Gigi D'Agostino.mp3
  • vidOutput = C:\ Users \ marti \ Documents \ projects \ mp3音频\ 08。奇怪-Gigi D'Agostino.mp4

我的音频文件的比特率为320kbps: enter image description here

如果我将上述ffmpeg函数与.audioCodec('aac')一起使用,则输出视频文件的音频比特率为 300kbps 。如果我改用.audioCodec('copy'),则我的输出视频文件的音频比特率为 317kbps

2)1411kbps wav文件

  • audioPath = C:\ Users \ marti \ Documents \ projects \ wav audio \ 01 Nem Kaldi.wav
  • imgPath = C:\ Users \ marti \ Documents \ projects \ wav audio \ cover.jpg
  • vidOutput = C:\ Users \ marti \ Documents \ projects \ wav audio \ 01 Nem Kaldi.mp4

我的wav文件的音频比特率为1411kbps; enter image description here 当我使用.audioCodec('aac')运行ffmpeg命令时,我的输出视频文件再次仅为 303kbps enter image description here

3)937kbps flac文件

  • audioPath = C:\ Users \ marti \ Documents \ projects \ flac audio \ 02-ryokika.flac
  • imgPath = C:\ Users \ marti \ Documents \ projects \ flac audio \ R-1042328-1388635895-5022.jpeg.jpg
  • vidOutput = C:\ Users \ marti \ Documents \ projects \ flac audio \ 02-ryokika.mp4

当我使用.audioCodec('aac')运行ffmpeg命令时,输出的视频文件仅为 304kbps

是否需要添加任何命令或其他标志以确保输出的视频文件具有高质量的音频比特率?

0 个答案:

没有答案