Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to disable -b:v #767

Merged
merged 10 commits into from
Mar 4, 2021
Merged

Add ability to disable -b:v #767

merged 10 commits into from
Mar 4, 2021

Conversation

chekalsky
Copy link
Contributor

@chekalsky chekalsky commented Oct 21, 2020

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets fixes #418
Related issues/PRs #418
License MIT

What's in this PR?

By passing 0 to setKiloBitrate() we can bypass setting -b:v setting.

Why?

Sometimes we may prefer not to use -b:v in favor to crf.

BC Breaks/Deprecations

No BC breaks.

To Do

  • Create tests

@fabienlege
Copy link

fabienlege commented Nov 3, 2020

Very good idea.

I search same function so i've tested your PR but it seam that it's not working as it...
We also need to disable the 2pass mode, but I don't know how...

As it, I have this error of ffmpef :


 ffmpeg version 3.4.8-0ubuntu0.2 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/www/html/s2l/web/app/uploads/sites/2/2020/11/Capture-video-2020-10-01-120655-5.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomiso2
    creation_time   : 2020-10-01T10:06:10.000000Z
    encoder         : x264
  Duration: 00:00:40.00, start: 0.000000, bitrate: 239 kb/s
    Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 239 kb/s, 15 fps, 15 tbr, 1500 tbn, 30 tbc (default)
    Metadata:
      creation_time   : 2020-10-01T10:06:10.000000Z
      handler_name    : VideoHandler
Codec AVOption b (set bitrate (in bits/s)) specified for output file #0 (/var/www/html/s2l/web/app/uploads/sites/2/2020/11/export-Capture-video-2020-10-01-120655-5-1080P.mp4) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x5641498b9ec0] using SAR=1/1
[libx264 @ 0x5641498b9ec0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x5641498b9ec0] constant rate-factor is incompatible with 2pass.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!```

@philipp-doblhofer
Copy link
Contributor

Hey,

I got the same issue as you, @fabienlege.
As described here (https://trac.ffmpeg.org/wiki/Encode/H.264#twopass), 2-pass is needed for x264, if a constant bit rate is desired (-b:v option).
The 2-pass setting is assigned here: src/FFMpeg/Format/Video/X264.php:23

Changing the getPasses() method in X264.php as following could help:

public function getPasses() {
   return $this->getKiloBitrate() == 0 ? 1 : 2;
}

@MR-AMDEV
Copy link

Guys please merge this PR so it can also be fixed in the laravel wrapper.

@Romain
Copy link
Member

Romain commented Mar 2, 2021

@chekalsky Thanks for this PR.
Since @fabienlege and @philipp-doblhofer identified an issue with your submission, could you change it and integrate the improvement suggested by @fabienlege?
Thanks!

@Romain
Copy link
Member

Romain commented Mar 4, 2021

@chekalsky I created the tests for you.
@philipp-doblhofer are you sure of your suggestion? Here is what the documentation says: There is no native or true CBR mode, but you can "simulate" a constant bit rate setting by tuning the parameters of a one-pass average bitrate encode

@chekalsky
Copy link
Contributor Author

@Romain thank you!
@philipp-doblhofer wouldn't return $this->getKiloBitrate() === 0 ? 1 : $this->passes; be better? Is there any sense?

@philipp-doblhofer
Copy link
Contributor

philipp-doblhofer commented Mar 4, 2021

@philipp-doblhofer are you sure of your suggestion? Here is what the documentation says: There is no native or true CBR mode, but you can "simulate" a constant bit rate setting by tuning the parameters of a one-pass average bitrate encode

As proposed in the PR

Sometimes we may prefer not to use -b:v in favor to crf.

CRF should be used instead of a constant bitrate with -b:v.

CRF is not CBR

@chekalsky, yes that would probably be more appropriate!

Co-Authored-By: Philipp Doblhofer <6283313+philipp-doblhofer@users.noreply.github.com>
@chekalsky
Copy link
Contributor Author

@philipp-doblhofer ok, added!

@Romain Romain merged commit afffd62 into PHP-FFMpeg:master Mar 4, 2021
@Romain
Copy link
Member

Romain commented Mar 4, 2021

Thanks for your contribution @philipp-doblhofer and @chekalsky !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can PHP-FFMPEG encode with Rate Control Modes other than Constant bitrate?
5 participants