Node-fluent-ffmpeg: got ffmpeg exited with code 1 with special mp4 file while using readstream as input

Created on 14 Jun 2018  路  7Comments  路  Source: fluent-ffmpeg/node-fluent-ffmpeg

Version information

  • fluent-ffmpeg version: 2.1.2
  • ffmpeg version:
    ffmpeg version N-91282-gc5e6c0b5f6 Copyright (c) 2000-2018 the FFmpeg developers
    built with gcc 7.3.0 (GCC)
    configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --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
    libavutil 56. 18.102 / 56. 18.102
    libavcodec 58. 20.101 / 58. 20.101
    libavformat 58. 17.100 / 58. 17.100
    libavdevice 58. 4.101 / 58. 4.101
    libavfilter 7. 25.100 / 7. 25.100
    libswscale 5. 2.100 / 5. 2.100
    libswresample 3. 2.100 / 3. 2.100
    libpostproc 55. 2.100 / 55. 2.100
  • OS: windows 10 17134

    Code to reproduce

code 1

const fs = require("fs");
ffmpeg = require('fluent-ffmpeg');
let file = '../testFileResource/t.mp4';
let infs = fs.createReadStream(file);
let proc = ffmpeg(infs)
    .on('error', function (err) {
        console.log('an error happened: ' + err.message);
    })
    .save('f.mp4');

code 2

const fs = require("fs");
ffmpeg = require('fluent-ffmpeg');
let file = '../testFileResource/t.mp4';
let infs = fs.createReadStream(file);
let proc = ffmpeg(file)
    .on('error', function (err) {
        console.log('an error happened: ' + err.message);
    })
    .save('f.mp4');

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

Expected results

code 2 work very well
but with code 1 I got the follow result

an error happened: ffmpeg exited with code 1: pipe:0: Invalid data found when processing input
Cannot determine format of input stream 0:1 after EOF
Error marking filters as finished
Conversion failed!

now i have no idea why it happens like that

Most helpful comment

oh, i forgot to attach some link for reference

what-is-the-difference-between-these-2-videos
post-processing-in-ffmpeg-to-move-moov-atom-in-mp4-files-qt-faststar
mov_002c-mp4_002c-ismv

i made a mistake with the code in step 3:
it should use outputOptions("-movflags faststart"),
but this option just work well with file url input, if you pass a stream to input, it's no useful

All 7 comments

I have tested other files and it works very well.
only this special mp4 file goes wrong
this is the special mp4 file metadata

{ streams: 
   [ { index: 0,
       codec_name: 'aac',
       codec_long_name: 'AAC (Advanced Audio Coding)',
       profile: 'LC',
       codec_type: 'audio',
       codec_time_base: '1/48000',
       codec_tag_string: 'mp4a',
       codec_tag: '0x6134706d',
       sample_fmt: 'fltp',
       sample_rate: 48000,
       channels: 2,
       channel_layout: 'stereo',
       bits_per_sample: 0,
       id: 'N/A',
       r_frame_rate: '0/0',
       avg_frame_rate: '0/0',
       time_base: '1/48000',
       start_pts: 0,
       start_time: 0,
       duration_ts: 257227776,
       duration: 5358.912,
       bit_rate: 105600,
       max_bit_rate: 135296,
       bits_per_raw_sample: 'N/A',
       nb_frames: 251199,
       nb_read_frames: 'N/A',
       nb_read_packets: 'N/A',
       tags: { language: 'eng', handler_name: 'SoundHandler' },
       disposition: 
        { default: 1,
          dub: 0,
          original: 0,
          comment: 0,
          lyrics: 0,
          karaoke: 0,
          forced: 0,
          hearing_impaired: 0,
          visual_impaired: 0,
          clean_effects: 0,
          attached_pic: 0,
          timed_thumbnails: 0 } },
     { index: 1,
       codec_name: 'h264',
       codec_long_name: 'H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10',
       profile: 'Constrained Baseline',
       codec_type: 'video',
       codec_time_base: '125/5994',
       codec_tag_string: 'avc1',
       codec_tag: '0x31637661',
       width: 1920,
       height: 1026,
       coded_width: 1920,
       coded_height: 1040,
       has_b_frames: 0,
       sample_aspect_ratio: 'N/A',
       display_aspect_ratio: 'N/A',
       pix_fmt: 'yuv420p',
       level: 30,
       color_range: 'unknown',
       color_space: 'unknown',
       color_transfer: 'unknown',
       color_primaries: 'unknown',
       chroma_location: 'left',
       field_order: 'unknown',
       timecode: 'N/A',
       refs: 1,
       is_avc: 'true',
       nal_length_size: 4,
       id: 'N/A',
       r_frame_rate: '2997/125',
       avg_frame_rate: '2997/125',
       time_base: '1/2997',
       start_pts: 0,
       start_time: 0,
       duration_ts: 16055000,
       duration: 5357.02369,
       bit_rate: 4866192,
       max_bit_rate: 'N/A',
       bits_per_raw_sample: 8,
       nb_frames: 128440,
       nb_read_frames: 'N/A',
       nb_read_packets: 'N/A',
       tags: { language: 'und', handler_name: 'VideoHandler' },
       disposition: 
        { default: 1,
          dub: 0,
          original: 0,
          comment: 0,
          lyrics: 0,
          karaoke: 0,
          forced: 0,
          hearing_impaired: 0,
          visual_impaired: 0,
          clean_effects: 0,
          attached_pic: 0,
          timed_thumbnails: 0 } },
     { index: 2,
       codec_name: 'mjpeg',
       codec_long_name: 'Motion JPEG',
       profile: 192,
       codec_type: 'video',
       codec_time_base: '0/1',
       codec_tag_string: '[0][0][0][0]',
       codec_tag: '0x0000',
       width: 667,
       height: 1000,
       coded_width: 667,
       coded_height: 1000,
       has_b_frames: 0,
       sample_aspect_ratio: '1:1',
       display_aspect_ratio: '667:1000',
       pix_fmt: 'yuvj444p',
       level: '-99',
       color_range: 'pc',
       color_space: 'bt470bg',
       color_transfer: 'unknown',
       color_primaries: 'unknown',
       chroma_location: 'center',
       field_order: 'unknown',
       timecode: 'N/A',
       refs: 1,
       id: 'N/A',
       r_frame_rate: '90000/1',
       avg_frame_rate: '0/0',
       time_base: '1/90000',
       start_pts: 0,
       start_time: 0,
       duration_ts: 482302080,
       duration: 5358.912,
       bit_rate: 'N/A',
       max_bit_rate: 'N/A',
       bits_per_raw_sample: 8,
       nb_frames: 'N/A',
       nb_read_frames: 'N/A',
       nb_read_packets: 'N/A',
       disposition: 
        { default: 0,
          dub: 0,
          original: 0,
          comment: 0,
          lyrics: 0,
          karaoke: 0,
          forced: 0,
          hearing_impaired: 0,
          visual_impaired: 0,
          clean_effects: 0,
          attached_pic: 1,
          timed_thumbnails: 0 } },
     { index: 3,
       codec_name: 'bin_data',
       codec_long_name: 'binary data',
       profile: 'unknown',
       codec_type: 'data',
       codec_tag_string: 'text',
       codec_tag: '0x74786574',
       id: 'N/A',
       r_frame_rate: '0/0',
       avg_frame_rate: '0/0',
       time_base: '1/1000',
       start_pts: 0,
       start_time: 0,
       duration_ts: 5358912,
       duration: 5358.912,
       bit_rate: 'N/A',
       max_bit_rate: 'N/A',
       bits_per_raw_sample: 'N/A',
       nb_frames: 20,
       nb_read_frames: 'N/A',
       nb_read_packets: 'N/A',
       tags: 
        { creation_time: '2014-10-06T11:02:51.000000Z',
          language: 'und' },
       disposition: 
        { default: 0,
          dub: 0,
          original: 0,
          comment: 0,
          lyrics: 0,
          karaoke: 0,
          forced: 0,
          hearing_impaired: 0,
          visual_impaired: 0,
          clean_effects: 0,
          attached_pic: 0,
          timed_thumbnails: 0 } } ],
  format: 
   { filename: '../testFileResource/t.mp4',
     nb_streams: 4,
     nb_programs: 0,
     format_name: 'mov,mp4,m4a,3gp,3g2,mj2',
     format_long_name: 'QuickTime / MOV',
     start_time: 0,
     duration: 5358.912,
     size: 3332627745,
     bit_rate: 4975081,
     probe_score: 100,
     '<plist version': '"1.0">',
     tags: 
      { major_brand: 'isom',
        minor_version: '512',
        compatible_brands: 'isomiso2avc1mp41',
        iTunEXTC: 'mpaa|R|400|',
        iTunMOVI: '<?xml version="1.0" encoding="UTF-8"?>',
        title: 'Let\'s Go to Prison',
        artist: 'Bob Odenkirk',
        genre: 'Comedy',
        date: '2006',
        compilation: '0',
        description: 'Welcome to the slammer in this no-holds-barred, outrageous comedy! When white-collar Nelson Biederman IV (Will Arnett) winds up in the state pen with mischievous cellmate John Lyshitski (Dax Shepard), all hell breaks loose. From toilet wine to big-house b',
        synopsis: 'Welcome to the slammer in this no-holds-barred, outrageous comedy! When white-collar Nelson Biederman IV (Will Arnett) winds up in the state pen with mischievous cellmate John Lyshitski (Dax Shepard), all hell breaks loose. From toilet wine to big-house beatdowns, it\'s a side-splitting comedy that could only happen in the clink!',
        hd_video: '2',
        media_type: '9' } },
  chapters: [] }

it seems like that i did something wrong , and I'm new at FFMPEG , can you give me some tips of this?

Did you manage to solve this somehow? @Esimorp

Hi, this problem is caused by moov atom metadata is on the end of the mp4 file,
so if you want get stream of it, you should move the moov atom to the head of the file.

how to solve it?

  1. check the file is Streamable?
    use mediainfo tool to check the info about your mp4 file
    you may see"IsStreamable": "No",.
  1. use ffmpeg tool to convert the unstreamable file to a streamable file
    ffmpeg -i no_streamable.mp4 -movflags faststart -f mp4 -y streamable.mp4
    then you can you the converted file, this time will not throw ffmpeg exited with code 1: pipe:0: Invalid data found when processing input

  2. can I use the options movflags in fluent-ffmpeg?
    Unfortunately, you can't, there exists some bugs for it

let inputStream = fs.createReadStream("no_streamable.mp4")
ffmpeg(inputStream)
    .inputOptions("-movflags faststart")
    .output("streamable.mp4")
    .format("mp4")
    .on("start", (cmd)=>{
        console.log("--- ffmpeg start process ---")
        console.log(`cmd: ${cmd}`)
    })
    .on("end",()=>{
        console.log("--- end processing ---")
    })
    .on("error", (err)=>{
        console.log("--- ffmpeg meets error ---")
        console.log(err)
    })
    .run()

you will get a error: ffmpeg exited with code 1: Option movflags not found.

because the generate cmd is like that: ffmpeg -movflags faststart -i pipe:0 -y -f mp4 streamable.mp4
you can try step2 cmd like this, it will throw the same error, it seems that the ffmpeg can't understand the cmd format.
ffmpeg -movflags faststart -i no_streamable.mp4 -f mp4 -y streamable.mp4
i don't know how to fix it too~ sadly

@Esimorp
@stajics

oh, i forgot to attach some link for reference

what-is-the-difference-between-these-2-videos
post-processing-in-ffmpeg-to-move-moov-atom-in-mp4-files-qt-faststar
mov_002c-mp4_002c-ismv

i made a mistake with the code in step 3:
it should use outputOptions("-movflags faststart"),
but this option just work well with file url input, if you pass a stream to input, it's no useful

@llcat Hi, thank you for solutions. Is the bug fixed? I still get them in 2021, it is two years later. Is it possible to get isStreamable using ffprobe instead of mediainfo?

@MichaelMikeJones I think that this issue is not solvable whether video has information written at the end of the stream.
It could be interesting trying to read stream from the end, but I don't know if it is doable without downloading the whole file.

The only fix is to download the whole file and process a file instead of a stream or to ensure you work with files having the headers `-movflags faststart' set.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

judemorrissey picture judemorrissey  路  5Comments

TomKaltz picture TomKaltz  路  5Comments

345ml picture 345ml  路  6Comments

echo66 picture echo66  路  3Comments

joergbirkhold picture joergbirkhold  路  5Comments