<p>Simplest solution is to use -movflags +faststart in your command while transcoding video file. It will move all metadata to the beginning of the file to be played. Hope this helps.</p>

CC BY-SA 3.0
2015-07-10T09:14:16.297Z
2015-07-10T09:14:16.297Z
89neuron
<p>So it turns out after a lot of research that this is the desired behaviour for Apple's AVPlayer component. Basically, my Internet is so slow here where I live, the component waits until the video has fully downloaded before it starts playing. The best and recommended way around this, is to generate alternate streams for the video before trying to play it. Here is documentation on the m3u8 format and HLS streaming guidelines:</p>

<p><a href="https://developer.apple.com/library/ios/documentation/networkinginternet/conceptual/streamingmediaguide/Introduction/Introduction.html" rel="nofollow">https://developer.apple.com/library/ios/documentation/networkinginternet/conceptual/streamingmediaguide/Introduction/Introduction.html</a></p>

<p>I followed the above and generated two extra streams from the original: a 200kbps, 400kbps, and playback now starts almost immediately. Your mileage may vary depending on the speed of your Internet connection.</p>

<p>Alternatively, if you don't have to use something like HLS, you can use plain mp4 files. Make sure that they have <code>-faststart</code> enabled if you are processing the file with ffmpeg.</p>

<p><strong>Update:</strong> To simplify this for other developers, I have released an SDK that is able to upload your mov or mp4 files to a cloud service and convert the file to an HLS compatible stream. The SDK can be installed via Cocoapods and you can access documentation and the framework here: </p>

<p><a href="https://github.com/Storie/StorieCloudSDK" rel="nofollow">https://github.com/Storie/StorieCloudSDK</a></p>

CC BY-SA 3.0
2015-07-13T23:24:18.747Z
It's `-movflags +faststart` for mp4.
Peter Cordes
CC BY-SA 3.0
2014-12-05T15:13:57.993Z
2016-06-27T17:10:57.790Z
2016-06-27T17:10:57.790Z
Michael Gaylord
<p>I am using ffmpeg to generate a segmented list of files in order to stream them to an iOS app. The list of files is generated fine but when it comes time to play them, the video needs to be downloaded in its entirety before playback starts. This behaviour seems to be the case on iOS, Safari and VLC.</p>

<p>Does anybody know why this is happening and how I can improve the performance of playback? I have complete control over how the files are recorded in iOS, as well as how they are processed. Here is a sample stream:</p>

<p><a href="http://www.bytesizecreations.com/storie-test/hls.m3u8" rel="nofollow">http://www.bytesizecreations.com/storie-test/hls.m3u8</a></p>

<p>Here are my ffmpeg commands to generate the segments from the file:</p>

<pre><code>ffmpeg -i joined.ts -flags -global_header -vcodec copy -acodec copy -map 0 -f segment -segment_time 2 -segment_list hls.m3u8 -segment_list_size 999999 -segment_format mpegts out%03d.ts
Here is the output of ffprobe on the file:

  libavutil      54.  7.100 / 54.  7.100
  libavcodec     56.  1.100 / 56.  1.100
  libavformat    56.  4.101 / 56.  4.101
  libavdevice    56.  0.100 / 56.  0.100
  libavfilter     5.  1.100 /  5.  1.100
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  0.100 /  3.  0.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  0.100 / 53.  0.100
Input #0, mpegts, from 'joined.ts':
  Duration: 00:00:07.96, start: 1.441667, bitrate: 3899 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 1280x720, 24 fps, 24 tbr, 90k tbn, 180k tbc
    Stream #0:1[0x101](und): Audio: aac ([15][0][0][0] / 0x000F), 44100 Hz, stereo, f
</code></pre>

CC BY-SA 3.0
2014-11-24T17:05:36.200Z
I'm sadly not particularly familiar with FFMPEG, however, generally speaking, a file needs to front load certain meta data to be a streamable file.  If this data is not front loaded, then the download will have to finish prior to the file being playable.  It is sometimes called things like "Progressive Download".  I'm sure someone else can give you a more exact answer for FFMPEG, but hopefully that direction can help you in the interim.
AJ Henderson
<ffmpeg><streaming><ios>
FFMpeg and HLS, videos need to load in their entirety before they start playing
Michael Gaylord
# FFMpeg and HLS, videos need to load in their entirety before they start playing

(Asked by: username_0 on 2014-11-24)

I am using ffmpeg to generate a segmented list of files in order to stream them to an iOS app. The list of files is generated fine but when it comes time to play them, the video needs to be downloaded in its entirety before playback starts. This behaviour seems to be the case on iOS, Safari and VLC.
Does anybody know why this is happening and how I can improve the performance of playback? I have complete control over how the files are recorded in iOS, as well as how they are processed. Here is a sample stream:
http://www.bytesizecreations.com/storie-test/hls.m3u8
Here are my ffmpeg commands to generate the segments from the file:
ffmpeg -i joined.ts -flags -global_header -vcodec copy -acodec copy -map 0 -f segment -segment_time 2 -segment_list hls.m3u8 -segment_list_size 999999 -segment_format mpegts out%03d.ts
Here is the output of ffprobe on the file:

  libavutil      54.  7.100 / 54.  7.100
  libavcodec     56.  1.100 / 56.  1.100
  libavformat    56.  4.101 / 56.  4.101
  libavdevice    56.  0.100 / 56.  0.100
  libavfilter     5.  1.100 /  5.  1.100
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  0.100 /  3.  0.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  0.100 / 53.  0.100
Input #0, mpegts, from 'joined.ts':
  Duration: 00:00:07.96, start: 1.441667, bitrate: 3899 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 1280x720, 24 fps, 24 tbr, 90k tbn, 180k tbc
    Stream #0:1[0x101](und): Audio: aac ([15][0][0][0] / 0x000F), 44100 Hz, stereo, f

**Tags:** ffmpeg, streaming, ios

> **Comments:**
> **username_1**: I'm sadly not particularly familiar with FFMPEG, however, generally speaking, a file needs to front load certain meta data to be a streamable file.  If this data is not front loaded, then the download will have to finish prior to the file being playable.  It is sometimes called things like "Progressive Download".  I'm sure someone else can give you a more exact answer for FFMPEG, but hopefully that direction can help you in the interim.  

---

## 2 answers

### Answer by username_0 on 2014-12-05. Score: 3 | Accepted answer

So it turns out after a lot of research that this is the desired behaviour for Apple's AVPlayer component. Basically, my Internet is so slow here where I live, the component waits until the video has fully downloaded before it starts playing. The best and recommended way around this, is to generate alternate streams for the video before trying to play it. Here is documentation on the m3u8 format and HLS streaming guidelines:

<https://developer.apple.com/library/ios/documentation/networkinginternet/conceptual/streamingmediaguide/Introduction/Introduction.html>

I followed the above and generated two extra streams from the original: a 200kbps, 400kbps, and playback now starts almost immediately. Your mileage may vary depending on the speed of your Internet connection.

Alternatively, if you don't have to use something like HLS, you can use plain mp4 files. Make sure that they have `-faststart` enabled if you are processing the file with ffmpeg.

**Update:** To simplify this for other developers, I have released an SDK that is able to upload your mov or mp4 files to a cloud service and convert the file to an HLS compatible stream. The SDK can be installed via Cocoapods and you can access documentation and the framework here:

<https://github.com/Storie/StorieCloudSDK>

> **Comments:**
> **username_3**: It's `-movflags +faststart` for mp4.  

---

### Answer by username_2 on 2015-07-10. Score: 1

Simplest solution is to use -movflags +faststart in your command while transcoding video file. It will move all metadata to the beginning of the file to be played. Hope this helps.


---

