fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.79k stars 873 forks source link

Audio and video out of sync. Stream mp4 files Concatenation #1112

Open JoBaAl opened 3 years ago

JoBaAl commented 3 years ago

First of all sorry if the question is duplicated. But I couldn't find out the right answer to other questions.

I'm trying to concatenate AWS S3 mp4 files using streams and fluent-ffmpeg. I managed to download and upload the concatenated files without storing them on the disk.

The concatenation seems correct but when I'm selecting a point in time of the video player (VLC media player or QuickTime) time bar seems the audio and video are out of sync.

This is the nodejs fluent-ffmpeg implementation:

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');
            }));
    });        
}

I'm using S3 file signed URLs in the file. The listFileName parameter is the path to a .txt file as follows:

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

I think that this out of sync is because of the fragmented output and maybe is not possible to do that without downloading the files, but maybe there's a possible solution.

Is there some way to do the mp4 concatenation without storing the files to the disk? Or am I doing something wrong?

coschmit commented 2 years ago

Hi man ! Did you find a solution about this problem ? I'm actually stuck... :(

JoBaAl commented 2 years ago

No 😞 . To avoid video/ audio sync issues using streams we had to download the files before contacting.

If you find any solution let me know. 😄