繁体   English   中英

如何在iOS中使用ffmpeg将.mp4文件转换为.ts文件

[英]How to convert .mp4 file to .ts using ffmpeg in iOS

我想以编程方式将.mp4文件转换为.ts文件。 我搜索并发现我可以使用ffmpeg库,这是我以前从未使用过的。

我也成功地将这个库导入到我的项目中,但我无法弄清楚如何将.mp4文件转换为.ts 我仔细查看了一下,发现了如下命令:

ffmpeg -i file.mp4 -acodec libfaac -vcodec libx264 -an -map 0 -f segment -segment_time 10 -segment_list test.m3u8 -segment_format mpegts -vbsf h264_mp4toannexb -flags -global_header stream%05d.ts

但是我如何在我的iOS项目中使用它? 任何帮助表示赞赏。

在您的课程中添加ffmpeg库。 我更喜欢在cocoapods中使用ffmpeg包装类。

pod 'FFmpegWrapper', '~> 1.0'

安装pod并使用以下代码将mp4文件转换为ts。

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);
    }];

inputFilePath:mp4视频文件的包路径outputFilePath:NSDocumentDirectory路径,您可以在其中保存.ts文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM