libx265 & ffmpeg: a melhor compactação, os arquivos maiores?

0

Tentando espremer o último bit, concluí que os arquivos ficam maiores e menores. Infelizmente eu devo ter interpretado erroneamente alguns parâmetros.

Talvez você possa me ajudar.

A referência é -preset placebo :

ffmpeg -y -hide_banner -i <input.mp4> \
       [... audio ...] \
       -pix_fmt yuv420p \
       -preset placebo \
       -crf 30 \
       -codec:v libx265 \
       -f mp4 \
       -movflags +faststart+disable_chpl \
       <output.mp4>

O tamanho do arquivo resultante é de 130.780,586 bytes.

Depois, li a documentação e tentei entender o significado dos parâmetros.

Depois eu usei

ffmpeg -y -hide_banner -i <input.mp4>  \
       [... audio ...] \
       -pix_fmt yuv420p \
       -preset placebo \
       -crf 30 \
       -x265-params "ssim=0:psnr=0:frame-threads=1:pools=*:wpp=0:pmode=0:pme=0:slices=1:copy-pic=1:level-idc=0:high-tier=1:ref=6:allow-non-conformance=0:uhd-bd=0:rd=6:ctu=64:min-cu-size=8:limit-refs=0:limit-modes=0:rect=0:amp=0:early-skip=0:rskip=0:splitrd-skip=0:fast-intra=0:b-intra=1:cu-lossless=1:tskip-fast=0:rd-refine=1:rdoq-level=1:tu-intra-depth=4:tu-inter-depth=4:limit-tu=0:nr-intra=0:tskip=0:rdpenalty=0:max-tu-size=32:dynamic-rd=0:ssim-rd=1:max-merge=5:me=full:subme=7:merange=32767:temporal-mvp=1:weightp=1:weightb=1:analyze-src-pics=1:strong-intra-smoothing=1:constrained-intra=0:psy-rd=2.0:psy-rdoq=1.0:open-gop=1:keyint=15000:min-keyint=2:scenecut=40:scenecut-bias=5:ctu-info=0:intra-refresh=0:rc-lookahead=250:lookahead-slices=0:lookahead-threads=0:b-adapt=2:bframes=16:bframe-bias=0:b-pyramid=1:force-flush=0:crf-max=51.0:crf-min=0.0:vbv-bufsize=0:vbv-maxrate=0:vbv-init=0.0:vbv-end=0.0:vbv-end-fr-adj=0:lossless=0:aq-mode=3:aq-strength=1.0:aq-motion=1:qg-size=8:cutree=1:strict-cbr=0:signhide=1:sao=1:sao-non-deblock=0:limit-sao=0:opt-qp-pps=1:opt-ref-list-length-pps=1:opt-cu-delta-qp=1" \
       -codec:v libx265 \
       -f mp4 \
       -movflags +faststart+disable_chpl \
       <output.mp4>

O tamanho do arquivo resultante é de 300.468.224 bytes.

Aparentemente, a qualidade visual é melhor. Mas eu pensei que deveria ser constante por causa de -crf 30 . Tenho que reduzir a taxa de bits variável aumentando -crf ?

Para uma melhor legibilidade dos parâmetros novamente:

-x265-params "
  ssim=0:
  psnr=0:
  frame-threads=1:
  pools=*:
  wpp=0:
  pmode=0:
  pme=0:
  slices=1:
  copy-pic=1:
  level-idc=0:
  high-tier=1:
  ref=6:
  allow-non-conformance=0:
  uhd-bd=0:
  rd=6:
  ctu=64:
  min-cu-size=8:
  limit-refs=0:
  limit-modes=0:
  rect=0:amp=0:
  early-skip=0:
  rskip=0:
  splitrd-skip=0:
  fast-intra=0:
  b-intra=1:
  cu-lossless=1:
  tskip-fast=0:
  rd-refine=1:
  rdoq-level=1:
  tu-intra-depth=4:
  tu-inter-depth=4:
  limit-tu=0:
  nr-intra=0:
  tskip=0:
  rdpenalty=0:
  max-tu-size=32:
  dynamic-rd=0:
  ssim-rd=1:
  max-merge=5:
  me=full:
  subme=7:
  merange=32767:
  temporal-mvp=1:
  weightp=1:
  weightb=1:
  analyze-src-pics=1:
  strong-intra-smoothing=1:
  constrained-intra=0:
  psy-rd=2.0:
  psy-rdoq=1.0:
  open-gop=1:
  keyint=15000:
  min-keyint=2:
  scenecut=40:
  scenecut-bias=5:
  ctu-info=0:
  intra-refresh=0:
  rc-lookahead=250:
  lookahead-slices=0:
  lookahead-threads=0:
  b-adapt=2:
  bframes=16:
  bframe-bias=0:
  b-pyramid=1:
  force-flush=0:
  crf-max=51.0:
  crf-min=0.0:
  vbv-bufsize=0:
  vbv-maxrate=0:
  vbv-init=0.0:
  vbv-end=0.0:
  vbv-end-fr-adj=0:
  lossless=0:
  aq-mode=3:
  aq-strength=1.0:
  aq-motion=1:
  qg-size=8:
  cutree=1:
  strict-cbr=0:
  signhide=1:
  sao=1:
  sao-non-deblock=0:
  limit-sao=0:
  opt-qp-pps=1:
  opt-ref-list-length-pps=1:
  opt-cu-delta-qp=1"

A saída do placebo run:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '<input.mp4>':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2018-03-25T07:58:52.000000Z
  Duration: 00:07:03.46, start: 0.000000, bitrate: 207200 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 207062 kb/s, 24 fps, 24 tbr, 24k tbn, 48 tbc (default)
    Metadata:
      creation_time   : 2018-03-25T07:58:52.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      encoder         : AVC Coding
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 157 kb/s (default)
    Metadata:
      creation_time   : 2018-03-25T07:58:52.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> hevc (libx265))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
x265 [info]: HEVC encoder version 2.6
x265 [info]: build info [Linux][GCC 7.2.0][64 bit] 8bit+10bit+12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main profile, Level-4 (Main tier)
x265 [info]: Thread pool created using 8 threads
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 3 / wpp(17 rows)
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 4 inter / 4 intra
x265 [info]: ME / range / subpel / merge         : star / 92 / 5 / 5
x265 [info]: Keyframe min / max / scenecut / bias: 24 / 250 / 40 / 5.00
x265 [info]: Lookahead / bframes / badapt        : 60 / 8 / 2
x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 1
x265 [info]: References / ref-limit  cu / depth  : 5 / off / off
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 1 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress            : CRF-30.0 / 0.60
x265 [info]: tools: rect amp rd=6 psy-rd=2.00 rdoq=2 psy-rdoq=1.00 tskip
x265 [info]: tools: signhide tmvp b-intra strong-intra-smoothing deblock sao
Output #0, mp4, to '<output.mp4>':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    encoder         : Lavf57.83.100
    Stream #0:0(eng): Video: hevc (libx265) (hev1 / 0x31766568), yuv420p(progressive), 1506x1080 [SAR 1:1 DAR 251:180], q=2-31, 24 fps, 12288 tbn, 24 tbc (default)
    Metadata:
      creation_time   : 2018-03-25T07:58:52.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      encoder         : Lavc57.107.100 libx265
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 48 kb/s (default)
    Metadata:
      creation_time   : 2018-03-25T07:58:52.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler
      encoder         : Lavc57.107.100 aac
[mp4 @ 0x558418671660] Starting second pass: moving the moov atom to the beginning of the file
frame=10162 fps=0.1 q=-0.0 Lsize=  127715kB time=00:07:03.43 bitrate=2470.8kbits/s speed=0.00405x    
video:124915kB audio:2502kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 0.233744%
x265 [info]: frame I:     58, Avg QP:32.08  kb/s: 3827.66 
x265 [info]: frame P:   1838, Avg QP:33.65  kb/s: 3792.41 
x265 [info]: frame B:   8266, Avg QP:36.26  kb/s: 2100.06 
x265 [info]: Weighted P-Frames: Y:7.0% UV:7.0%
x265 [info]: Weighted B-Frames: Y:18.1% UV:17.6%
x265 [info]: consecutive B-frames: 4.7% 3.3% 11.0% 20.1% 16.9% 12.9% 10.2% 9.7% 11.2% 

encoded 10162 frames in 104535.21s (0.10 fps), 2416.02 kb/s, Avg QP:35.76
[aac @ 0x5584186c0220] Qavg: 156.304

E a saída da execução exagerada:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '<input.mp4>':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2018-03-25T07:58:52.000000Z
  Duration: 00:07:03.46, start: 0.000000, bitrate: 207200 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 207062 kb/s, 24 fps, 24 tbr, 24k tbn, 48 tbc (default)
    Metadata:
      creation_time   : 2018-03-25T07:58:52.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      encoder         : AVC Coding
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 157 kb/s (default)
    Metadata:
      creation_time   : 2018-03-25T07:58:52.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> hevc (libx265))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
x265 [info]: HEVC encoder version 2.6
x265 [info]: build info [Linux][GCC 7.2.0][64 bit] 8bit+10bit+12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main profile, Level-4 (Main tier)
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 1 / none
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 4 inter / 4 intra
x265 [info]: ME / range / subpel / merge         : full / 32767 / 7 / 5
x265 [info]: Keyframe min / max / scenecut / bias: 2 / 15000 / 40 / 5.00
x265 [info]: Lookahead / bframes / badapt        : 250 / 16 / 2
x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 1
x265 [info]: References / ref-limit  cu / depth  : 6 / off / off
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 3 / 1.0 / 8 / 1
x265 [info]: Rate Control / qCompress            : CRF-30.0 / 0.60
x265 [info]: tools: rd=6 ssim-rd psy-rd=2.00 rdoq=1 psy-rdoq=1.00 rd-refine
x265 [info]: tools: cu-lossless signhide tmvp b-intra strong-intra-smoothing
x265 [info]: tools: deblock sao
Output #0, mp4, to '<output.mp4>':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    encoder         : Lavf57.83.100
    Stream #0:0(eng): Video: hevc (libx265) (hev1 / 0x31766568), yuv420p(progressive), 1506x1080 [SAR 1:1 DAR 251:180], q=2-31, 24 fps, 12288 tbn, 24 tbc (default)
    Metadata:
      creation_time   : 2018-03-25T07:58:52.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      encoder         : Lavc57.107.100 libx265
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 48 kb/s (default)
    Metadata:
      creation_time   : 2018-03-25T07:58:52.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler
      encoder         : Lavc57.107.100 aac
[mp4 @ 0x564f7705a760] Starting second pass: moving the moov atom to the beginning of the file
frame=10162 fps=0.1 q=-0.0 Lsize=  293426kB time=00:07:03.43 bitrate=5676.7kbits/s speed=0.00402x    
video:290747kB audio:2502kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 0.060220%
x265 [info]: frame I:     34, Avg QP:28.44  kb/s: 8462.33 
x265 [info]: frame P:   1710, Avg QP:31.95  kb/s: 6614.87 
x265 [info]: frame B:   8418, Avg QP:32.51  kb/s: 5411.77 
x265 [info]: Weighted P-Frames: Y:7.0% UV:6.8%
x265 [info]: Weighted B-Frames: Y:18.4% UV:17.2%
x265 [info]: consecutive B-frames: 5.6% 3.6% 11.8% 22.0% 17.3% 11.6% 7.3% 5.3% 2.9% 1.9% 1.5% 2.2% 0.8% 0.9% 0.7% 1.5% 2.9% 

encoded 10162 frames in 105460.05s (0.10 fps), 5624.43 kb/s, Avg QP:32.40
[aac @ 0x564f770d19e0] Qavg: 156.304

Obrigado por ler!

    
por Thomas R. 26.09.2018 / 18:13

1 resposta

1

Sugira que você se atenha às predefinições regulares.

Ainda não verificamos todos os seus parâmetros personalizados, mas notamos que você tem cu-lossless=1 . Isso diz ao x265 para avaliar a codificação sem perdas como uma opção no nível CU. Essas UCs assim codificadas não terão nenhuma transformação / quantização aplicada e a codificação de entropia também será mais difícil nos resíduos resultantes.

Além disso, x265 docs dizem

--psy-rd influences the RDO decisions in favor of energy (detail) preservation over bit cost and results in more blocks being losslessly coded.

e você definiu psy-rd=2.0

    
por 26.09.2018 / 21:08