3

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
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.
    – AJ Henderson
    Nov 24, 2014 at 17:05

2 Answers 2

3

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

1
  • 2
    It's -movflags +faststart for mp4. Jul 13, 2015 at 23:24
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.