0

pretty basic node script im using to merge 2 mp4 files together, currently have an error:

Error ffmpeg exited with code 1: Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #1:0 Conversion failed!

if i merge 2 of the same video together it works but when i use 2 different videos it throws that error!. i used the first code snippet to change the size and aspect ration but still no luck! I have spent hours on end search for this fix. how on earth do you merge 2 different videos together.

i've seen people comment that: 1. sizing is different 2. aspect is out of whack 3. you can use Unsafe = 1 ???? 4. maybe different frame rate on the files?

any help would be awesome! cheers!

var fluent_ffmpeg = require("fluent-ffmpeg");
var fs = require('fs');
var ffmpeg = require('fluent-ffmpeg');


//ATTEMPT TO RESIZE VIDEO FILES
//-------------------------------------------------------
var command = ffmpeg();
var command2 = ffmpeg();

var command = ffmpeg('./save/pokemon/name0.mp4')
  .videoCodec('libx264')
  .format('mp4');

var command2 = ffmpeg('./save/pokemon/name1.mp4')
  .videoCodec('libx264')
  .format('mp4');

command.clone()
  .size('640x?').aspect('4:3').autopad()
  .save('./save/name0.mp4')

command2.clone()
  .size('640x?').aspect('4:3').autopad()
  .save('./save/name1.mp4');
//-------------------------------------------------------

//MERGE VIDEOS TOGETHER
//-------------------------------------------------------
async function test()
{
    var mergedVideo = fluent_ffmpeg();

    var videoNames  = ['./save/name0.mp4','./save/name1.mp4']

    videoNames.forEach(function(videoName)
    {
        mergedVideo = mergedVideo.addInput(videoName);
    });

    mergedVideo.mergeToFile('./save/mergedVideo.avi', './tmp/').on('error', function(err) 
    {
        console.log('Error ' + err.message);

    }).on('end', function() 
    {
        console.log('Finished!');
    });
}
//-------------------------------------------------------
C:\gif>ffmpeg -i ./save/pokemon/name0.mp4 -i ./save/pokemon/name1.mp4
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20200122
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './save/pokemon/name0.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.26.101
  Duration: 00:00:01.14, start: 0.000000, bitrate: 1104 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 480x334 [SAR 1:1 DAR 240:167], 1098 kb/s, 33.33 fps, 33.33 tbr, 333333 tbn, 66.67 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from './save/pokemon/name1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.26.101
    comment         : PhotoScape
  Duration: 00:00:01.80, start: 0.000000, bitrate: 1157 kb/s
    Stream #1:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 480x358 [SAR 1:1 DAR 240:179], 1153 kb/s, 6.67 fps, 6.67 tbr, 666667 tbn, 13.33 tbc (default)
    Metadata:
      handler_name    : VideoHandler
At least one output file must be specified
Getwrong
  • 177
  • 1
  • 2
  • 13
  • Immediately above the line `Error reinitializing filters!` should be another error message that may explain the actual problem. The attributes of your files probably don't match, but they need to for proper merging. In command line run `ffmpeg -i /save/pokemon/name0.mp4 -i /save/pokemon/name1.mp4` and then [edit] your question to include the complete log. – llogan Mar 29 '20 at 02:28
  • thanks man ill give that a go. also how do you see the full error message. – Getwrong Mar 29 '20 at 02:32
  • also i ran that line of code and it says at least one output file must be specified. how do you output to file – Getwrong Mar 29 '20 at 02:36
  • That command is only to show info of each input to see how they are different. You can ignore the "at least one output file must be specified" message. I'm not sure how to see the full error message in fluent-ffmpeg. – llogan Mar 29 '20 at 02:46
  • i updated the post, and display the message i got from the cmd input this did not work, it merged name0.mp4 together instead – Getwrong Mar 29 '20 at 02:49
  • 1
    Unfortunately these look like the files from `/save/name0.mp4` and not the originals from `/save/pokemon/`. Outputting files just to resize them is suboptimal because in your case you're getting generation loss. There are better methods. Anyway, your files vary in SAR and frame rate, but the SAR difference is causing the fatal error: most likely being `Input link in1:v0 parameters (size 640x480, SAR 211:212) do not match the corresponding output link in0:v0 parameters (640x480, SAR 333:334)`. Either add setsar filter or scale to specific size while preserving aspect w/ pad or crop. – llogan Mar 29 '20 at 03:05
  • okay, really appreciate the help. ill change the code so i dont resize it and add setsar. how do i go about incorporating setsar in my code. sorry im new with ffmpeg or scaling to specific size? – Getwrong Mar 29 '20 at 03:09
  • You basically have the [same issue as all of these duplicate questions](https://stackoverflow.com/search?q=%5Bffmpeg%5D+%22do+not+match+the+corresponding+output+link%22+concat), but with the added complication of the fluent/javascript/node.js wrappers. Unfortunately I know nothing of fluent: I only know how to use the `ffmpeg` command-line tool directly. – llogan Mar 29 '20 at 03:12
  • Alright man, thankyou so much for your help. hopefully with your information i can figure something out! appreciate it – Getwrong Mar 29 '20 at 03:14
  • Show the output of `ffmpeg -i /save/pokemon/name0.mp4 -i /save/pokemon/name1.mp4` and I can at least show you how to do it in normal `ffmpeg`. – llogan Mar 29 '20 at 03:15
  • i updated the code with what you wanted @llogan – Getwrong Mar 29 '20 at 03:17
  • it shows the SAR is the same now – Getwrong Mar 29 '20 at 03:19
  • when i compile it through cmd with an output file it works but it only create an output mp4 with the first mp4 file in it not the second one :s. when i use my js script i still get error and and a corrupt output file als found this: – Getwrong Mar 29 '20 at 03:24
  • at ChildProcess. (C:\gif\node_modules\fluent-ffmpeg\lib\processor.js:182:22) at ChildProcess.emit (events.js:210:5) at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12) – Getwrong Mar 29 '20 at 03:27

0 Answers0