视频流使用FFmpeg将mp4视频转换为m3u8/ts文件
风信建站新的开发项目中引用视频流技术,为了有效解决大视频在数据请求过程中加载过慢的问题,经过多次测试,决定使用m3u8格式做为视频流的格式,那么mp4和m3u8格式的视频各有什么缺点和优点呢?
mp4视频格式有以下优点:
1:跨平台支持,即支持pc端和移动端(ios和安卓)。
2:该格式性能优越。
mp4视频的缺点:
1:视频时间长度过长时,在移动端会消耗大量的流量,但随着互联网流量资费的发展(将来流量是包月/年的,每月交一定费用,流量无限使用。)该缺点将不再存在。
2:视频文件相对大一些。对于服务器的空间占用方面会有一定压力。
视频本身的要求
1:视频转码格式需要是h.264
2:音频转码格式需要是AAC
3:如果考虑到需要支持在PC端低版本IE(IE9及以下)的环境中(在该环境中只能使用flashplayer播放)支持视频请求未下载到用户本地缓存区的内容播放。则需要视频本身存在关键帧和关键时间点(服务器方面也有要求)。
m3u8的优点:
1:因为视频被切成多个.ts文件,所以不需要考虑元数据的问题,并且可以分段加载。
2:在PC端使用flashplayer播放时可以实现视频的绝对加密。也就是视频即使是被下载到用户本地也无法使用。
m3u8的缺点
正常情况下不支持PC端的播放。ckplayer做了兼容是支持在pc端播放的,前提是pc端浏览器需要支持flashplayer
使用m3u8我们需要将mp4视频进行转码,命令如下:
ffmpeg -i 2.mp4 -codec copy -vbsf h264_mp4toannexb -map 0 -f segment -segment_list m3u8/2.m3u8 -segment_time 10 m3u8/out%03d.ts
G:phpstudy_prowwwrootebiaoip-vpublic>ffmpeg -i 2.mp4 -codec copy -vbsf h264_
mp4toannexb -map 0 -f segment -segment_list m3u8/2.m3u8 -segment_time 10 m3u8/ou
t%03d.ts
ffmpeg version n4.3.1-23-gc19641b2e2 Copyright (c) 2000-2020 the FFmpeg develope
rs
built with gcc 9.3-win32 (GCC) 20200320
configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-conf
ig=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw
32 --enable-gpl --enable-version3 --disable-debug --enable-iconv --enable-zlib -
-enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-l
zma --enable-fontconfig --enable-opencl --enable-libvmaf --disable-vulkan --enab
le-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --
enable-libdavs2 --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --ena
ble-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libt
heora --enable-libvpx --enable-libwebp --enable-libmfx --enable-libopencore-amrn
b --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-lib
rubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --en
able-libtwolame --enable-libvidstab --enable-libx264 --enable-libx265 --enable-l
ibxavs2 --enable-libxvid --enable-libzimg --extra-cflags=-DLIBTWOLAME_STATIC --e
xtra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.58.101
Duration: 00:04:10.13, start: 0.000000, bitrate: 161 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x368 [
SAR 1:1 DAR 40:23], 107 kb/s, 20 fps, 20 tbr, 10240 tbn, 80 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, flt
p, 48 kb/s (default)
Metadata:
handler_name : SoundHandler
[segment @ 00000000004b8d00] Opening 'm3u8/out000.ts' for writing
Output #0, segment, to 'm3u8/out%03d.ts':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x368 [
SAR 1:1 DAR 40:23], q=2-31, 107 kb/s, 20 fps, 20 tbr, 90k tbn, 40 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, flt
p, 48 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out001.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out002.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out003.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out004.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out005.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out006.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out007.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out008.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out009.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out010.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out011.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out012.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out013.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out014.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out015.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out016.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out017.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out018.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/out019.ts' for writing
[segment @ 00000000004b8d00] Opening 'm3u8/2.m3u8.tmp' for writing
frame= 4996 fps=0.0 q=-1.0 Lsize=N/A time=00:04:10.09 bitrate=N/A speed=1.44e+03
x
video:3274kB audio:1468kB subtitle:0kB other streams:0kB global headers:0kB muxi
ng overhead: unknown
转码成功之后就可以在播放器中使用,加载速度快多啦!
如需网站开发、微信开发,接口开发,建站功能定制开发,欢迎致电风信网络,电话:189-8648-0214(微信同号)
上一篇:原创薛之谦最“羞耻”的一首歌,女装大佬都自愧不如,谦友:单曲循环
下一篇:2016年国产烂片泛滥 IP电影成走点心行么
最近更新娱乐资讯
- 获奖影评赏析|《阿丽塔·战斗天使》
- 人生必看十部好看的纪录片(十部必看的现实主义纪录片)
- 日本十大禁欲动漫盘点:唯美霸道下的污镜头
- 墨西哥大麻即将合法化,美媒:美国夹在两个“卖大麻的邻居”之间
- “和合”文化背景下昭君文化的价值生成
- 马来酸阿法替尼片人体生物等效性试验
- 原创《满城尽带黄金甲》:喧哗与沉静的戏台,道德与伦理的悲歌
- 裴旖旎
- 隐适美附件又掉了,从第一天掉了2颗,第二天掉了1颗,今晚我还戴牙套吗?
- 电视剧《最美的青春》:好作品是如何炼就的
- 狗头萝莉出摊卖煎饼大家怎么看?
- 记者的职业伦理:我该何时放下相机
- 绝命毒师电影,「蚁人」改造DNA,首部Netflix华语剧...10月流媒体片单
- 这是一部非常独特的「成人动画」,少儿不宜
- 高分电影推荐!六部直击人性黑暗面的韩国片!部部引人深省!
- 2022天津解放军464医院整形美容中心整形价格表(价目表)全新发布
- 精 [电影推荐]一再婚女人因拯救女儿,让两个家庭面临人性考验,此电影令人感动
- 缓冲晶体溶液与生理盐水对重症监护病房患者急性肾损伤的影响:SPLIT随机临床试验
- 未成年人千万别看这部片子,简直太变态了!!!
- 生态在文学中的位置
- 与3800多名女性发生过关系,世界小电影之王,终于那啥了
- 新加坡电影《爸妈不在家》爆冷获多项金马奖
- 调查称52%受访者认为国产电影色情暴力问题严重
- 红楼梦初中读书笔记
- 家庭伦理剧,小品剧本《家庭矛盾》