Cuma, Aralık 27, 2024

Ffmpeg ile VOD HLS Stream Nasıl Oluşturulur?

ffmpeg yüksek çözünürlüklü logo, ffmpeg svg logo, ffmpeg logo

HLS, masaüstü ve mobil tarayıcılarda en belirgin video akış biçimlerinden biri. Bazıları bu ve buna benzer yöntemleri paralı bir şekilde satmaya çalışıyor, bilinen şeylerin paralı bir şekilde birilerine itelenmesine karşıyım.

Son kullanıcı farklı ekran boyutlarına ve farklı ağ performansına sahip özellikle Türkiye’de çoğu kullanıcı 480p’ye muhtaç, videonun farklı çözünürlüklerde ve sorunsuz bir şekilde değiştirilebilen birden çok formatını oluşturmalı ve yayınlamalıyız. Bu iş için hem giriş hem de çıkış olarak HLS dahil olmak üzere çeşitli video formatlarının birinden diğerine dönüştürülmesini destekleyen ffmpeg’i kullanacağız, başka bir araca zaten ihtiyacımız asla yok.

Ancak Encoding ve diğer işlemler için doğru düzgün bir işlemci öneririm CPU ile bu iş yapılmaz. Şimdi çıkıp ben içeriği korumak istiyorum diyorsanız o noktaya karışmıyorum.

Bağımlılıkların Kurulması

Şimdi NVIDIA GPU uyumlu bir şekilde kurulum yapacağız, önce NVIDIA‘nın ihtiyaç duyduğu kütüphaneleri kuralım

git clone https://github.com/FFmpeg/nv-codec-headers.git
cd nv-codec-headers && sudo make install
ShellScript

Derleme işlemi için gerekenleri kuralım

sudo apt-get update -qq && sudo apt-get -y install \
  autoconf \
  automake \
  build-essential \
  cmake \
  git-core \
  libass-dev \
  libfreetype6-dev \
  libgnutls28-dev \
  libtool \
  libvorbis-dev \
  pkg-config \
  texinfo \
  wget \
  yasm \
  zlib1g-dev \
  bc

sudo apt-get install nasm libx264-dev libx265-dev libnuma-dev libvpx-dev libfdk-aac-dev libmp3lame-dev libopus-dev
ShellScript

Şimdi geldik en civcivli kısma, ffmpeg’i NVIDIA uyumlu bir şekilde derleyeceğiz, burada sürücüleriniz uyumsuz çıkması durumunda ffmpeg sürümünü düşürün.

git clone https://git.ffmpeg.org/ffmpeg.git

./configure \
  --enable-gpl \
  --enable-gnutls \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-cuda-sdk \
  --enable-cuvid \
  --enable-nvenc \
  --enable-nonfree \
  --enable-libnpp \
  --extra-cflags=-I/usr/local/cuda/include \
  --extra-ldflags=-L/usr/local/cuda/lib64

make -j 10
ShellScript

Derleme işlemi bittikten hemen sonra, bulunduğunuz dizinde bir ffmpeg dosyası göreceksiniz. İşte bu GPU destekli bir ffmpeg dosyası. GPU kullanma sebebimiz encoding işleminin ciddi anlamda kısalması, iki saatlik bir 1080p Full HD bir filmin CPU ile encoding işlemi yaklaşık 20 saat kadar sürecektir. Ancak GPU ile 2 saate bu işi halledebilirsiniz.

AMD GPU kullanıyorum nasıl yaparım diyenler gitsin Google’den baksın, hiç AMD tarafında ekran kartı kullanmadığım için maalesef tecrübem bile yok.


Elle yapmak ve sunucunuza atmak isterseniz en temelde yöntem şu şekilde, kaç adet oynatma listesi ve format oluşturacağınıza siz karar verebilirsiniz. Ben direk olarak bluray üzerinden çevirim yapacağım için aşağıdaki gibi bir yapılandırma uyguladım ve örnekte 720p kullandım.

ffmpeg.exe -i 1994.mp4 -vf scale=1280:trunc(ow/a/2)*2:force_original_aspect_ratio=decrease -c:a aac -b:a 128k -ac 2 -c:v libx264 -crf 21 -preset veryfast -g 48 -keyint_min 48 -sc_threshold 0 -b:v 2500k -maxrate 2675k -bufsize 3750k -fflags flush_packets -max_delay 5 -flags -global_header -start_number 0 -hls_time 10 -hls_playlist_type vod -hls_list_size 3 -f hls -hls_segment_filename 1993/720p_%03d.ts 1993/720p.m3u8
ShellScript

Bu işlemin sonucunda size bir adet .m3u8 uzantılı dosya ve bolca .ts uzantılı medya dosyası verecek. Yukarıda kullandığımız parametrelerde apple standartlarını göz önünde bulundurduk.

  • -vf scale=1280:trunc(ow/a/2)*2:force_original_aspect_ratio=decrease Videomuzu 720p olarak boyutladık, çerçeve oranı ise boyuta göre otomatik şekillenecek.
  • -c:a aac -b:a 128k -ac 2 Ses olarak aac ve 128 bit seçtik.
  • -c:v libx264 -crf 21 -preset veryfast -g 48 -keyint_min 48 -sc_threshold 0 -b:v 2500k -maxrate 2675k -bufsize 3750k Videomuzu x264 kodek ile birlikte veryfast yaptım görüntüden ödün vereceğiz ama işlem hızlı bitecek sisteminiz iyiyse duruma göre işlem yapın. bitrate ayarımız ise 2500k olarak ayarlı

Bütün parametreleri ve nasıl kullanıldığını öğrenmek isterseniz ffmpeg belgelendirmelerini ziyaret edebilirsiniz, hepsini açıklayamayız.

Yukarıdaki parametre eşliğinde örnek olarak çalıştırdığımız dosyamızın ffmpeg ile encode edilmiş halinden bir konsol çıktısı

ffmpeg version 4.4-essentials_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1994.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01T00:00:00.000000Z
    encoder         : Lavf53.24.2
  Duration: 00:02:50.86, start: 0.000000, bitrate: 1474 kb/s
  Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1086 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      creation_time   : 1970-01-01T00:00:00.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 383 kb/s (default)
    Metadata:
      creation_time   : 1970-01-01T00:00:00.000000Z
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 00000149c0e60540] using SAR=1/1
[libx264 @ 00000149c0e60540] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 00000149c0e60540] profile High, level 3.1, 4:2:0, 8-bit
Output #0, hls, to '1993/720p.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    encoder         : Lavf58.76.100
  Stream #0:0(und): Video: h264, yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 2500 kb/s, 25 fps, 90k tbn (default)
    Metadata:
      creation_time   : 1970-01-01T00:00:00.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc58.134.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 2675000/0/2500000 buffer size: 3750000 vbv_delay: N/A
  Stream #0:1(und): Audio: aac (LC), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc58.134.100 aac
[hls @ 00000149c0ba7340] Opening '1993/720p_000.ts' for writingA speed=21.9x
[hls @ 00000149c0ba7340] Opening '1993/720p_001.ts' for writingA speed=21.6x
[hls @ 00000149c0ba7340] Opening '1993/720p_002.ts' for writingA speed=20.8x
[hls @ 00000149c0ba7340] Opening '1993/720p_003.ts' for writingA speed=  21x
[hls @ 00000149c0ba7340] Opening '1993/720p_004.ts' for writing
[hls @ 00000149c0ba7340] Opening '1993/720p_006.ts' for writingA speed=  22x
[hls @ 00000149c0ba7340] Opening '1993/720p_007.ts' for writingA speed=21.8x
[hls @ 00000149c0ba7340] Opening '1993/720p_008.ts' for writingA speed=22.1x
[hls @ 00000149c0ba7340] Opening '1993/720p_009.ts' for writingA speed=22.3x
[hls @ 00000149c0ba7340] Opening '1993/720p_010.ts' for writing
[hls @ 00000149c0ba7340] Opening '1993/720p_011.ts' for writingA speed=22.8x
[hls @ 00000149c0ba7340] Opening '1993/720p_012.ts' for writingA speed=  23x
[hls @ 00000149c0ba7340] Opening '1993/720p_013.ts' for writingA speed=22.8x
[hls @ 00000149c0ba7340] Opening '1993/720p_014.ts' for writingA speed=22.7x
[hls @ 00000149c0ba7340] Opening '1993/720p_015.ts' for writingA speed=22.7x
[hls @ 00000149c0ba7340] Opening '1993/720p_016.ts' for writingA speed=22.4x
frame= 4271 fps=556 q=-1.0 Lsize=N/A time=00:02:50.83 bitrate=N/A speed=22.3x
video:28977kB audio:2686kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 00000149c0e60540] frame I:89    Avg QP:16.00  size: 90339
[libx264 @ 00000149c0e60540] frame P:2380  Avg QP:20.06  size:  7823
[libx264 @ 00000149c0e60540] frame B:1802  Avg QP:23.19  size:  1672
[libx264 @ 00000149c0e60540] consecutive B-frames: 38.7% 11.6% 10.5% 39.1%
[libx264 @ 00000149c0e60540] mb I  I16..4: 10.9% 29.8% 59.3%
[libx264 @ 00000149c0e60540] mb P  I16..4:  1.7%  5.0%  1.7%  P16..4: 19.3%  6.1%  3.2%  0.0%  0.0%    skip:63.0%
[libx264 @ 00000149c0e60540] mb B  I16..4:  0.2%  0.6%  0.2%  B16..8:  5.6%  1.6%  0.3%  direct: 2.3%  skip:89.2%  L0:48.8% L1:38.3% BI:12.9%
[libx264 @ 00000149c0e60540] 8x8 transform intra:51.2% inter:32.0%
[libx264 @ 00000149c0e60540] coded y,uvDC,uvAC intra: 66.1% 74.6% 33.6% inter: 4.1% 7.7% 0.3%
[libx264 @ 00000149c0e60540] i16 v,h,dc,p: 34% 31% 16% 19%
[libx264 @ 00000149c0e60540] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 27% 18%  4%  5%  5%  5%  5%  5%
[libx264 @ 00000149c0e60540] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 18% 10%  7%  8%  9%  7%  9%  7%
[libx264 @ 00000149c0e60540] i8c dc,h,v,p: 41% 27% 21% 11%
[libx264 @ 00000149c0e60540] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 00000149c0e60540] kb/s:1389.50
[aac @ 00000149c0cda740] Qavg: 167.390
ShellScript

Tek format ve tek çözünürlük olarak işlemlerimizi tamamladık ancak HLS dediğimiz şey birden fazla çözünürlükle yapılır. Bu iş içinde aşağıdaki örnek parametreleri kullanabilirsiniz.

ffmpeg -i 1994.mp4 -filter_complex [v:0]split=2[vtemp001][vout002];[vtemp001]scale=w=960:h=540[vout001] -preset veryfast -g 25 -sc_threshold 0 -map [vout001] -c:v:0 libx264 -b:v:0 2000k -map [vout002] -c:v:1 libx264 -b:v:1 6000k -map a:0 -map a:0 -c:a aac -b:a 128k -ac 2 -f hls -hls_time 4 -hls_playlist_type event -master_pl_name master.m3u8 -var_stream_map v:0,a:0 v:1,a:1 stream_%v.m3u8
ShellScript

Yukarıdaki parametreler eşliğinde örnek çıktımız şu şekilde oldu

ffmpeg version 4.4-essentials_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1994.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01T00:00:00.000000Z
    encoder         : Lavf53.24.2
  Duration: 00:02:50.86, start: 0.000000, bitrate: 1474 kb/s
  Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1086 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      creation_time   : 1970-01-01T00:00:00.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 383 kb/s (default)
    Metadata:
      creation_time   : 1970-01-01T00:00:00.000000Z
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 (h264) -> split (graph 0)
  scale (graph 0) -> Stream #0:0 (libx264)
  split:output1 (graph 0) -> Stream #0:1 (libx264)
  Stream #0:1 -> #0:2 (aac (native) -> aac (native))
  Stream #0:1 -> #0:3 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0000026330bfc2c0] using SAR=1/1
[libx264 @ 0000026330bfc2c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0000026330bfc2c0] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 0000026330bfc2c0] 264 - core 161 r3048 b86ae3c - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=17 lookahead_threads=4 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=25 keyint_min=2 scenecut=0 intra_refresh=0 rc_lookahead=10 rc=abr mbtree=1 bitrate=2000 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[libx264 @ 000002633096c040] using SAR=1/1
[libx264 @ 000002633096c040] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000002633096c040] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 000002633096c040] 264 - core 161 r3048 b86ae3c - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=22 lookahead_threads=5 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=25 keyint_min=2 scenecut=0 intra_refresh=0 rc_lookahead=10 rc=abr mbtree=1 bitrate=6000 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, hls, to 'stream_%v.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Stream #0:0: Video: h264, yuv420p(tv, progressive), 960x540 [SAR 1:1 DAR 16:9], q=2-31, 2000 kb/s, 25 fps, 90k tbn (default)
    Metadata:
      encoder         : Lavc58.134.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 0 vbv_delay: N/A
  Stream #0:1: Video: h264, yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 6000 kb/s, 25 fps, 90k tbn (default)
    Metadata:
      encoder         : Lavc58.134.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/6000000 buffer size: 0 vbv_delay: N/A
  Stream #0:2(und): Audio: aac (LC), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 1970-01-01T00:00:00.000000Z
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc58.134.100 aac
  Stream #0:3(und): Audio: aac (LC), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 1970-01-01T00:00:00.000000Z
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc58.134.100 aac
[hls @ 0000026330af0540] Opening 'stream_00.ts' for writing bitrate=N/A speed=11.3x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_10.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'master.m3u8' for writing
[hls @ 0000026330af0540] Opening 'stream_01.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_11.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_02.ts' for writing bitrate=N/A speed=11.8x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_12.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_03.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_13.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_04.ts' for writing bitrate=N/A speed=11.9x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_14.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_05.ts' for writing bitrate=N/A speed=11.5x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_15.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_06.ts' for writing bitrate=N/A speed=11.6x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_16.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_07.ts' for writing bitrate=N/A speed=11.2x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_17.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_08.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_18.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_09.ts' for writing bitrate=N/A speed=11.4x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_19.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_010.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_110.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_011.ts' for writingbitrate=N/A speed=11.6x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_111.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_012.ts' for writingbitrate=N/A speed=11.9x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_112.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_013.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_113.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_014.ts' for writingbitrate=N/A speed=11.9x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_114.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_015.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_115.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_016.ts' for writingbitrate=N/A speed=11.9x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_116.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_017.ts' for writingbitrate=N/A speed=11.9x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_117.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_018.ts' for writingbitrate=N/A speed=11.9x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_118.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_019.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_119.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_020.ts' for writingbitrate=N/A speed=11.9x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_120.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_021.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_121.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_022.ts' for writingbitrate=N/A speed=11.9x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_122.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_023.ts' for writingbitrate=N/A speed=11.9x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_123.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_024.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_124.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_025.ts' for writingbitrate=N/A speed=11.9x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_125.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_026.ts' for writingbitrate=N/A speed=  12x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_126.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_027.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_127.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_028.ts' for writingbitrate=N/A speed=  12x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_128.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_029.ts' for writingbitrate=N/A speed=12.1x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_129.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_030.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_130.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_031.ts' for writingbitrate=N/A speed=12.1x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_131.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_032.ts' for writingbitrate=N/A speed=12.1x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_132.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_033.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_133.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_034.ts' for writingbitrate=N/A speed=12.1x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_134.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_035.ts' for writingbitrate=N/A speed=12.1x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_135.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_036.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_136.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_037.ts' for writingbitrate=N/A speed=  12x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_137.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_038.ts' for writingbitrate=N/A speed=12.1x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_138.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_039.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_139.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_040.ts' for writingbitrate=N/A speed=12.1x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_140.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_041.ts' for writingbitrate=N/A speed=  12x
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_141.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_042.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_0.m3u8.tmp' for writing
[hls @ 0000026330af0540] Opening 'stream_142.ts' for writing
[hls @ 0000026330af0540] Opening 'stream_1.m3u8.tmp' for writing
frame= 4271 fps=299 q=-1.0 Lq=-1.0 size=N/A time=00:02:50.83 bitrate=N/A speed=  12x
video:169733kB audio:5372kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0000026330bfc2c0] frame I:171   Avg QP:11.40  size: 97885
[libx264 @ 0000026330bfc2c0] frame P:1524  Avg QP:15.14  size: 12339
[libx264 @ 0000026330bfc2c0] frame B:2576  Avg QP:18.78  size:  3160
[libx264 @ 0000026330bfc2c0] consecutive B-frames: 14.6% 12.2%  8.3% 64.9%
[libx264 @ 0000026330bfc2c0] mb I  I16..4:  9.7% 12.8% 77.5%
[libx264 @ 0000026330bfc2c0] mb P  I16..4:  1.5%  3.9%  6.0%  P16..4: 20.4%  8.4%  7.8%  0.0%  0.0%    skip:51.9%
[libx264 @ 0000026330bfc2c0] mb B  I16..4:  0.2%  0.8%  0.7%  B16..8:  9.2%  5.1%  1.4%  direct: 5.6%  skip:77.1%  L0:38.7% L1:38.8% BI:22.5%
[libx264 @ 0000026330bfc2c0] final ratefactor: 14.72
[libx264 @ 0000026330bfc2c0] 8x8 transform intra:26.1% inter:28.0%
[libx264 @ 0000026330bfc2c0] coded y,uvDC,uvAC intra: 86.8% 91.0% 78.3% inter: 9.4% 11.6% 1.7%
[libx264 @ 0000026330bfc2c0] i16 v,h,dc,p: 30% 42% 12% 16%
[libx264 @ 0000026330bfc2c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 30% 10%  5%  6%  6%  6%  7%  6%
[libx264 @ 0000026330bfc2c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 20%  8%  6%  8%  9%  8%  9%  8%
[libx264 @ 0000026330bfc2c0] i8c dc,h,v,p: 39% 28% 19% 14%
[libx264 @ 0000026330bfc2c0] Weighted P-Frames: Y:0.1% UV:0.1%
[libx264 @ 0000026330bfc2c0] kb/s:2045.60
[libx264 @ 000002633096c040] frame I:171   Avg QP: 4.75  size:244180
[libx264 @ 000002633096c040] frame P:2363  Avg QP: 7.60  size: 31617
[libx264 @ 000002633096c040] frame B:1737  Avg QP:12.44  size:  7862
[libx264 @ 000002633096c040] consecutive B-frames: 40.4% 12.6% 10.3% 36.7%
[libx264 @ 000002633096c040] mb I  I16..4:  8.8% 16.5% 74.6%
[libx264 @ 000002633096c040] mb P  I16..4:  1.2%  1.7%  4.8%  P16..4: 25.3%  6.4%  5.8%  0.0%  0.0%    skip:54.7%
[libx264 @ 000002633096c040] mb B  I16..4:  0.1%  0.2%  0.6%  B16..8: 16.5%  4.9%  2.2%  direct: 5.7%  skip:69.8%  L0:46.3% L1:37.3% BI:16.4%
[libx264 @ 000002633096c040] final ratefactor: 8.24
[libx264 @ 000002633096c040] 8x8 transform intra:19.6% inter:21.5%
[libx264 @ 000002633096c040] coded y,uvDC,uvAC intra: 83.9% 87.1% 78.1% inter: 15.5% 13.9% 5.1%
[libx264 @ 000002633096c040] i16 v,h,dc,p: 39% 34% 15% 12%
[libx264 @ 000002633096c040] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 36% 21%  2%  2%  2%  2%  3%  3%
[libx264 @ 000002633096c040] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 21%  8%  6%  7%  8%  7%  8%  7%
[libx264 @ 000002633096c040] i8c dc,h,v,p: 40% 27% 19% 13%
[libx264 @ 000002633096c040] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 000002633096c040] kb/s:6093.24
[aac @ 000002633053bbc0] Qavg: 167.390
[aac @ 0000026330911780] Qavg: 167.390
ShellScript

Bunun neticesinde elimizde bir adet master.m3u8 dosyası oluştu, içeriğini merak edenler için şu şekilde

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=2340800,RESOLUTION=960x540,CODECS=avc1.64001f,mp4a.40.2
stream_0.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=6740800,RESOLUTION=1280x720,CODECS=avc1.64001f,mp4a.40.2
stream_1.m3u8
ShellScript

Bu işlemlerin hepsini otomatize etmek istersek şu şekilde yapabiliriz, elimizin altında bir linux makine ve GPU olması yeterli. GPU olmadan bu işlemi yapamazsınız bilginiz olsun.(betik çalışmayacaktır.)

Son olarak doğru bitrate seçimini yapmalısınız yoksa görüntü ciddi anlamda çamur olur, örnek olması açısından bir kaç IPTV işi yapan arkadaşın kullandığı oranları bırakıyorum.

KaliteÇözünürlükBitrate
240p426×240600k
360p640×360900k
480p854×4801600k
HD1280×7203200k
HD 60fps1280×7204400k
FHD1920×10805300k
FHD 60fps1920×10807400k
UHD3840×216018200k
UHD 60fps3840×216029500k