HLS公開課(五)HLS合成爲一整個視頻

M3U8視頻下載完成以後, 會有一個索引文件加上N多個分片文件, 這樣咱們想拷貝整個M3U8文件就會很麻煩, 並且M3U8索引文件中會定義分片文件的位置, 若是是相對地址還好, 若是是絕對地址那拷貝出來也不能用.java

咱們能不能將分散的M3U8分片文件合成一整個MP4文件, 這樣我也能夠拷貝, 也能夠分享.git

具體的作法能夠參考: M3U8-TS文件合併爲MP4文件, 我這兒就不贅述了, 這兒主要分享一下合併過程當中出現的一些坑, 但願對你們解決問題有幫助.github

1.加密的M3U8視頻如何合併

舉一個加密視頻的例子: europe.olemovienews.com/hlstimeofff… 解析出來的索引文件以下:數據庫

#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字段, 說明視頻加密了, 下載到本地時的索引文件以下:安全

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本地索引文件以下:markdown

#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文件的時候, 出現以下的報錯:併發

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視頻了.app

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頭部在後面, 不影響播放.ide

2.M3U8視頻dts非連續增加致使的合併失敗問題

europe.olemovienews.com/hlstimeofff…, 說明有一個初始化的片斷全局複用, 這種狀況下就會檢測出dts不是連續增加的, 出現下面的問題:函數

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
複製代碼

其中關鍵的一行是:

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 具體的接入方式請參考: github.com/JeffMony/Vi…

相關文章
相關標籤/搜索