您好,欢迎来到二三四教育网。
搜索
您的当前位置:首页ijkplayer-ffmpeg之concat

ijkplayer-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
  • 播放器地址:类似file:///sdcard/1.ffconcat
  • 如果你的ffmpeg版本低于3.0左右, 可能要改ffmpeg的源码

根据文档精神,需要新建一个文件,命名为 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 
duration 48.8
file 
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的

Copyright © 2019- how234.cn 版权所有 赣ICP备2023008801号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务