title: What parameters are necessary in FFMPEG to stream (HLS) to modern Android devices?
body: <p>I want to convert a regular video file (MP4 x264) to HLS to be streamed on Android devices using <code>ffmpeg</code>. I have an html5 player setup to play the HLS stream (m3u8) and have tested it on Chrome and Firefox desktop browsers and everything works fine. The issue is that the same exact player and m3u8 playlist does not work on Android Chrome and Android Firefox (both give an unsupported file type error). </p>
  
  <p>At first I thought it may be an issue with the html5 player and HLS support, so I took a random m3u8 playlist stream from a quick google search, and of course that stream worked fine in my html5 player on Android. So I know it is not the html5 player and lack of HLS support. I think that I am using an incorrect codec or other parameter in ffmpeg, but after dozens of attempts I decided to ask here because I'm all out of ideas.</p>
  
  <p>My original <code>ffmpeg</code> command is:</p>
  
  <pre><code>ffmpeg -i "test.mp4" -preset ultrafast -c:v h264 -c:a aac -f ssegment -segment_list playlist.m3u8 -segment_list_type hls -segment_list_size 0 out_%6d.ts
  </code></pre>
  
  <p>I've tried:</p>
  
  <pre><code>ffmpeg -i "test.mp4" -c:v libx264 -c:a aac -ac 1 -strict -2 -crf 18 -profile:v baseline -maxrate 400k -bufsize 1835k -pix_fmt yuv420p -flags -global_header -hls_time 10 -hls_list_size 6 -hls_wrap 10 -start_number 1 playlist.m3u8
  ffmpeg -i "test.mp4" -c:v copy -c:a aac -ac 2 -f hls -hls_time 60 -hls_playlist_type event playlist.m3u8
  ffmpeg -i "test.mp4" -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -hls_playlist_type vod -vf scale=w=640:h=360:force_original_aspect_ratio=decrease -b:v 800k -maxrate 856k -bufsize 1200k -b:a 96k -hls_segment_filename 360p_%03d.ts playlist.m3u8 
  ffmpeg -i "test.mp4" -c:v libx264 -c:a aac -ac 1 -strict -2 -crf 18 -profile:v baseline -maxrate 400k -bufsize 1835k -pix_fmt yuv420p -flags -global_header -hls_time 10 -hls_list_size 6 -hls_wrap 10 -start_number 1 playlist.m3u8
  </code></pre>
  
  <p>And have tried dozens of other combinations of patterns i.e. changing segment file sizes, setting aspect ratio, and just about any example I could find that would seem relevant. I know I probably just got one parameter wrong or perhaps it is a header issue?</p>
  
  <p>As I said before, I took a sample HLS stream online and it didn't give any problems. It is only when I'm running it through <code>ffmpeg</code> that it doesn't work on mobile devices. I also downloaded a test mp4 file in case there was something wrong with my file, but it made no difference.</p>
  
  <p>I have been tracking down where the issue lies. I've been able to narrow out it being a codec problem, because I took a sample video file and re-encoded it to mp4 (h264 aac). In the html5 player on Android it streamed correctly so long as it was in mp4 format.</p>
  
  <p>I've been able to narrow it down to something related to the m3u8 playlist file itself and/or location of files. Perhaps the m3u8 playlist file is missing a parameter. Trying to compare it with others found on the internet and haven't really noticed a difference so far.</p>