日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HLS协议及java切片相关

發(fā)布時間:2025/7/25 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HLS协议及java切片相关 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

http://blog.csdn.net/cjsafty/article/details/7922849


簡介:HTTP Live Streaming(縮寫是 HLS)是一個由蘋果公司提出的基于HTTP的流媒體 網絡傳輸協(xié)議。

是蘋果公司QuickTime X和iPhone軟件系統(tǒng)的一部分。它的工作原理是把整個流分成一個個小的基于HTTP

的文件來下載,每次只下載一些。當媒體流正在播放時,客戶端可以選擇從許多不同的備用源中以不同的速

率下載同樣的資源,允許流媒體會話適應不同的數(shù)據速率。在開始一個流媒體會話時,客戶端會下載一個包

含元數(shù)據的extended M3U (m3u8) playlist文件,用于尋找可用的媒體流。


HLS只請求基本的HTTP報文,與實時傳輸協(xié)議(RTP)不同,HLS可以穿過任何允許HTTP數(shù)據通過的防

火墻或者代理服務器。它也很容易使用內容分發(fā)網絡來傳輸媒體流。

此協(xié)議詳細內容請參考apple官方網站:https://developer.apple.com/resources/http-streaming/

有兩種方式搭建HLSserver,

一種是利用apple SDK,

一種是利用adobe 的fms,4.5版本支持hls,參考,

http://www.adobe.com/products/flash-media-streaming/features._sl_id-contentfilter_sl_featuredisplaytypes_sl_new.html

adobe的fms現(xiàn)在很強大,但是商用需要licence。有興趣的可以研究下。

一種是利用opensouce.我比較喜歡這一種。

?

方法:

opensource的方法主要是使用m3u8-segmenter+ffmpeg對ts文件進行分片。

因此思路就是:

1,用編譯好的ffmpeg制作所需要的ts文件,

2,安裝libavformat-dev版本,

3,編譯m3u8-segmenter,

4,部署到nginx

5,高級功能,流切換

6,頁面

過程

1,本來想下載ffmpeg源碼編譯,但是因為要涉及到faac,x264,lame庫。有時候ffmpeg版本對這些庫的版本又有最低版本要求,在編譯

faac時候遇到以下問題

[plain] view plaincopy
  • 安裝支持庫??
  • apt-get?install?automake?autoconf?m4?libtool??
  • ??
  • -bash:?./bootstrap:?/bin/sh^M:?bad?interpreter:?No?such?file?or?directory??
  • ??
  • 轉換字符:??
  • dos2unix?bootstrap??
  • make??
  • ??
  • 錯誤:mpeg4ip.h:126:58:?error:?new?declaration?‘char*?strcasestr(const?char*,?const?char*)’??
  • ??
  • 解決方法:Remove?line?126?containing?strcasecmp?from?mpeg4ip.h?as?a?temporary?workaround??
  • ??
  • make?install時遇到??
  • usr/local/share/man/man1文件夾無法創(chuàng)建問題。??

  • 最后一個問題無法解決,好像是Linux(ubuntu)下同一個目錄下,如果已經有一個文件了,則不能創(chuàng)建同名文件夾,遂放棄編譯,

    直接從ffmpeg網站:http://ffmpeg.org/download.html ,的linux下載頁面下載編譯好ffmpeg靜態(tài)文件。這個靜態(tài)文件的主要目的是

    為了把各種文件轉換成apple所規(guī)定的文件。所以需要AAC,mp3,x264庫支持。


    或者干脆按照2的方法。apt-get install ffmpeg.這樣會得到ffmpeg可行性文件。


    2,安裝ffmpeg支持庫,主要用于編譯m3u8-segmenter,這里的ffmpeg支持庫,其目的是給segmenter提供libavformat支持。不涉及編解碼。

    apt-get install libavformat-dev.

    [plain] view plaincopy
  • Reading?package?lists...?Done??
  • Building?dependency?tree?????????
  • Reading?state?information...?Done??
  • The?following?extra?packages?will?be?installed:??
  • ??libavcodec-dev?libavcodec53?libavformat53?libavutil-dev?libavutil51?libgsm1?libogg0?liborc-0.4-0??
  • ??libschroedinger-1.0-0?libspeex1?libtheora0?libva1?libvorbis0a?libvorbisenc2?libvpx1??
  • Suggested?packages:??
  • ??libfaad-dev?libgsm1-dev?libogg-dev?libschroedinger-dev?libspeex-dev?libtheora-dev?libvorbis-dev?libx11-dev??
  • ??libxext-dev?libraw1394-dev?libdc1394-22-dev?speex??
  • The?following?NEW?packages?will?be?installed:??
  • ??libavcodec-dev?libavcodec53?libavformat-dev?libavformat53?libavutil-dev?libavutil51?libgsm1?libogg0?liborc-0.4-0??
  • ??libschroedinger-1.0-0?libspeex1?libtheora0?libva1?libvorbis0a?libvorbisenc2?libvpx1??

  • 這樣會自動安裝ffmepg幾個相關庫。


    3,從https://github.com/johnf/m3u8-segmenter?下載m3u8-segmenter

    下載后不要用它的反復編譯,直接取m3u8-segmenter.c文件,

    [plain] view plaincopy
  • gcc?-Wall?-g?segmenter.c?-o?segmenter?-lavformat??
  • 從源碼來看,因為只用到了avformat庫,所以只鏈接這一個即可。生成segmenter文件,用help命令,可以看到已經成功。

    [plain] view plaincopy
  • HTTP?Live?Streaming?-?Segments?TS?file?and?creates?M3U8?index.??
  • ????????-i,?--input?FILE?????????????TS?file?to?segment?(Use?-?for?stdin)??
  • ????????-d,?--duration?SECONDS???????Duration?of?each?segment?(default:?10?seconds)??
  • ????????-p,?--output-prefix?PREFIX???Prefix?for?the?TS?segments,?will?be?appended??
  • ?????????????????????????????????????with?-1.ts,?-2.ts?etc??
  • ????????-m,?--m3u8-file?FILE?????????M3U8?output?filename??
  • ????????-u,?--url-prefix?PREFIX??????Prefix?for?web?address?of?segments,?e.g.?http://example.org/video/??
  • ????????-n,?--num-segment?NUMBER?????Number?of?segments?to?keep?on?disk??
  • ????????-h,?--help???????????????????This?help??

  • 從上圖來看,語法很簡單,這里貼一個我用的。 [plain] view plaincopy
  • ./segmenter?-i?test.ts?-n?30?-p?sample_test?-m?stream-test.m3u8?-u?http://192.168.1.10:8080/hls/??

  • i表示輸入文件,n表示切割30個,p表示切割文件的前綴。m表示生成的m3u8文件名,u表示這些切割后的文件處于web server的哪個目錄下,這個一定要和web目錄匹配


    4,部署到nginx。

    nginx的相關部署我在前兩個博客中已經詳細說明,這里在jwplayer博客的基礎上部署hls。

    1)目錄問題:

    在html/jwplayer目錄下,建立hls文件夾,將m3u8文件和切割后的全部ts文件拷貝到此目錄下,

    在VLC PLAYER或者ipad safie瀏覽器或者在ffplayer(我用的是0.11版本的windows編譯版本)

    上的訪問路徑應該是http://192.168.1.10:8080/hls/stream-test.m3u8

    2)文件類型問題:編輯?/usr/local/nginx/conf/mime.types 文件,添加如下類型

    [plain] view plaincopy
  • application/x-mpegURL?????????????????m3u8;??
  • video/MP2T?????????????????????????????ts;???

  • 3)重啟nginx?

    輸入上述路徑,你應該就看到視頻了。


    5,高級功能,流切換

    上述m3u8文件,只有一個流,不具備流切換功能。在優(yōu)酷上,如果是ipad客戶端,可以看到有標清,高清,超清的按鈕,其實那個是對應著不同標準

    的(單個)m3u8文件,來實現(xiàn)流切換的,不知道apple是不是這樣做的,apple好像是要求“智能”流切換。即不要求用戶去選擇,而是根據網絡狀況自適應的。

    apple給的sample的流切換是把各個流的m3u8寫在一個m3u8文件里實現(xiàn)的。

    類似于這樣,其實原理是一樣的。

    [plain] view plaincopy
  • #EXTM3U??
  • #EXT-X-STREAM-INF:PROGRAM-ID=1,?BANDWIDTH=100000??
  • video1/index1.m3u8??
  • #EXT-X-STREAM-INF:PROGRAM-ID=1,?BANDWIDTH=200000??
  • video2/index2.m3u8??


  • 6,頁面,

    如果再繼續(xù)搭建一個頁面,把上述地址嵌在頁面里面,這樣配合CSS就比較美觀了。頁面可以在這個基礎上,用webpy去做。



    頁面參考:

    蘋果開發(fā)網:https://developer.apple.com/resources/http-streaming/

    博客:http://www.nginxs.com/linux/459.html

    ffmpeg開發(fā)網:http://ffmpeg.org/download.html

    segmenter源碼:https://github.com/johnf/m3u8-segmenter

    adboe fms介紹:http://www.adobe.com/products/flash-media-streaming/features._sl_id-contentfilter_sl_featuredisplaytypes_sl_new.html


    ?

    2014.02備注:

    文中所描述的切片軟件可能有問題,可選擇這個

    https://code.google.com/p/httpsegmenter/downloads/list



    說明:在寫這篇文章時不知道查了多少資料不是資料不完整就是根本不能安裝,網上許多資料都是轉載。寫這篇文章時我親自做了測試,安裝完全通過,如果有什么不對的地方歡迎拍磚?
    一、安裝ffmpeg?
    操作系統(tǒng):centos 5.6?
    (一)安裝編譯環(huán)境?
    #yum install -y automake autoconf libtool gcc gcc-c++??
    (二)安裝所需程序庫的RPM包到 centos(因為centos自帶的庫中沒有ffmpeg包,這里相當于是擴展)?
    view plaincopy to clipboardprint??
    #rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm??
    如果上面的代碼執(zhí)行失敗,你可以在本站下載,然后安裝這個rpm包。?
    (三)安裝 Install ffmpeg 等模塊?
    yum -y install ffmpeg ffmpeg-devel


    CentOS yum方式安裝ffmpeg

    時間?2013-08-12 18:37:10??天使羊波波閃耀光芒原文??http://www.live-in.org/archives/1860.html

    系統(tǒng)為CentOS 6.4,自己編譯ffmpeg和眾多解碼器太痛苦了,yum方式安裝ffmpeg的解碼器很全,先用用看。

    1、安裝所需軟件?

    yum install -y automake autoconf libtool gcc gcc-c++

    2、安裝第三方更新源?

    rpm -ivh http://apt.sw.be/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.3-1.el6.rf.i686.rpm

    3、安裝ffmpeg?

    yum install ffmpeg ffmpeg-devel

    會自動安裝眾多解碼器,ffmpeg版本為0.6.5-1.el6.rf。看了下yum安裝的解碼器版本還不是很舊,但是ffmpeg版本較老。

    4、測試一下?
    將一個.avi視屏轉為.flv格式?

    ffmpeg -i Destination.avi -y -ab 56 -ar 22050 -r 15 -sameq test2.flv

    轉換前后兩個文件的格式比較:


    轉換前

    Destination.avi
    ?? General
    ????? Complete name : E:\PV\Destination.avi
    ????? Format : AVI
    ????? Format/Info : Audio Video Interleave
    ????? Format/Family : RIFF
    ????? File size : 79.5 MiB
    ????? PlayTime : 4mn 1s
    ????? Bit rate : 2754 Kbps
    ????? StreamSize : 469 KiB
    ????? Subject : doobie (2007)
    ????? Writing application : VirtualDubMod 1.5.10.2 (build 2540/release)
    ????? Writing library : VirtualDubMod build 2540/release
    ?? Video #0
    ????? Codec : XviD
    ????? Codec/Family : MPEG-4
    ????? Codec/Info : XviD project
    ????? Codec profile : Streaming Video Profile/Level 1
    ????? Codec settings/PacketBitStream : Yes
    ????? Codec settings/BVOP : Yes
    ????? Codec settings/QPel : No
    ????? Codec settings/GMC : 0
    ????? Codec settings/Matrix : Default
    ????? PlayTime : 4mn 1s
    ????? Bit rate : 2556 Kbps
    ????? Width : 640 pixels
    ????? Height : 480 pixels
    ????? Display Aspect ratio : 4/3
    ????? Frame rate : 29.976 fps
    ????? Resolution : 8 bits
    ????? Chroma : 4:2:0
    ????? Interlacement : Progressive
    ????? Bits/(Pixel*Frame) : 0.277
    ????? StreamSize : 73.5 MiB
    ?? Audio #1
    ????? Codec : MPEG-1 Audio layer 3
    ????? Codec profile : Joint stereo
    ????? PlayTime : 4mn 1s
    ????? Bit rate : 190 Kbps
    ????? Bit rate mode : CBR
    ????? Channel(s) : 2 channels
    ????? Sampling rate : 48 KHz
    ????? Resolution : 16 bits
    ????? StreamSize : 5.47 MiB
    ????? Writing library : Gogo (after 3.0)


    轉換后

    test2.flv
    ?? General
    ????? Complete name : E:\PV\test2.flv
    ????? Format : Flash Video
    ????? File size : 45.0 MiB
    ????? PlayTime : 4mn 1s
    ????? Bit rate : 1564 Kbps
    ?? Video
    ????? Codec : Sorenson H263
    ????? PlayTime : 4mn 1s
    ????? Bit rate : 195 Kbps
    ????? Width : 640 pixels
    ????? Height : 480 pixels
    ????? Display Aspect ratio : 4/3
    ????? Frame rate : 15.000 fps
    ????? Bits/(Pixel*Frame) : 0.042
    ?? Audio
    ????? Codec : MPEG-1 Audio Layer 3
    ????? Bit rate : 55 bps
    ????? Channel(s) : 2 channels
    ????? Sampling rate : 22 KHz
    ????? Resolution : 16 bits

    參考資料:

    http://www.rosoo.net/a/201205/16001.html

    分類:?LINUX?發(fā)表評論


    • CentOS編譯安裝ffmpeg以及相關編碼解碼器

      CentOS編譯安裝ffmpeg是一件很痛苦的過程,因為各種編碼器、解碼器什么的很繁雜,而且相互依賴關系更復雜。

      編譯了一天終于把它搞定并基本測試無問題,以下是步驟。

      安裝yasm

      wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
      tar zxf yasm-1.2.0.tar.gz
      cd yasm-1.2.0
      ./configure
      make
      make install

      安裝frei0r(先安裝新版autoconf,這會覆蓋掉系統(tǒng)中的舊版本哦)

      wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
      tar zxf autoconf-2.69.tar.gz
      cd autoconf-2.69
      ./configure –prefix=/usr
      make
      make install

      wget http://files.dyne.org/frei0r/releases/frei0r-plugins-1.4.tar.gz
      tar zxf frei0r-plugins-1.4.tar.gz
      cd frei0r-plugins-1.4
      ./configure
      make
      make install

      安裝gnutls

      參考:http://blog.creke.net/800.html

      安裝mp3lame

      wget http://iweb.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
      tar zxf lame-3.99.5.tar.gz
      cd lame-3.99.5
      make
      make install

      安裝opencore-amr

      wget http://iweb.dl.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.3.tar.gz
      tar zxf opencore-amr-0.1.3.tar.gz
      ./configure –enable-shared
      make
      make install

      安裝opus

      wget http://downloads.xiph.org/releases/opus/opus-1.0.2.tar.gz
      tar zxf opus-1.0.2.tar.gz
      cd opus-1.0.2
      make
      make install

      安裝rtmpdump

      wget http://rtmpdump.mplayerhq.hu/download/rtmpdump-2.3.tgz
      tar zxf rtmpdump-2.3.tgz
      cd rtmpdump-2.3
      make
      make install

      安裝schroedinger(先安裝好orc庫)

      wget http://code.entropywave.com/download/orc/orc-0.4.17.tar.gz
      tar zxf orc-0.4.17.tar.gz
      cd orc-0.4.17
      ./configure
      make
      make install
      /sbin/ldconfig

      wget http://diracvideo.org/download/schroedinger/schroedinger-1.0.11.tar.gz
      tar zxf schroedinger-1.0.11.tar.gz
      cd schroedinger-1.0.11
      PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig ./configure
      make
      make install

      安裝soxr(注:新版libsoxr貌似與當前ffmpeg不兼容,用舊版)

      yum install -y xz
      wget http://hivelocity.dl.sourceforge.net/project/soxr/soxr-0.1.0-Source.tar.xz
      xz -d soxr-0.1.0-Source.tar.xz
      tar xf soxr-0.1.0-Source.tar
      cd soxr-0.1.0-Source
      ./go
      cd Release/
      make
      make install
      /sbin/ldconfig

      安裝speex(先安裝libogg庫)

      wget http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
      tar zxf libogg-1.3.0.tar.gz
      ./configure
      make
      make install
      /sbin/ldconfig

      wget http://downloads.xiph.org/releases/speex/speex-1.2rc1.tar.gz
      tar zxf speex-1.2rc1.tar.gz
      cd speex-1.2rc1
      ./configure
      make
      make install

      安裝theora(先安裝好libvorbis庫和libsdl庫)

      wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz
      tar zxf libvorbis-1.3.3.tar.gz
      ./configure
      make
      make install

      wget http://www.libsdl.org/release/SDL-1.2.15.tar.gz
      tar zxf SDL-1.2.15.tar.gz
      cd SDL-1.2.15
      ./configure
      make
      make install
      /sbin/ldconfig

      wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.bz2
      tar zjf libtheora-1.1.1.tar.bz2
      ./configure
      make
      make install

      安裝twolame

      wget http://downloads.sourceforge.net/twolame/twolame-0.3.13.tar.gz
      tar zxf twolame-0.3.13
      .tar.gz
      cd twolame-0.3.13
      ./configure
      make
      make install
      /sbin/ldconfig

      安裝VisualOn AAC(注:github的tag和master版均無法autoconf,用zeranoe版代替)

      wget wget http://ffmpeg.zeranoe.com/builds/source/external_libraries/vo-aacenc-0.1.2.tar.xz
      xz -d vo-aacenc-0.1.2.tar.xz
      tar xf vo-aacenc-0.1.2.tar
      cd vo-aacenc-0.1.2
      ./configure
      make
      make install

      安裝VisualOn AMR-WB(注:github的tag和master版均無法autoconf,用zeranoe版代替)

      wget http://ffmpeg.zeranoe.com/builds/source/external_libraries/vo-amrwbenc-0.1.2.tar.xz
      xz -d vo-amrwbenc-0.1.2.tar.xz
      tar xf vo-amrwbenc-0.1.2.tar
      cd vo-amrwbenc-0.1.2
      ./configure

      安裝libvpx(注:新版libvpx貌似與當前ffmpeg不兼容,用舊版)

      wget http://webm.googlecode.com/files/libvpx-v1.1.0.tar.bz2
      tar jxf libvpx-v1.1.0.tar.bz2
      cd libvpx-v1.1.0
      ./configure
      make
      make install

      安裝x264

      wget ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
      tar jxf last_x264.tar.bz2
      cd x264-snapshot-20130311-2245/
      ./configure –enable-shared
      make
      make install

      安裝xvid

      wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
      tar zxf xvidcore-1.3.2.tar.gz
      cd xvidcore
      cd build/generic
      ./configure
      make
      make install

      最重要的一步——編譯安裝ffmpeg!

      wget http://ffmpeg.org/releases/ffmpeg-1.1.3.tar.gz
      tar zxf ffmpeg-1.1.3.tar.gz
      cd ffmpeg-1.1.3
      PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig ./configure –disable-static –enable-shared –enable-gpl –enable-version3 –enable-bzlib –enable-fontconfig –enable-frei0r –enable-gnutls –enable-libfreetype –enable-libmp3lame –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libopus –enable-librtmp –enable-libschroedinger –enable-libsoxr –enable-libspeex –enable-libtheora –enable-libtwolame –enable-libvo-aacenc –enable-libvo-amrwbenc –enable-libvorbis –enable-libvpx –enable-libx264 –enable-libxvid –enable-zlib
      make
      make install

      注1:

      我在編譯安裝時參考Windows Build:http://ffmpeg.zeranoe.com/builds/。

      注2:

      與Windows Build相比,以下沒有選項開啟:

      –enable-libgsm –enable-libilbc -enable-libass –enable-libbluray –enable-libcaca –enable-libopenjpeg –disable-w32threads –enable-avisynth –enable-libxavs

      分類:?所謂技術?| 標簽:?CentOS,ffmpeg,安裝,編碼器,編譯,解碼器



    http://www.cnblogs.com/mystory/archive/2013/04/07/3006200.html


    linux下搭建生成HLS所需的.ts和.m3u8文件

    要想利用HLS來實現(xiàn)視頻的在線播放,就得需要將一個完整的視頻文件切割成多個ts視頻流,然后利用m3u8的索引文件來播放。

    在Mac下,蘋果提供了streamingTools的工具,里面有mediafilesegmenter和mediastreamsegmenter來分別實現(xiàn)文件和直播流的切割,一行命令直接就可以將輸入的原始視頻文件導出成幾個ts和索引文件,直接就可以用了。但是一般服務器都是基于linux的,要想在linux下實現(xiàn)同樣的切割,著實費了一番功夫。

    網上也找了好多相關的資料,基本是利用開源的ffmpeg和segmenter工具來實現(xiàn),但是這搭建這個環(huán)境的過程是曲折的,編譯這些工具的時候會出現(xiàn)好多錯誤,難以解決,好多文章的步驟介紹的也很復雜,又要安裝各種包,又要修改源代碼,經過幾天的各種反復嘗試,才知道在不是直接將源文件切割,而是先要轉換一下,再切割,最終終于痛苦的摸索到了一個成功的路子,特此記錄下來以防忘記。

    1、首先獲得ffmpeg

      apt-get install ffmpeg

    2、安裝ffmpeg支持庫,為m3u8-segmenter準備

      apt-get install libavformat-dev

    3、獲得m3u8-segmenter

      https://github.com/johnf/m3u8-segmenter?

    4、編譯并安裝m3u8-segmenter

      aclocal

      automake -ac

      ./configure

      make

      sudo make install  

    4、編譯其中的文件m3u8-segmenter

      gcc -Wall -g ?m3u8-segmenter.c -o segmenter -lavformat?

    5、利用ffmpeg將已有的視頻文件轉換成ts文件

      ffmpeg -y -i <in file> -vcodec copy -acodec copy -vbsf h264_mp4toannexb <output file>

    其中in file為待轉換的視頻文件,比如input.mov,output file為轉換后的文件,要命名為output.ts

    6、利用segmenter將轉換好的ts文件切割成多個ts片,并生成.m3u8的索引文件

      ./segmenter -i out.ts -n 10 -p segmenter_test -m test.m3u8 -u?

    i表示輸入文件,n表示切割10秒,p表示切割文件的前綴。m表示生成的m3u8文件名,u表示這些切割后的文件處于web server的哪個目錄下

    PS:實踐過程中發(fā)現(xiàn)一個問題,就是切片之后,最后一段ts不管是不是10s,同樣會按10s去切,導致切好后的視頻最后一段會加上去幾秒的黑段來補足10s,原因是segmenter.c中的程序寫的還有缺陷,修正方法如下:

    https://github.com/johnf/m3u8-segmenter/pull/10/files

    參考:

    http://blog.chinaunix.net/uid-25530360-id-3483535.html

    http://shappy1978.iteye.com/blog/1071815

    http://www.ioncannon.net/programming/452/iphone-http-streaming-with-ffmpeg-and-an-open-source-segmenter/

    http://hi.baidu.com/lphack/item/83865611c5f82c8988a956df

    http://blog.cnrainbird.com/index.php/2012/03/25/ping_guo_http_shi_pin_dian_bo_ji_shu/



    3. ?TS流分割器segmenter的安裝與使用

    第一個?m3u8-segmenter

    ? ? ? ? git clone https://github.com/johnf/m3u8-segmenter

    ? ? ? ? 下載m3u8-segmenter 下載后不要用它的反復編譯,直接取m3u8-segmenter.c文件。

    執(zhí)行

    gcc -Wall -g m3u8-segmenter.c -o segmenter -lavformat?-lavcodec -lavutil


    第二個?segmenter

    svn co http://httpsegmenter.googlecode.com/svn/trunk segmenter

    cd ?segmenter

    gcc -Wall -g segmenter.c -o segmenter -lavformat -lavcodec -lavutil -std=c99


    安裝好其中一個后

    cp segmenter /usr/bin/

    把執(zhí)行文件拷貝過去。



    下面給2個超簡單的執(zhí)行例子

    直接轉成ts

    ffmpeg -i vp5.flv -acodec copy -vcodec libx264 vp5.ts

    分割轉成ts 一秒為單位

    ffmpeg -ss 0 -t 30 -i vp5.flv -acodec copy -vcodec libx264 1.ts

    ffmpeg -ss 30 -t 60 -i vp5.flv -acodec copy -vcodec libx264 2.ts

    合并

    ffmpeg -i "concat:1.ts|2.ts" -acodec copy -vcodec copy -absf aac_adtstoasc output.mp4

    切割

    m3u8-segmenter -i test.ts -d 10 -p segmenter_test -m test.m3u8 -u http://127.0.0.1:8080/Video/


    這樣就可以切片出m3u8文件 ?直接使用hls


    ?

    如何編譯m3u8_segmenter

    ?535人閱讀?評論(0)?收藏?舉報

    最近研究hls,發(fā)現(xiàn)需要使用m3u8_segmenter這個程序,搞了半天才編譯通過,特此記錄一下。

    使用正常的./configure等編譯老是出錯誤

    gcc?-Wall?-g?m3u8-segmenter.c?-o?segmenter?-lavformat?-lavcodec?-lavutilm3u8-segmenter.c:?In?function?add_output_stream:

    m3u8-segmenter.c:58:?warning:?implicit?declaration?of?function?avformat_new_stream

    m3u8-segmenter.c:58:?warning:?assignment?makes?pointer?from?integer?without?a?cast

    m3u8-segmenter.c:?In?function?main:

    m3u8-segmenter.c:343:?warning:?implicit?declaration?of?function?avformat_find_stream_info

    m3u8-segmenter.c:380:?error:?AVFMT_FLAG_IGNDTS’?undeclared?(first?use?in?this?function)

    m3u8-segmenter.c:380:?error:?(Each?undeclared?identifier?is?reported?only?once

    m3u8-segmenter.c:380:?error:?for?each?function?it?appears?in.)

    m3u8-segmenter.c:390:?warning:?implicit?declaration?of?function?avcodec_open2

    m3u8-segmenter.c:397:?error:?AVIO_FLAG_WRITE’?undeclared?(first?use?in?this?function)

    ?

    在網上查資料,特別是參考xjd_1985的文章,m3u8-segmenter工程編譯和使用

    ?

    ./configure?FFMPEG_CFLAGS=-I../ffmpeg-2.1.1??FFMPEG_LIBS='-L?../ffmpeg-2.1.1/libavformat?-L../ffmpeg-2.1.1/libavcodec?-L../ffmpeg-2.1.1/libavutil?-pthread?-lavformat?-lavcodec?-lavutil?-lm?-lz'

    ?

    ?

    ffmpeg-2.1.1是我使用ffmpeg的版本和目錄

    然后再make就通過了。

    總結

    以上是生活随笔為你收集整理的HLS协议及java切片相关的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。