Ffmpeg sends the duration of the video to the client (using node-fluent-ffmpeg)

I'm really new to the ffmpeg world, so please excuse me if this is a stupid quest.

I am using the Node -fluent-ffmpeg module to stream a movie and convert it from avi to webm using FFMPEG.

It’s still so good (it plays the video), but I can’t figure out the duration for the player. It also gives me an error, even if I play the video.

my code is as follows:

var stat = fs.statSync(movie); var start = 0; var end = 0; var range = req.header('Range'); if (range != null) { start = parseInt(range.slice(range.indexOf('bytes=')+6, range.indexOf('-'))); end = parseInt(range.slice(range.indexOf('-')+1, range.length)); } if (isNaN(end) || end == 0) end = stat.size-1; if (start > end) return; var duration = (end / 1024) * 8 / 1024; res.writeHead(206, { // NOTE: a partial http response 'Connection':'close', 'Content-Type':'video/webm', 'Content-Length':end - start, 'Content-Range':'bytes '+start+'-'+end+'/'+stat.size, 'Transfer-Encoding':'chunked' }); var proc = new ffmpeg({ source: movie, nolog: true, priority: 1, timeout:15000}) .toFormat('webm') .addOptions(['-probesize 900000', '-analyzeduration 0', '-minrate 1024k', '-maxrate 1024k', '-bufsize 1835k', '-t '+duration+' -ss']) .writeToStream(res, function(retcode, error){ if (!error){ console.log('file has been converted succesfully',retcode); }else{ console.log('file conversion error',error); } }); 

I set the header with start and end based on this article: http://delog.wordpress.com/2011/04/25/stream-webm-file-to-chrome-using-node-js/

I calculate the length in seconds in a variable duration.

The FFmpeg error gives me:

  file conversion error ffmpeg version N-52458-gaa96439 Copyright (c) 2000-2013 the FFmpeg developers built on Apr 24 2013 22:19:32 with gcc 4.8.0 (GCC) configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --e nable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable -libgsm --enable-libilbc --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --ena ble-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwola me --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enabl e-libxvid --enable-zlib libavutil 52. 27.101 / 52. 27.101 libavcodec 55. 6.100 / 55. 6.100 libavformat 55. 3.100 / 55. 3.100 libavdevice 55. 0.100 / 55. 0.100 libavfilter 3. 60.101 / 3. 60.101 libswscale 2. 2.100 / 2. 2.100 libswresample 0. 17.102 / 0. 17.102 libpostproc 52. 3.100 / 52. 3.100 Input #0, avi, from 'C:/temp/test.avi': Metadata: encoder : Nandub v1.0rc2 Duration: 00:01:09.78, start: 0.000000, bitrate: 1517 kb/s Stream #0:0: Video: msmpeg4v3 (DIV3 / 0x33564944), yuv420p, 640x352, 23.98 tbr, 23.98 tbn, 23.98 tbc Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 222 kb/s [libvpx @ 0036db20] v1.2.0 Output #0, webm, to 'pipe:1': Metadata: encoder : Lavf55.3.100 Stream #0:0: Video: vp8, yuv420p, 640x352, q=-1--1, 200 kb/s, 1k tbn, 23.98 tbc Stream #0:1: Audio: vorbis, 48000 Hz, stereo, fltp Stream mapping: Stream #0:0 -> #0:0 (msmpeg4 -> libvpx) Stream #0:1 -> #0:1 (mp3 -> libvorbis) 

The client-side player (which is VideoJs) says the file is infinite / NaN in length.

I feel pretty close to a solution, but my inexperience in this matter forbids me to work. If I do not quite understand, please let me know. (I have a tendency to explain things fuzzy.)

Thanks in advance!

[EDIT]

I deleted the duration bit because it has nothing to do with the problem. I checked the header of the client response and saw:

  Accept-Ranges:bytes Connection:keep-alive Content-Length:13232127 Content-Range:bytes 0-13232127/13232128 Content-Type:video/webm 

Why can't the client determine the duration, even if he gets it in the header?

+4
source share
2 answers

I realized what the problem is. I made some tweaks with the response header, but ffmpeg was the villain in history. I fixed mp3 transcoding, and the analysis duration is processed by the client. Thus, due to the fact that I received an error with FFMPEG, while the transcoding of metadata was written incorrectly.

+1
source

Not an answer, but how

 var duration = (end / 1024) * 8 / 1024; 

going to give you the duration of the content, given that the "end" is the number of bytes of your source, and you use the bitrate of the result to calculate? This does not make sense unless your source always has a value of 1024 Kbps CBR.

To get the duration, you will have to analyze / analyze the source file and / or view its metadata.

In addition, ffmpeg reports a 200 kbps output as the output rate, which is not like what you intended.

Edit:

Perhaps you can get the duration of the source using node-fluent-ffmpeg, see https://github.com/schaermu/node-fluent-ffmpeg#reading-video-metadata

+1
source

Source: https://habr.com/ru/post/1482376/


All Articles