concat顧名思義,就是把多段視頻拼接播放,可以用于連續(xù)劇的連續(xù)播放埂淮。
configure配置:
--enable-demuxer=concat
--enable-protocol=concat
ijkplayer對(duì)應(yīng)修改
export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-protocol=concat"
export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-demuxer=concat"
總得來(lái)說(shuō)慨畸,只需要3步
- 建個(gè)文件, 命名為1.ffconcat
- 播放器地址:類似file:///sdcard/1.ffconcat
- 如果你的ffmpeg版本低于3.0左右蛛蒙, 可能要改ffmpeg的源碼
根據(jù)文檔精神糙箍,需要新建一個(gè)文件,命名為 1.ffconcat (當(dāng)然牵祟,也可以1.ffcat)
A list file with the suffix ".ffcat" or ".ffconcat" will auto-select this format.
1.ffconcat內(nèi)容:
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
這樣還是有問(wèn)題深夯,因?yàn)閟afe參數(shù)的原因:
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默認(rèn)是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這個(gè)函數(shù)被判斷返回0了诺苹,簡(jiǎn)單做法是把FAIL這行屏蔽掉咕晋,簡(jiǎn)單粗暴!
編譯驗(yàn)證ffmpeg3.1收奔,播放沒(méi)問(wèn)題掌呜。(ffmpeg3.1及以下都有這問(wèn)題,以上的沒(méi)驗(yàn)證過(guò))
有一點(diǎn)要注意:要加上duration坪哄,要不然播放的時(shí)候總的時(shí)長(zhǎng)和進(jìn)度會(huì)有問(wèn)題
參考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.
說(shuō)的很清楚:加上duration 是防止文件時(shí)長(zhǎng)給錯(cuò)质蕉,如果所有文件都加上,可以在合并的視頻中seek翩肌。
這樣就OK了模暗,測(cè)試了seek也是ok的