I am creating a mediacenter application in NodeJS that is going well. (you can check this on Github: https://github.com/jansmolders86/mediacenterjs )
I use FFMPEG to transcode local (static) movies to a stream, which I then send to the browser.
At first I used h264 with Flash, which worked in browsers, but I really need it to work on Android iOS (so there is no Flash) and, preferably, work on the raspberry Pi.
But making him play on all devices is driving me crazy!
I have all these puzzle pieces that I collected from countless hours reading articles, tutorials, and stack overflow messages, which led me to conclude that I needed to create the following:
- Use H264 video codec to transcode to MP4
- Move moovatom '-movflags' to make MP4 stream
- Segment the stream so that Apple can also play the stream.
But nothing will work. Every time I create a series of FFMPEG settings that either don't work or work on some devices, not all.
Some of my failed attempts:
My attempt to flash -> The main problem (does not work on iOS):
'-y','-ss 0','-b 800k','-vcodec libx264','-acodec mp3'\ '-ab 128','-ar 44100','-bufsize 62000', '-maxrate 620k'\ metaDuration,tDuration,'-f flv
my HLS attempt -> The main problem (not running in the browser):
'-r 15','-b:v 128k','-c:v libx264','-x264opts level=41'\ '-threads 4','-s 640x480','-map 0:v','-map 0:a:0','-c:a mp3'\ '-b:a 160000','-ac 2','-f hls','-hls_time 10','-hls_list_size 6'\ '-hls_wrap 18','-start_number 1'
My attempt at MP4 -> The main problem (the duration is shortened, and the later part of the video is accelerated)
'-y','-ss 0','-b 800k','-vcodec libx264','-acodec mp3'\ '-ab 128','-ar 44100','-bufsize 62000', '-maxrate 620k'\ metaDuration,tDuration,'-f mp4','-movflags','frag_keyframe+empty_moov'
Second MP4 attempt: โ The main problem (the duration is shortened, and the later part of the video is accelerated)
'-y','-vcodec libx264','-pix_fmt yuv420p','-b 1200k','-flags +loop+mv4'\ '-cmp 256','-partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8'\ '-me_method hex','-subq 7','-trellis 1','-refs 5','-bf 3','-coder 1'\ '-me_range 16','-g 150','-keyint_min 25','-sc_threshold 40'\ '-i_qfactor 0.71','-acodec mp3','-qmin 10','-qdiff 4','-qmax 51'\ '-ab 128k','-ar 44100','-threads 2','-f mp4','-movflags','frag_keyframe+empty_moov'])
Here is an example of the FFMPEG log that works with these settings:
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 [avi @ 02427900] non-interleaved AVI Guessed Channel Layout for Input Stream
Finally, this is my node code that runs FFMPEG. (I am using the Fluent-ffmpeg module: https://github.com/schaermu/node-fluent-ffmpeg )
var proc = new ffmpeg({ source: movie, nolog: true, timeout:15000}) .addOptions(['-r 15','-b:v 128k','-c:v libx264','-x264opts level=41','-threads 4','-s 640x480','-map 0:v','-map 0:a:0','-c:a mp3','-b:a 160000','-ac 2','-f hls','-hls_time 10','-hls_list_size 6','-hls_wrap 18','-start_number 1 stream.m3u8']) .writeToStream(res, function(retcode, error){ if (!error){ console.log('file has been converted succesfully',retcode .green); }else{ console.log('file conversion error',error .red); } });
So, to complete this very long and complicated question:
I hope this does not break away from the lazy request, but can someone show / explain to me what FFMPEG settings could / should have worked on all platforms (modern browsers, Android and iOS), creating a stream of a static file that I can send the player HTML5
[EDIT] what I need if the general option is unavailable
And if this is not possible, as some messages may suggest, I would really like to see a set of FFMPEG settings that would do the job properly before mp4 streaming. (e.g. encoding streaming mp4).
Mp4 streaming requires the following
- Shifted moovatom
- It must be h264
Thank you very much for your help!