HLS合成为一整个视频拓展篇

2021-04-13 15:15:43 浏览数 (1)

M3U8视频下载完成之后, 会有一个索引文件加上N多个分片文件, 这样我们想拷贝整个M3U8文件就会很麻烦, 而且M3U8索引文件中会定义分片文件的位置, 如果是相对地址还好, 如果是绝对地址那拷贝出来也不能用.

我们能不能将分散的M3U8分片文件合成一整个MP4文件, 这样我也可以拷贝, 也可以分享.

具体的做法可以参考:M3U8-TS文件合并为MP4文件, 我这儿就不赘述了, 这儿主要分享一下合并过程中出现的一些坑, 希望对大家解决问题有帮助.

  • 1.加密的M3U8视频如何合并
  • 2.M3U8视频dts非连续增长导致的合并失败问题
  • 3.怎么接入VideoDownloader
1.加密的M3U8视频如何合并

举一个加密视频的例子: https://europe.olemovienews.com/hlstimeofffmp4/20210226/fICqcpqr/mp4/fICqcpqr.mp4/master.m3u8

解析出来的索引文件如下:

代码语言:javascript复制
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:6.0
#EXT-X-KEY:METHOD=AES-128,URI="https://www.qzamfz.com/20190710/BjhH5Ffw/key.key"
#EXTINF:5.110089,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw000.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw001.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw002.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw003.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw004.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw005.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw006.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw007.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw008.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw009.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw010.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw011.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw012.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw013.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw014.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw015.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw016.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw017.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw018.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw019.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw020.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw021.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw022.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw023.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw024.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw025.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw026.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw027.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw028.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw029.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw030.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw031.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw032.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw033.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw034.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw035.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw036.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw037.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw038.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw039.ts
#EXTINF:5.005333,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw040.ts
#EXTINF:4.755067,
https://www.qzamfz.com/20190710/BjhH5Ffw/BjhH5Ffw041.ts
#EXT-X-ENDLIST

有#EXT-X-KEY字段, 说明视频加密了, 下载到本地时的索引文件如下:

代码语言:javascript复制
130|PD1824:/sdcard/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec # ls
e546f6e1e7a649e93be7cf705a9af9ec_local.m3u8 video_1.ts  video_13.ts video_17.ts video_20.ts video_24.ts video_28.ts video_31.ts video_35.ts video_39.ts video_5.ts video_9.ts 
local.key                                   video_10.ts video_14.ts video_18.ts video_21.ts video_25.ts video_29.ts video_32.ts video_36.ts video_4.ts  video_6.ts 
remote.m3u8                                 video_11.ts video_15.ts video_19.ts video_22.ts video_26.ts video_3.ts  video_33.ts video_37.ts video_40.ts video_7.ts 
video_0.ts                                  video_12.ts video_16.ts video_2.ts  video_23.ts video_27.ts video_30.ts video_34.ts video_38.ts video_41.ts video_8.ts

其中e546f6e1e7a649e93be7cf705a9af9ec_local.m3u8本地索引文件如下:

代码语言:javascript复制
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:6.0
#EXT-X-KEY:METHOD=AES-128,URI="/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/local.key"
#EXTINF:5.110089,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_0.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_1.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_2.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_3.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_4.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_5.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_6.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_7.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_8.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_9.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_10.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_11.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_12.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_13.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_14.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_15.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_16.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_17.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_18.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_19.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_20.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_21.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_22.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_23.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_24.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_25.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_26.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_27.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_28.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_29.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_30.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_31.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_32.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_33.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_34.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_35.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_36.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_37.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_38.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_39.ts
#EXTINF:5.005333,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_40.ts
#EXTINF:4.755067,
/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_41.ts
#EXT-X-ENDLIST

连密钥都存储到本地了, 直接将e546f6e1e7a649e93be7cf705a9af9ec_local.m3u8合并为MP4文件的时候, 出现如下的报错:

代码语言:javascript复制
2021-03-17 14:02:46.612 18038-18077/com.jeffmony.videodemo I/FFmpeg_JeffMony: Input_path=/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/e546f6e1e7a649e93be7cf705a9af9ec_local.m3u8, Output_path=/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/e546f6e1e7a649e93be7cf705a9af9ec_merged.mp4
2021-03-17 14:02:46.615 18038-18077/com.jeffmony.videodemo E/FFmpeg_JeffMony: Filename extension of '/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/local.key' is not a common multimedia extension, blocked for security reasons.
    If you wish to override this adjust allowed_extensions, you can set it to 'ALL' to allow all
2021-03-17 14:02:46.615 18038-18077/com.jeffmony.videodemo E/FFmpeg_JeffMony: Unable to open key file /storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/local.key
2021-03-17 14:02:46.615 18038-18077/com.jeffmony.videodemo I/FFmpeg_JeffMony: Opening 'crypto:/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_0.ts' for reading
2021-03-17 14:02:46.688 18038-18077/com.jeffmony.videodemo I/FFmpeg_JeffMony: Opening 'crypto:/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_1.ts' for reading
2021-03-17 14:02:46.735 18038-18077/com.jeffmony.videodemo E/FFmpeg_JeffMony: Error when loading first segment '/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/video_0.ts'
2021-03-17 14:02:46.735 18038-18077/com.jeffmony.videodemo E/FFmpeg_JeffMony: Could not open input file '/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec/e546f6e1e7a649e93be7cf705a9af9ec_local.m3u8'
2021-03-17 14:02:46.735 18038-18077/com.jeffmony.videodemo E/FFmpeg_JeffMony: Error occurred: Invalid data found when processing input

解析HLS视频的时候密钥不支持本地密钥, 这也是为了安全考虑, 对应ffmpeg=====>hls.c

主要是ffmpeg没有放开所有的protocol解析器,这也是为了安全考虑, 我们直接注释掉这个代码, 就可以合并成MP4视频了.

代码语言:javascript复制
PD1824:/sdcard/Android/data/com.jeffmony.videodemo/files/Video/Download/e546f6e1e7a649e93be7cf705a9af9ec # ls -al
total 28364
drwxrwx--x 2 u0_a391 sdcard_rw     4096 2021-03-17 18:07 .
drwxrwx--x 3 u0_a391 sdcard_rw     4096 2021-03-17 17:58 ..
-rw-rw---- 1 u0_a391 sdcard_rw 29021305 2021-03-17 18:07 e546f6e1e7a649e93be7cf705a9af9ec_merged.mp4

生成的确实是MP4视频, 但是MOOV头部在后面, 不影响播放.

2.M3U8视频dts非连续增长导致的合并失败问题

https://europe.olemovienews.com/hlstimeofffmp4/20210226/fICqcpqr/mp4/fICqcpqr.mp4/master.m3u8 视频是包含#EXT-X-MAP字段的视频, 说明有一个初始化的片段全局复用, 这种情况下就会检测出dts不是连续增长的, 出现下面的问题:

代码语言:javascript复制
2021-03-17 15:05:52.692 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: Input_path=/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/eba1ec20a933910678da79dbc507ea46/eba1ec20a933910678da79dbc507ea46_local.m3u8, Output_path=/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/eba1ec20a933910678da79dbc507ea46/eba1ec20a933910678da79dbc507ea46_merged.mp4
2021-03-17 15:05:52.696 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: Opening '/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/eba1ec20a933910678da79dbc507ea46/init_video_0.mp4' for reading
2021-03-17 15:05:52.696 20070-20114/com.jeffmony.videodemo E/FFmpeg_JeffMony: Could not read complete segment.
2021-03-17 15:05:52.697 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: Opening '/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/eba1ec20a933910678da79dbc507ea46/video_0.m4s' for reading
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: Index=2, duration=2719839994
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: Input #1, hls,applehttp, from '/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/eba1ec20a933910678da79dbc507ea46/eba1ec20a933910678da79dbc507ea46_local.m3u8':
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:   Duration: 
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: 00:45:19.84
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: , start: 
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: 0.000000
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: , bitrate: 
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: 0 kb/s
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:   Program 0 
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:     Metadata:
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:       variant_bitrate : 
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: 0
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:     Stream #1:0
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: : Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 12 kb/s
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: , 
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: 25 fps, 
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: 25 tbr, 
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: 90k tbn, 
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: 50 tbc
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:     Metadata:
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:       variant_bitrate : 
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: 0
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:       major_brand     : 
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: isom
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:       minor_version   : 
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: 1
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:       compatible_brands: 
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: isomavc1
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:     Stream #1:1
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: : Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 0 kb/s
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:     Metadata:
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:       variant_bitrate : 
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: 0
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: Output format=mp4
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: Output #0, mp4, to '/storage/emulated/0/Android/data/com.jeffmony.videodemo/files/Video/Download/eba1ec20a933910678da79dbc507ea46/eba1ec20a933910678da79dbc507ea46_merged.mp4':
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:     Stream #0:0
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: : Video: h264, yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 12 kb/s
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony:     Stream #0:1
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: : Audio: aac, 48000 Hz, stereo, fltp, 0 kb/s
2021-03-17 15:05:52.720 20070-20114/com.jeffmony.videodemo I/FFmpeg_JeffMony: Open output file
2021-03-17 15:05:52.721 20070-20114/com.jeffmony.videodemo E/FFmpeg_JeffMony: Application provided invalid, non monotonically increasing dts to muxer in stream 1: 11264 >= 0
2021-03-17 15:05:52.721 20070-20114/com.jeffmony.videodemo E/FFmpeg_JeffMony: Error muxing packet
2021-03-17 15:05:52.721 20070-20114/com.jeffmony.videodemo E/FFmpeg_JeffMony: Error occurred: Invalid argument
2021-03-17 15:05:52.721 20070-20114/com.jeffmony.videodemo I/VideoProcessManager: VideoMerge mergeTs result=-1
2021-03-17 15:05:52.722 20070-20114/com.jeffmony.videodemo I/VideoDownloadManager: VideoMerge onMergeFailed e=java.lang.Exception: Merge ts failed

其中关键的一行是:

代码语言:javascript复制
2021-03-17 15:05:52.721 20070-20114/com.jeffmony.videodemo E/FFmpeg_JeffMony: Application provided invalid, non monotonically increasing dts to muxer in stream 1: 11264 >= 0

对应ffmpeg====>mux.c中的compute_muxer_pkt_fields函数:

本质原因是视频的时间戳出现问题了, 如果视频的时间戳并不是连续递增的, 会导致合成视频的时候出现检测异常, 认为当前的视频已经遭到破坏了, 这种情况下不太建议直接注释调这个代码, 还是建议调整一下源视频的时间戳.

3.怎么接入VideoDownloader

VideoDownloader是一个非常强大的视频下载SDK

  • 1.支持下载HLS视频/非HLS视频
  • 2.支持并发任务下载
  • 3.支持线程池动态调整策略
  • 4.支持HLS众多特性: #EXT-X-KEY / #EXT-X-MAP等
  • 5.支持下载百分比/下载速度/下载大小等提示
  • 6.支持数据库同步
  • 7.支持一系列下载成功率的优化措施
  • 8.支持HLS下载成功之后合并为MP4视频
  • 9.支持下载完成之后播放视频

如果你有什么其他的需求, 可以在评论区留言.

VideoDownloader最新版本已经升级到5.0.0 具体的接入方式请参考:

https://github.com/JeffMony/VideoDownloader

0 人点赞