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');
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)
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
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?
mediainfo tool to check the info about your mp4 file"IsStreamable": "No",.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
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
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.
Most helpful comment
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