fluent-ffmpeg extract audio using streaming
I'm trying to extract audio from video. This code works well:
ffmpeg('1.mp4').output('1.mp3')
.noVideo()
.format('mp3')
.outputOptions('-ab','192k')
.run();
But if I read the file with a stream like this:
var video = fs.createReadStream('1.mp4');
var audio = fs.createWriteStream('1.mp3');
ffmpeg(video).output(audio)
.noVideo()
.format('mp3')
.outputOptions('-ab','192k')
.run();
The output file weighs 1KB and does not have anything in it.
How can I extract audio using streams?
node.js ffmpeg streaming fluent-ffmpeg
|
show 3 more comments
I'm trying to extract audio from video. This code works well:
ffmpeg('1.mp4').output('1.mp3')
.noVideo()
.format('mp3')
.outputOptions('-ab','192k')
.run();
But if I read the file with a stream like this:
var video = fs.createReadStream('1.mp4');
var audio = fs.createWriteStream('1.mp3');
ffmpeg(video).output(audio)
.noVideo()
.format('mp3')
.outputOptions('-ab','192k')
.run();
The output file weighs 1KB and does not have anything in it.
How can I extract audio using streams?
node.js ffmpeg streaming fluent-ffmpeg
Is the Readstream seekable? If not, ffmpeg can't read the MP4.
– Gyan
Dec 25 '18 at 5:49
1
FFmpeg needs to be able to go back and forth in the MP4. If thefs
method doesn't support that, ffmpeg will not be able to parse the input.
– Gyan
Dec 27 '18 at 4:23
2
Althoiugh you may be able to work around if your MP4 has MOOV box at the front..
– Gyan
Dec 27 '18 at 5:05
1
@ABE, I had no problems running the code above. For my mp4 sample, I used the following file: github.com/mediaelement/mediaelement-files/blob/master/… Can you verify this?
– r0hitsharma
Dec 28 '18 at 19:14
1
@r0hitsharma Yes, it works fine. Why does it only work in your file?
– ABE
Dec 29 '18 at 22:09
|
show 3 more comments
I'm trying to extract audio from video. This code works well:
ffmpeg('1.mp4').output('1.mp3')
.noVideo()
.format('mp3')
.outputOptions('-ab','192k')
.run();
But if I read the file with a stream like this:
var video = fs.createReadStream('1.mp4');
var audio = fs.createWriteStream('1.mp3');
ffmpeg(video).output(audio)
.noVideo()
.format('mp3')
.outputOptions('-ab','192k')
.run();
The output file weighs 1KB and does not have anything in it.
How can I extract audio using streams?
node.js ffmpeg streaming fluent-ffmpeg
I'm trying to extract audio from video. This code works well:
ffmpeg('1.mp4').output('1.mp3')
.noVideo()
.format('mp3')
.outputOptions('-ab','192k')
.run();
But if I read the file with a stream like this:
var video = fs.createReadStream('1.mp4');
var audio = fs.createWriteStream('1.mp3');
ffmpeg(video).output(audio)
.noVideo()
.format('mp3')
.outputOptions('-ab','192k')
.run();
The output file weighs 1KB and does not have anything in it.
How can I extract audio using streams?
node.js ffmpeg streaming fluent-ffmpeg
node.js ffmpeg streaming fluent-ffmpeg
edited Dec 25 '18 at 10:57
TGrif
3,26181836
3,26181836
asked Dec 24 '18 at 21:45
ABEABE
307214
307214
Is the Readstream seekable? If not, ffmpeg can't read the MP4.
– Gyan
Dec 25 '18 at 5:49
1
FFmpeg needs to be able to go back and forth in the MP4. If thefs
method doesn't support that, ffmpeg will not be able to parse the input.
– Gyan
Dec 27 '18 at 4:23
2
Althoiugh you may be able to work around if your MP4 has MOOV box at the front..
– Gyan
Dec 27 '18 at 5:05
1
@ABE, I had no problems running the code above. For my mp4 sample, I used the following file: github.com/mediaelement/mediaelement-files/blob/master/… Can you verify this?
– r0hitsharma
Dec 28 '18 at 19:14
1
@r0hitsharma Yes, it works fine. Why does it only work in your file?
– ABE
Dec 29 '18 at 22:09
|
show 3 more comments
Is the Readstream seekable? If not, ffmpeg can't read the MP4.
– Gyan
Dec 25 '18 at 5:49
1
FFmpeg needs to be able to go back and forth in the MP4. If thefs
method doesn't support that, ffmpeg will not be able to parse the input.
– Gyan
Dec 27 '18 at 4:23
2
Althoiugh you may be able to work around if your MP4 has MOOV box at the front..
– Gyan
Dec 27 '18 at 5:05
1
@ABE, I had no problems running the code above. For my mp4 sample, I used the following file: github.com/mediaelement/mediaelement-files/blob/master/… Can you verify this?
– r0hitsharma
Dec 28 '18 at 19:14
1
@r0hitsharma Yes, it works fine. Why does it only work in your file?
– ABE
Dec 29 '18 at 22:09
Is the Readstream seekable? If not, ffmpeg can't read the MP4.
– Gyan
Dec 25 '18 at 5:49
Is the Readstream seekable? If not, ffmpeg can't read the MP4.
– Gyan
Dec 25 '18 at 5:49
1
1
FFmpeg needs to be able to go back and forth in the MP4. If the
fs
method doesn't support that, ffmpeg will not be able to parse the input.– Gyan
Dec 27 '18 at 4:23
FFmpeg needs to be able to go back and forth in the MP4. If the
fs
method doesn't support that, ffmpeg will not be able to parse the input.– Gyan
Dec 27 '18 at 4:23
2
2
Althoiugh you may be able to work around if your MP4 has MOOV box at the front..
– Gyan
Dec 27 '18 at 5:05
Althoiugh you may be able to work around if your MP4 has MOOV box at the front..
– Gyan
Dec 27 '18 at 5:05
1
1
@ABE, I had no problems running the code above. For my mp4 sample, I used the following file: github.com/mediaelement/mediaelement-files/blob/master/… Can you verify this?
– r0hitsharma
Dec 28 '18 at 19:14
@ABE, I had no problems running the code above. For my mp4 sample, I used the following file: github.com/mediaelement/mediaelement-files/blob/master/… Can you verify this?
– r0hitsharma
Dec 28 '18 at 19:14
1
1
@r0hitsharma Yes, it works fine. Why does it only work in your file?
– ABE
Dec 29 '18 at 22:09
@r0hitsharma Yes, it works fine. Why does it only work in your file?
– ABE
Dec 29 '18 at 22:09
|
show 3 more comments
2 Answers
2
active
oldest
votes
For further investigation, I added a callback for different sort of errors while transcoding, as well as other events. First hint was the following callback on progress
event:
{ frames: NaN,
currentFps: NaN,
currentKbps: NaN,
targetSize: 0,
timemark: '00:00:00.00' }
As well, there was a stderr
event:
ffmpeg version n4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20180831
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] stream 0, offset 0x30: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 240x180, 374 kb/s): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:0':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf54.63.104
Duration: 00:00:14.72, start: 0.000000, bitrate: N/A
Stream #0:0(und): Video: h264 (avc1 / 0x31637661), none, 240x180, 374 kb/s, 25 fps, 25 tbr, 12800 tbn, 25600 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 75 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:1 -> #0:0 (aac (native) -> mp3 (libmp3lame))
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] stream 1, offset 0xa1e: partial file
pipe:0: Invalid data found when processing input
Output #0, mp3, to 'pipe:1':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
TSSE : Lavf58.20.100
Stream #0:0(und): Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp, 192 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc58.35.100 libmp3lame
size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
{ frames: NaN,
currentFps: NaN,
currentKbps: NaN,
targetSize: 0,
timemark: '00:00:00.00' }
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
The latter explains the empty file you're seeing in the output. As to why the error only happens while streaming the file, and not while opening it through another method, this answer explains the details: https://stackoverflow.com/a/40028894/1494833
Unfortunately the library doesn't yet support movflags
input option as recommended above (https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/issues/823).
add a comment |
Assuming that you are using the ffmpeg package which is basically a wrapper for running ffmpeg in node, you would have to do it somewhat like this:
This code works on my system using the same file you provided in the comments above but you may have to make some changes (Node v8.12.0, ffmpeg v0.0.4).
const ffmpeg = require('ffmpeg');
try {
let process = new ffmpeg('3.mp4');
process.then(function (video) {
// Callback mode
video.fnExtractSoundToMP3('3.mp3', function (error, file) {
if (!error)
console.log('Audio file: ' + file);
});
}, function (err) {
console.log('Error: ' + err);
});
} catch (e) {
console.log(e.code);
console.log(e.msg);
}
1
Thanks for your response, but I probably did not understand, there's no problem extracting the audio, the problem is to use streams, your code will not work if you write this way: let process = new ffmpeg(fs.createReadStream('3.mp4')); video.fnExtractSoundToMP3(fs.createWriteStream('3.mp3')
– ABE
Jan 2 at 17:28
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53917893%2ffluent-ffmpeg-extract-audio-using-streaming%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
For further investigation, I added a callback for different sort of errors while transcoding, as well as other events. First hint was the following callback on progress
event:
{ frames: NaN,
currentFps: NaN,
currentKbps: NaN,
targetSize: 0,
timemark: '00:00:00.00' }
As well, there was a stderr
event:
ffmpeg version n4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20180831
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] stream 0, offset 0x30: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 240x180, 374 kb/s): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:0':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf54.63.104
Duration: 00:00:14.72, start: 0.000000, bitrate: N/A
Stream #0:0(und): Video: h264 (avc1 / 0x31637661), none, 240x180, 374 kb/s, 25 fps, 25 tbr, 12800 tbn, 25600 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 75 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:1 -> #0:0 (aac (native) -> mp3 (libmp3lame))
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] stream 1, offset 0xa1e: partial file
pipe:0: Invalid data found when processing input
Output #0, mp3, to 'pipe:1':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
TSSE : Lavf58.20.100
Stream #0:0(und): Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp, 192 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc58.35.100 libmp3lame
size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
{ frames: NaN,
currentFps: NaN,
currentKbps: NaN,
targetSize: 0,
timemark: '00:00:00.00' }
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
The latter explains the empty file you're seeing in the output. As to why the error only happens while streaming the file, and not while opening it through another method, this answer explains the details: https://stackoverflow.com/a/40028894/1494833
Unfortunately the library doesn't yet support movflags
input option as recommended above (https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/issues/823).
add a comment |
For further investigation, I added a callback for different sort of errors while transcoding, as well as other events. First hint was the following callback on progress
event:
{ frames: NaN,
currentFps: NaN,
currentKbps: NaN,
targetSize: 0,
timemark: '00:00:00.00' }
As well, there was a stderr
event:
ffmpeg version n4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20180831
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] stream 0, offset 0x30: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 240x180, 374 kb/s): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:0':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf54.63.104
Duration: 00:00:14.72, start: 0.000000, bitrate: N/A
Stream #0:0(und): Video: h264 (avc1 / 0x31637661), none, 240x180, 374 kb/s, 25 fps, 25 tbr, 12800 tbn, 25600 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 75 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:1 -> #0:0 (aac (native) -> mp3 (libmp3lame))
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] stream 1, offset 0xa1e: partial file
pipe:0: Invalid data found when processing input
Output #0, mp3, to 'pipe:1':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
TSSE : Lavf58.20.100
Stream #0:0(und): Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp, 192 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc58.35.100 libmp3lame
size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
{ frames: NaN,
currentFps: NaN,
currentKbps: NaN,
targetSize: 0,
timemark: '00:00:00.00' }
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
The latter explains the empty file you're seeing in the output. As to why the error only happens while streaming the file, and not while opening it through another method, this answer explains the details: https://stackoverflow.com/a/40028894/1494833
Unfortunately the library doesn't yet support movflags
input option as recommended above (https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/issues/823).
add a comment |
For further investigation, I added a callback for different sort of errors while transcoding, as well as other events. First hint was the following callback on progress
event:
{ frames: NaN,
currentFps: NaN,
currentKbps: NaN,
targetSize: 0,
timemark: '00:00:00.00' }
As well, there was a stderr
event:
ffmpeg version n4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20180831
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] stream 0, offset 0x30: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 240x180, 374 kb/s): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:0':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf54.63.104
Duration: 00:00:14.72, start: 0.000000, bitrate: N/A
Stream #0:0(und): Video: h264 (avc1 / 0x31637661), none, 240x180, 374 kb/s, 25 fps, 25 tbr, 12800 tbn, 25600 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 75 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:1 -> #0:0 (aac (native) -> mp3 (libmp3lame))
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] stream 1, offset 0xa1e: partial file
pipe:0: Invalid data found when processing input
Output #0, mp3, to 'pipe:1':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
TSSE : Lavf58.20.100
Stream #0:0(und): Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp, 192 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc58.35.100 libmp3lame
size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
{ frames: NaN,
currentFps: NaN,
currentKbps: NaN,
targetSize: 0,
timemark: '00:00:00.00' }
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
The latter explains the empty file you're seeing in the output. As to why the error only happens while streaming the file, and not while opening it through another method, this answer explains the details: https://stackoverflow.com/a/40028894/1494833
Unfortunately the library doesn't yet support movflags
input option as recommended above (https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/issues/823).
For further investigation, I added a callback for different sort of errors while transcoding, as well as other events. First hint was the following callback on progress
event:
{ frames: NaN,
currentFps: NaN,
currentKbps: NaN,
targetSize: 0,
timemark: '00:00:00.00' }
As well, there was a stderr
event:
ffmpeg version n4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20180831
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] stream 0, offset 0x30: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 240x180, 374 kb/s): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:0':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf54.63.104
Duration: 00:00:14.72, start: 0.000000, bitrate: N/A
Stream #0:0(und): Video: h264 (avc1 / 0x31637661), none, 240x180, 374 kb/s, 25 fps, 25 tbr, 12800 tbn, 25600 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 75 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:1 -> #0:0 (aac (native) -> mp3 (libmp3lame))
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x562c9e18de80] stream 1, offset 0xa1e: partial file
pipe:0: Invalid data found when processing input
Output #0, mp3, to 'pipe:1':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
TSSE : Lavf58.20.100
Stream #0:0(und): Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp, 192 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc58.35.100 libmp3lame
size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
{ frames: NaN,
currentFps: NaN,
currentKbps: NaN,
targetSize: 0,
timemark: '00:00:00.00' }
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
The latter explains the empty file you're seeing in the output. As to why the error only happens while streaming the file, and not while opening it through another method, this answer explains the details: https://stackoverflow.com/a/40028894/1494833
Unfortunately the library doesn't yet support movflags
input option as recommended above (https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/issues/823).
answered Jan 10 at 14:23
r0hitsharmar0hitsharma
999714
999714
add a comment |
add a comment |
Assuming that you are using the ffmpeg package which is basically a wrapper for running ffmpeg in node, you would have to do it somewhat like this:
This code works on my system using the same file you provided in the comments above but you may have to make some changes (Node v8.12.0, ffmpeg v0.0.4).
const ffmpeg = require('ffmpeg');
try {
let process = new ffmpeg('3.mp4');
process.then(function (video) {
// Callback mode
video.fnExtractSoundToMP3('3.mp3', function (error, file) {
if (!error)
console.log('Audio file: ' + file);
});
}, function (err) {
console.log('Error: ' + err);
});
} catch (e) {
console.log(e.code);
console.log(e.msg);
}
1
Thanks for your response, but I probably did not understand, there's no problem extracting the audio, the problem is to use streams, your code will not work if you write this way: let process = new ffmpeg(fs.createReadStream('3.mp4')); video.fnExtractSoundToMP3(fs.createWriteStream('3.mp3')
– ABE
Jan 2 at 17:28
add a comment |
Assuming that you are using the ffmpeg package which is basically a wrapper for running ffmpeg in node, you would have to do it somewhat like this:
This code works on my system using the same file you provided in the comments above but you may have to make some changes (Node v8.12.0, ffmpeg v0.0.4).
const ffmpeg = require('ffmpeg');
try {
let process = new ffmpeg('3.mp4');
process.then(function (video) {
// Callback mode
video.fnExtractSoundToMP3('3.mp3', function (error, file) {
if (!error)
console.log('Audio file: ' + file);
});
}, function (err) {
console.log('Error: ' + err);
});
} catch (e) {
console.log(e.code);
console.log(e.msg);
}
1
Thanks for your response, but I probably did not understand, there's no problem extracting the audio, the problem is to use streams, your code will not work if you write this way: let process = new ffmpeg(fs.createReadStream('3.mp4')); video.fnExtractSoundToMP3(fs.createWriteStream('3.mp3')
– ABE
Jan 2 at 17:28
add a comment |
Assuming that you are using the ffmpeg package which is basically a wrapper for running ffmpeg in node, you would have to do it somewhat like this:
This code works on my system using the same file you provided in the comments above but you may have to make some changes (Node v8.12.0, ffmpeg v0.0.4).
const ffmpeg = require('ffmpeg');
try {
let process = new ffmpeg('3.mp4');
process.then(function (video) {
// Callback mode
video.fnExtractSoundToMP3('3.mp3', function (error, file) {
if (!error)
console.log('Audio file: ' + file);
});
}, function (err) {
console.log('Error: ' + err);
});
} catch (e) {
console.log(e.code);
console.log(e.msg);
}
Assuming that you are using the ffmpeg package which is basically a wrapper for running ffmpeg in node, you would have to do it somewhat like this:
This code works on my system using the same file you provided in the comments above but you may have to make some changes (Node v8.12.0, ffmpeg v0.0.4).
const ffmpeg = require('ffmpeg');
try {
let process = new ffmpeg('3.mp4');
process.then(function (video) {
// Callback mode
video.fnExtractSoundToMP3('3.mp3', function (error, file) {
if (!error)
console.log('Audio file: ' + file);
});
}, function (err) {
console.log('Error: ' + err);
});
} catch (e) {
console.log(e.code);
console.log(e.msg);
}
edited Jan 2 at 6:44
answered Jan 2 at 6:29
The DoctorThe Doctor
6428
6428
1
Thanks for your response, but I probably did not understand, there's no problem extracting the audio, the problem is to use streams, your code will not work if you write this way: let process = new ffmpeg(fs.createReadStream('3.mp4')); video.fnExtractSoundToMP3(fs.createWriteStream('3.mp3')
– ABE
Jan 2 at 17:28
add a comment |
1
Thanks for your response, but I probably did not understand, there's no problem extracting the audio, the problem is to use streams, your code will not work if you write this way: let process = new ffmpeg(fs.createReadStream('3.mp4')); video.fnExtractSoundToMP3(fs.createWriteStream('3.mp3')
– ABE
Jan 2 at 17:28
1
1
Thanks for your response, but I probably did not understand, there's no problem extracting the audio, the problem is to use streams, your code will not work if you write this way: let process = new ffmpeg(fs.createReadStream('3.mp4')); video.fnExtractSoundToMP3(fs.createWriteStream('3.mp3')
– ABE
Jan 2 at 17:28
Thanks for your response, but I probably did not understand, there's no problem extracting the audio, the problem is to use streams, your code will not work if you write this way: let process = new ffmpeg(fs.createReadStream('3.mp4')); video.fnExtractSoundToMP3(fs.createWriteStream('3.mp3')
– ABE
Jan 2 at 17:28
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53917893%2ffluent-ffmpeg-extract-audio-using-streaming%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is the Readstream seekable? If not, ffmpeg can't read the MP4.
– Gyan
Dec 25 '18 at 5:49
1
FFmpeg needs to be able to go back and forth in the MP4. If the
fs
method doesn't support that, ffmpeg will not be able to parse the input.– Gyan
Dec 27 '18 at 4:23
2
Althoiugh you may be able to work around if your MP4 has MOOV box at the front..
– Gyan
Dec 27 '18 at 5:05
1
@ABE, I had no problems running the code above. For my mp4 sample, I used the following file: github.com/mediaelement/mediaelement-files/blob/master/… Can you verify this?
– r0hitsharma
Dec 28 '18 at 19:14
1
@r0hitsharma Yes, it works fine. Why does it only work in your file?
– ABE
Dec 29 '18 at 22:09