ijkplayer视频音频Android iOS开发知识库

ijkplayer-ffmpeg之concat

2016-10-12  本文已影响3232人  南风无影

参考ffmpeg的concat官方文档

concat顾名思义,就是把多段视频拼接播放,可以用于连续剧的连续播放。

configure配置:

--enable-demuxer=concat
--enable-protocol=concat

ijkplayer对应修改

export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-protocol=concat"
export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-demuxer=concat"

总得来说,只需要3步

根据文档精神,需要新建一个文件,命名为 1.ffconcat (当然,也可以1.ffcat)

A list file with the suffix ".ffcat" or ".ffconcat"  will auto-select this format.

1.ffconcat内容:

ffconcat version 1.0
file '/sdcard/1.mp4'
duration 3.0
file '/sdcard/2.mp4'
duration 3.0
file '/sdcard/3.mp4'
duration 3.0

url路径这样写:
file:///sdcard/1.ffconcat

这样还是有问题,因为safe参数的原因:

safe
If set to 1, reject unsafe file paths. A file path is considered safe if it does not contain a protocol specification and is relative and all components only contain characters from the portable character set (letters, digits, period, underscore and hyphen) and have no period at the beginning of a component.

If set to 0, any file name is accepted.

The default is 1.

-1 is equivalent to 1 if the format was automatically probed and 0 otherwise.

很明显,safe默认是1.
看代码libavformat/concatdec.c

static int add_file(AVFormatContext *avf, char *filename, ConcatFile **rfile,
                    unsigned *nb_files_alloc)
{
    ConcatContext *cat = avf->priv_data;
    ConcatFile *file;
    char *url = NULL;
    const char *proto;
    size_t url_len, proto_len;
    int ret;

    if (cat->safe > 0 && !safe_filename(filename)) {
        av_log(avf, AV_LOG_ERROR, "Unsafe file name '%s'\n", filename);
        //FAIL(AVERROR(EPERM)); //gongjia mask
    }

safe_filename这个函数被判断返回0了,简单做法是把FAIL这行屏蔽掉,简单粗暴!

编译验证ffmpeg3.1,播放没问题。(ffmpeg3.1及以下都有这问题,以上的没验证过)

有一点要注意:要加上duration,要不然播放的时候总的时长和进度会有问题
参考2.ffconcat

ffconcat version 1.0
file http://v1.play.fangyantianxia.cn/630ef5659bd52ff1.m3u8
duration 48.8
file http://v1.play.fangyantianxia.cn/e1e92bc7782670d6.m3u8
duration 255.7

官方解释是这样:

duration dur

Duration of the file. This information can be specified from the file; specifying it here may be more efficient or help if the information from the file is not available or accurate.
If the duration is set for all files, then it is possible to seek in the whole concatenated video.

说的很清楚:加上duration 是防止文件时长给错,如果所有文件都加上,可以在合并的视频中seek。

这样就OK了,测试了seek也是ok的

上一篇下一篇

猜你喜欢

热点阅读