Mp4到HLS使用ffmpeg

我试图在iOS应用程序中使用ffmpeg将本地.mp4video转换为HLS。 我已经使用pod集成了ffmpeg包装器,并生成了所有分段的.ts文件和m3u8文件,但某些.ts文件段未在.m3u8播放列表文件中列出,如下所示。 它总是列出最后5个video片段。

#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 

我用下面的代码来生成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); }]; 

有没有其他方法可以做到这一点?

转换为HLS时的默认列表大小为5 。 所以,你得到最后5个.ts文件。 您必须设置-hls_list_size 0以包含所有生成的.ts文件。

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更多这里

最后我通过使用下面的代码在FFOutputFile.m设置hls的大小来解决这个问题。

 av_opt_set_int(formatContext->priv_data, "hls_list_size", list_size, 0);