首页 > 解决方案 > 音频和视频不同步。使用 fluent-ffmpeg 串流 mp4 文件

问题描述

首先抱歉,如果问题重复。但我在其他问题中找不到正确答案。

我正在尝试使用流和 fluent-ffmpeg 连接 AWS S3 mp4 文件。我设法下载和上传连接的文件而不将其存储到磁盘。

串联似乎是正确的,但是当我选择视频播放器(VLC 媒体播放器或 QuickTime)的时间点时,时间栏似乎音频和视频不同步。

这是 nodejs fluent-ffmpeg 实现:

concatenation = (listFileName, passthroughStream) => {

    return new Promise((resolve) => {  
        let command = ffmpeg().input(listFileName)
            .inputOptions(['-f concat', '-safe 0', '-protocol_whitelist', 'file,http,tcp,https,tls'])
            //.videoCodec('libx264')
            .outputFormat('mp4')
            .outputOptions('-movflags frag_keyframe+empty_moov')
            
            var ffstream = command.on('end', function() {
                const result = 'files have been merged succesfully';
                resolve(result);
            })
            .on('error', function(err) {
                console.log('an error happened: ' + err.message);
                reject(err);
            }).pipe(passthroughStream);
            ffstream.on('data', ((chunk) => {
                console.log('ffmpeg just wrote ' + chunk.length + ' bytes');
            }));
    });        
}

我在文件中使用 S3 文件签名的 URL。像这样的东西:

file 'https://bucket.s3.region.amazonaws.com/file_0.mp4'
file 'https://bucket.s3.region.amazonaws.com/file_1.mp4'

我认为这种不同步是因为输出碎片化,如果不下载文件可能无法做到这一点,但也许有一个可能的解决方案。

有没有办法在不将文件存储到磁盘的情况下进行 mp4 连接?还是我做错了什么?

标签: amazon-s3ffmpegvideo-streamingfluent-ffmpeg

解决方案


推荐阅读