ios 使用 ffmpeg 将 Mp4 转换为 HLS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30912542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mp4 to HLS using ffmpeg
提问by Vishnu Kumar. S
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.
我正在尝试在 iOS 应用程序中使用 ffmpeg 将本地 .mp4 视频转换为 HLS。我已经使用 pods 集成了 ffmpeg 包装器,并生成了所有分段的 .ts 文件和 m3u8 文件,但某些 .ts 文件段未在 .m3u8 播放列表文件中列出,如下所示。它总是列出最后 5 个视频片段。
#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.
我使用以下代码生成 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?
有没有其他方法可以做到这一点?
采纳答案by Vishnu Kumar. S
At last I fixed this issue by setting the hls size in the FFOutputFile.m
using the following code.
最后,我通过FFOutputFile.m
使用以下代码设置 hls 大小来解决此问题。
av_opt_set_int(formatContext->priv_data, "hls_list_size", list_size, 0);
回答by budthapa
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.
转换为 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
More here
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
更多在这里