Mp4 to HLS using ffmpeg
Asked Answered
F

2

22

I'm trying to convert a local .mp4 video to HLS using ffmpeg in an iOS app. I have integrated the ffmpeg wrapper using pods and generated all the segmented .ts files and the m3u8 file, but some of the .ts file segments are not listed in the .m3u8 playlist file as shown below. It is always listing the last 5 video segments.

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:2
#EXT-X-MEDIA-SEQUENCE:13
#EXTINF:2,
out13.ts
#EXTINF:1,
out14.ts
#EXTINF:2,
out15.ts
#EXTINF:2,
out16.ts
#EXTINF:1,
out17.ts
#EXT-X-ENDLIST

I used the following codes to generate the HLS.

    FFmpegWrapper *wrapper = [[FFmpegWrapper alloc] init];
    [wrapper convertInputPath:inputFilePath outputPath:outputFilePath options:nil progressBlock:^(NSUInteger bytesRead, uint64_t totalBytesRead, uint64_t totalBytesExpectedToRead) {

    } completionBlock:^(BOOL success, NSError *error) {
        success?NSLog(@"Success...."):NSLog(@"Error : %@",error.localizedDescription);
    }];

Is there any other methods to do this?

Fotinas answered 18/6, 2015 at 10:13 Comment(3)
I'm considering letting users' devices encode the videos they take, instead of doing it on the server. I was curious whether encoding would take too long on the user's side. Could you comment on your experience?Durwood
any info on @GaziAlankus question? I too am curious to how long it would takeMess
I have tried video with length upto 15 minutes and its all working fine without taking much time. The HLS module get completed with in some seconds. May be it will take some time depending upon the video quality and video length.Fotinas
F
7

At last I fixed this issue by setting the hls size in the FFOutputFile.m using the following code.

av_opt_set_int(formatContext->priv_data, "hls_list_size", list_size, 0);
Fotinas answered 19/6, 2015 at 8:52 Comment(2)
Where exactly did you add this? I am facing same issue. Can you help?Rhea
@Bhumit: In the FFOutputFile.m you can see an init method - (id) initWithPath:(NSString *)path options:(NSDictionary *)options. Set the code inside this function.Fotinas
S
37

Default list size while converting to HLS is 5. So, you are getting the last 5 .ts files. You must set -hls_list_size 0 to include all the generated .ts files.

ffmpeg -i input.mp4 -profile:v baseline -level 3.0 -s 640x360 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls index.m3u8 More here

Septuor answered 18/6, 2015 at 11:57 Comment(2)
Thanks for your reply, but where should I set this size in my code. I'm using this in an iphone app.Fotinas
I don't know about your iphone app. You can look for Media File Segmenter from Apple. linkSeptuor
F
7

At last I fixed this issue by setting the hls size in the FFOutputFile.m using the following code.

av_opt_set_int(formatContext->priv_data, "hls_list_size", list_size, 0);
Fotinas answered 19/6, 2015 at 8:52 Comment(2)
Where exactly did you add this? I am facing same issue. Can you help?Rhea
@Bhumit: In the FFOutputFile.m you can see an init method - (id) initWithPath:(NSString *)path options:(NSDictionary *)options. Set the code inside this function.Fotinas

© 2022 - 2024 — McMap. All rights reserved.