ijkplayer支持分段播放设置

http://blog.csdn.net/liushihua147/article/details/60962967?locationNum=10&fps=1

http://blog.csdn.net/lhy412484577/article/details/68063917

https://ffmpeg.org/ffmpeg-formats.html#concat-1


3.5 concat

Virtual concatenation script demuxer.

This demuxer reads a list of files and other directives from a text file and demuxes them one after the other, as if all their packets had been muxed together.

The timestamps in the files are adjusted so that the first file starts at 0 and each next file starts where the previous one finishes. Note that it is done globally and may cause gaps if all streams do not have exactly the same length.

All files must have the same streams (same codecs, same time base, etc.).

The duration of each file is used to adjust the timestamps of the next file: if the duration is incorrect (because it was computed using the bit-rate or because the file is truncated, for example), it can cause artifacts. The duration directive can be used to override the duration stored in each file.


支持分段视频(一个视频多个片段)的播放


可以更改 下图中的文件中















打开如图标记的这个文件 找到concat有两条相关





将前面的disable 都改为enable (本身是的就不用动了啦) 然后别忘记保存


接着执行



cd ios


./compile-ffmpeg.sh clean

./compile-ffmpeg.sh all



然后等待编译完成 这是一个漫长的过程 此时编译的是ffmpeg


剩下的就是和bilibili文档一样






导入相应的工程 B站提供的是不打包直接拖入工程 同样你可以选择打包 然后在拖入工程的为framework



当然这时并没有结束



如果需要播放分片视频 还要对ijkplayer做处理


打开如下文件




为了实现播放分片视频 比如加上如下框中的三行代码,保证播放器的安全开启




ijkmp_set_option(_mediaPlayer,IJKMP_OPT_CATEGORY_FORMAT,"safe"0);

ijkmp_set_option(_mediaPlayer,IJKMP_OPT_CATEGORY_PLAYER,"protocol_whitelist","ffconcat,file,http,https");

ijkmp_set_option(_mediaPlayer,IJKMP_OPT_CATEGORY_FORMAT,"protocol_whitelist","concat,http,tcp,https,tls,file");




之后使用方法


#pragma mark -

#pragma mark   ==============读写文件==============

@interface GLVideoDetailInfoModel :NSObject


@property (nonatomic,copyNSString *duration;

@property (nonatomic,copyNSString *size;

@property (nonatomic,copyNSString *url;


@end



- (NSURL *)writeTofeildWithData:(NSArray *)urlArr {

    // 1.找到Documents文件夹路径

    NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMaskYES)objectAtIndex:0];

    // 2.创建要存储的内容:字符串

    NSString *str =@"ffconcat version 1.0";

    for (GLVideoDetailInfoModel *modelin urlArr) {

        str = [NSStringstringWithFormat:@"%@\nfile %@\nduration %.0f",str,model.url,[model.durationfloatValue] / 1000.0];

    }

    DLog(@"分片视频数据:%@",str);

    // 3.需要知道字符串最终存储的地方,所以需要创建一个路径去存储字符串

    NSString *strPath = [documentsPathstringByAppendingPathComponent:@"videoUrl.concat"];

    // 4.将字符串写入文件

    [str writeToFile:strPathatomically:YESencoding:NSUTF8StringEncodingerror:nil];

    NSURL *URL = [[NSURLallocinitFileURLWithPath:strPath];

    

    return URL;

}





此方法获取写入本地的拼接好的ffmpeg的播放地址 传给播放器 即可使用播放 但是必须要各个分片视频的长度 单位为s(秒)

项目是一个视频类的app 刚开始找很多播放器,感觉都还不错,随着业务不断的变迁,对视频播放也要求越来越高,要满足基本的视频播放,如MP4 、m3u8...正常的播放地址,后来又有分段式的视频地址,有的还要设置视频连接的请求头,一般的播放器都满足简单的地址播放,多段播放的就很少了,后来在网上查了好久,满足多段播放比较不错的播放器有两个:一个是ijkplayer ,一个是vitamin 都能支持分段时播放,他们都是基于ffmpeg 来实现的,下面我来说下怎么使用它们播放多短视频

1.ijkplayer点击打开链接

如何安装的这里我就不多说了,网上都有的 

ijkplayer 播放多短视频,需要修改ffmpeg的一些配置,

打开如图标记的这个文件 找到concat有两条相关 

将前面的disable 都改为enable (本身是的就不用动了啦)然后别忘记保存

当然这时并没有结束

剩下的就是跟ijkplayer 里面一样使用了,播放分段地址,需要创建一个concat文件,类似于m3u8 样的一个文件,然后获取本地路径,播放器本地文件,如何生成concat文件点击打开链接

多谢 伊卡洛斯Master 分享的文章

http://blog.csdn.NET/liushihua147/article/details/60962967

2.vitamin 点击打开链接



数组里面存放多段视频地址 setOptionsWithKeys:可以设置请求头参数,具体的api 可以参考官方demo ,希望可以给大家带来帮助!



你可能感兴趣的:(iOS_音视频)