a在线亚洲男人的天堂_男女做爽爽爽视频免费_曰本一级毛片高清视频_精品黑人AV免费观看

0712-2888027 189-8648-0214
微信公眾號

孝感風信網(wǎng)絡科技有限公司微信公眾號

當前位置:主頁 > 技術支持 > PHP > 視頻流使用FFmpeg將mp4視頻轉(zhuǎn)換為m3u8/ts文件

視頻流使用FFmpeg將mp4視頻轉(zhuǎn)換為m3u8/ts文件

時間:2024-10-01來源:風信官網(wǎng) 點擊: 8530次
風信建站新的開發(fā)項目中引用視頻流技術,為了有效解決大視頻在數(shù)據(jù)請求過程中加載過慢的問題,經(jīng)過多次測試,決定使用m3u8格式做為視頻流的格式,那么mp4和m3u8格式的視頻各有什么缺點和優(yōu)點呢?
 
mp4視頻格式有以下優(yōu)點:
 
1:跨平臺支持,即支持pc端和移動端(ios和安卓)。
2:該格式性能優(yōu)越。
 
mp4視頻的缺點:
 
1:視頻時間長度過長時,在移動端會消耗大量的流量,但隨著互聯(lián)網(wǎng)流量資費的發(fā)展(將來流量是包月/年的,每月交一定費用,流量無限使用。)該缺點將不再存在。
2:視頻文件相對大一些。對于服務器的空間占用方面會有一定壓力。
 
視頻本身的要求
1:視頻轉(zhuǎn)碼格式需要是h.264
2:音頻轉(zhuǎn)碼格式需要是AAC
3:如果考慮到需要支持在PC端低版本IE(IE9及以下)的環(huán)境中(在該環(huán)境中只能使用flashplayer播放)支持視頻請求未下載到用戶本地緩存區(qū)的內(nèi)容播放。則需要視頻本身存在關鍵幀和關鍵時間點(服務器方面也有要求)。
 
m3u8的優(yōu)點:
 
1:因為視頻被切成多個.ts文件,所以不需要考慮元數(shù)據(jù)的問題,并且可以分段加載。
2:在PC端使用flashplayer播放時可以實現(xiàn)視頻的絕對加密。也就是視頻即使是被下載到用戶本地也無法使用。
 
m3u8的缺點
 
正常情況下不支持PC端的播放。ckplayer做了兼容是支持在pc端播放的,前提是pc端瀏覽器需要支持flashplayer
 
使用m3u8我們需要將mp4視頻進行轉(zhuǎn)碼,命令如下:
 
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_pro\wwwroot\ebiaoip-v\public>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
 
轉(zhuǎn)碼成功之后就可以在播放器中使用,加載速度快多啦!

視頻流使用FFmpeg將mp4視頻轉(zhuǎn)換為m3u8/ts文件
視頻流使用FFmpeg將mp4視頻轉(zhuǎn)換為m3u8/ts文件
 
如需網(wǎng)站開發(fā)、微信開發(fā),接口開發(fā),建站功能定制開發(fā),歡迎致電風信網(wǎng)絡,電話:189-8648-0214(微信同號)
欄目列表
推薦內(nèi)容
熱點內(nèi)容
展開