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
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?