fluent-ffmpeg / node-fluent-ffmpeg

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

Conversion Error when merging video and video generated from images #824

Open mayureshmandan opened 6 years ago

mayureshmandan commented 6 years ago

Version information

Code to reproduce

Code where I'm converting Images to Video:

                    async.each(images, (imageItem, innerCb) => {
                        let videoPath = getLocalFileUrl(storyId, `image${imageItem.index}.mp4`);
                        console.log('Image: ', imageItem.uri,'Video Path: ', videoPath);
                        var imageCommand = fluentFfmpeg();
                        imageCommand
                        .input(imageItem.uri)
                        .addInputOptions(['-loop 1'])
                        .addOutputOptions(['-t '+imageItem.loop, '-pix_fmt yuv420p'])
                        .outputFPS(60)
                        .size('800x1200')
                        .autopad()
                        .on('start', (imageCommand) => {
                            console.log('ffmpeg process started:', imageCommand)
                        })
                        .on('error', (err, stdout, stderr) => {
                            console.log('Error in async.each in imageToVideo: ' + err, stdout, stderr);
                            return innerCb(err);
                        })
                        .on('end', () => {
                            console.log('Video file created succesfully');
                            localVideos.push({uri: videoPath, index: imageItem.index});
                            return innerCb();
                        })
                        .output(videoPath)
                        .run();
                    }, (err) => {
                        if(err){
                            console.log('Error in imageToVideo', err);
                        }
                        cb1(err);
                    });

Code where I'm merging videos( video generated from images and a video)

                var finalVideoCommand = fluentFfmpeg();
                async.each(localVideos, (videoItem, innerCb2) => {
                    console.log('video: ', videoItem);
                    finalVideoCommand = finalVideoCommand.addInput(videoItem.uri);
                    return innerCb2();
                }, (err) => {
                    if(err){
                        console.log('Error in async.each in mergeVideos',err);
                        return cb2(err);
                    } else {
                        finalVideoCommand
                        .outputFPS(60)
                        .on('start', (finalVideoCommand) => {
                            console.log('ffmpeg process started:', finalVideoCommand)
                        })
                        .on('error', (err, stdout, stderr) => {
                            console.log('STDERR:', stderr);
                            cb2(err);
                        })
                        .on('end', () => {
                            console.log('Video file created succesfully');
                            return defaultBucket.upload(finalVideoPath, {
                                destination: `/stories/${userId}/${storyId}/shareable.mp4`,
                                metadata: {contentType: 'video/mp4'}
                            }).then(() => {
                                return cb2();
                            })
                        })
                        .mergeToFile(finalVideoPath);
                    }
                });

(note: if the problem only happens with some inputs, include a link to such an input file)

Expected results

Videos merge perfectly when:

Merge fails when:

Observed results

START: ffmpeg -i /tmp/-LFMESGcjI67hhSnEJnp/image0.mp4 -i /tmp/-LFMESGcjI67hhSnEJnp/video1.mp4 -y -filter_complex concat=n=2:v=1:a=0 -r 60 /tmp/-LFMESGcjI67hhSnEJnp/finalVideo.mp4

ERR: Error: ffmpeg exited with code 1: Conversion failed!

STDERR: ffmpeg version N-45896-g19c3df0cd-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2018 the FFmpeg developers built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516 configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg libavutil 56. 17.100 / 56. 17.100 libavcodec 58. 19.100 / 58. 19.100 libavformat 58. 13.100 / 58. 13.100 libavdevice 58. 4.100 / 58. 4.100 libavfilter 7. 20.100 / 7. 20.100 libswscale 5. 2.100 / 5. 2.100 libswresample 3. 2.100 / 3. 2.100 libpostproc 55. 2.100 / 55. 2.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/tmp/-LFMESGcjI67hhSnEJnp/image0.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf58.13.100 Duration: 00:00:05.00, start: 0.000000, bitrate: 32 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 800x1200 [SAR 1:1 DAR 2:3], 25 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default) Metadata: handler_name : VideoHandler Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/tmp/-LFMESGcjI67hhSnEJnp/video1.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf58.13.100 Duration: 00:00:07.61, start: 0.000000, bitrate: 659 kb/s Stream #1:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 800x1200 [SAR 675:674 DAR 225:337], 720 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default) Metadata: handler_name : VideoHandler Stream #1:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 8000 Hz, mono, fltp, 28 kb/s (default) Metadata: handler_name : SoundHandler Stream mapping: Stream #0:0 (h264) -> concat:in0:v0 (graph 0) Stream #1:0 (h264) -> concat:in1:v0 (graph 0) concat (graph 0) -> Stream #0:0 (libx264) Stream #1:1 -> #0:1 (aac (native) -> aac (native)) Press [q] to stop, [?] for help [aac @ 0x4cefcc0] Too many bits 8832.000000 > 6144 per frame requested, clamping to max [Parsed_concat_0 @ 0x4dec300] Input link in1:v0 parameters (size 800x1200, SAR 675:674) do not match the corresponding output link in0:v0 parameters (800x1200, SAR 1:1) [Parsed_concat_0 @ 0x4dec300] Failed to configure output pad on Parsed_concat_0 Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #1:0 [aac @ 0x4cefcc0] Qavg: 1422.199 [aac @ 0x4cefcc0] 2 frames left in the queue on closing Conversion failed!

Checklist

mayureshmandan commented 6 years ago

Locally the function executes successfully.

Local Version Information

mayureshmandan commented 6 years ago

I'm using size('800x1200') and autopad() to make the aspect ratio of the video same as other videos( which are of correct aspect ratio 2:3 800x1200) before merging The highlight in the STDERR shared above is: Input link in1:v0 parameters (size 800x1200, SAR 675:674) do not match the corresponding output link in0:v0 parameters (800x1200, SAR 1:1)

MrPowerScripts commented 5 years ago

I'm having the same issue. Seems like you can't use videos generated from images? I wonder what the issue with those generated videos is

mannymu commented 5 years ago

好像是需要 使用不同编解码器连接文件 ,但是具体怎么做,我不太清除,希望有大神解决了, 告诉我;https://trac.ffmpeg.org/wiki/Concatenate#differentcodec

anonrig commented 5 years ago

I'm having the same exact issue:

Input link in1:v0 parameters (size 640x360, SAR 13359:13333) do not match the corresponding output link in0:v0 parameters (640x360, SAR 1:1)

Any solutions?