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 support for VideoToolbox hardware encoding. #1522

Closed
wants to merge 3 commits into
base: master
from

Conversation

5 participants
@galad87
Contributor

galad87 commented Aug 7, 2018

Description of Change:

Things to do:

  • fake some bitrate values for disable CQ
  • check why b-frames are not enabled for HEVC

Test on:

  • Windows 10+ (via MinGW)
  • macOS 10.13+
  • Ubuntu Linux
@sr55

This comment has been minimized.

Member

sr55 commented Aug 7, 2018

Maybe we should just not show the quality slider rather than fooling people into thinking it's true cq.

@sr55

This comment has been minimized.

Member

sr55 commented Aug 7, 2018

Using an awful lot of CPU suggesting it's not actually offloading onto the ASIC.

@galad87

This comment has been minimized.

Contributor

galad87 commented Aug 7, 2018

It does use the ASIC on my Mac, but it can encode up to 400 FPS so I guess it spends a lot of cpu to decode the source. Anyway, make a sample or either use Instruments to see what's going on.

@sr55

This comment has been minimized.

Member

sr55 commented Aug 7, 2018

Yeh, wasn't thinking decode. The relatively low clock speeds from my laptop probably holding back decode and thus encode. Getting a decent enough 260fps average here on a 6700HQ

@sr55

This comment has been minimized.

Member

sr55 commented Aug 7, 2018

Builds fine with MinGW.

@sr55 sr55 added the Enhancement label Aug 7, 2018

@sr55 sr55 modified the milestones: 1.1.2, 1.2.0 Aug 7, 2018

@cehoyos

This comment has been minimized.

cehoyos commented Aug 7, 2018

--enable-encoder=h264_videotoolbox
--enable-encoder=hevc_videotoolbox

Can be simplified:
--enable-encoder=h264_videotoolbox,hevc_videotoolbox
(or even *_videotoolbox)

@galad87 galad87 force-pushed the galad87:vt_ffmpeg branch from f36a8fa to b94136a Aug 25, 2018

galad87 added some commits Aug 7, 2018

@galad87 galad87 force-pushed the galad87:vt_ffmpeg branch from b94136a to a8863ba Aug 31, 2018

@bradleysepos

This comment has been minimized.

Contributor

bradleysepos commented Sep 4, 2018

This does not work on my Mac Pro. I have both NVidia GTX 670 and GT 640 cards installed (both support Metal and Mojave, if that matters). Additionally, while I see the H.265 encoder, I do not see the H.264 variant.

Default preset, H.265 (VideoToolbox) encoder, ABR mode, 6000 kbps. Same for one or two pass.

[23:56:12] macgui: Handbrake Version: 20180904032342-bf3f700-vt_ffmpeg  (2018090401)
[23:56:12] hb_init: starting libhb thread
[23:56:12] hb_init: starting libhb thread
[23:56:15] macgui: trying to open a folder or file
[23:56:15] macgui: ScanCore scanning titles with a duration of 0 seconds or more
[23:56:15] CPU: Intel(R) Xeon(R) CPU           W3680  @ 3.33GHz
[23:56:15]  - logical processor count: 12
[23:56:15] hb_scan: path=/Users/bradley/Desktop/IMG_2411.MOV, title_index=0
udfread ERROR: ECMA 167 Volume Recognition failed
disc.c:323: failed opening UDF image /Users/bradley/Desktop/IMG_2411.MOV
disc.c:424: error opening file BDMV/index.bdmv
disc.c:424: error opening file BDMV/BACKUP/index.bdmv
[23:56:15] bd: not a bd - trying as a stream/file instead
libdvdnav: Using dvdnav version 6.0.0
libdvdread: Encrypted DVD support unavailable.
libdvdread:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdread:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.BUP failed
libdvdread: Can't open file VIDEO_TS.IFO.
libdvdnav: vm: failed to read VIDEO_TS.IFO
[23:56:15] dvd: not a dvd - trying as a stream/file instead
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/bradley/Desktop/IMG_2411.MOV':
  Metadata:
    major_brand     : qt  
    minor_version   : 0
    compatible_brands: qt  
    creation_time   : 2018-06-08T08:06:32.000000Z
    com.apple.quicktime.location.ISO6709: +40.8924-081.4036+351.458/
    com.apple.quicktime.make: Apple
    com.apple.quicktime.model: iPhone 6
    com.apple.quicktime.software: 11.4
    com.apple.quicktime.creationdate: 2018-06-08T04:06:32-0400
  Duration: 00:00:25.27, start: 0.000000, bitrate: 23988 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 23883 kb/s, 59.95 fps, 60 tbr, 600 tbn, 1200 tbc (default)
    Metadata:
      creation_time   : 2018-06-08T08:06:32.000000Z
      handler_name    : Core Media Data Handler
      encoder         : H.264
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 91 kb/s (default)
    Metadata:
      creation_time   : 2018-06-08T08:06:32.000000Z
      handler_name    : Core Media Data Handler
    Stream #0:2(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
    Metadata:
      creation_time   : 2018-06-08T08:06:32.000000Z
      handler_name    : Core Media Data Handler
    Stream #0:3(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
    Metadata:
      creation_time   : 2018-06-08T08:06:32.000000Z
      handler_name    : Core Media Data Handler
[23:56:15] scan: decoding previews for title 1
[23:56:15] scan: audio 0x1: aac, rate=44100Hz, bitrate=91021 Unknown (AAC LC) (1.0 ch)
[23:56:16] scan: 10 previews, 1920x1080, 59.940 fps, autocrop = 0/0/0/0, aspect 16:9, PAR 1:1
[23:56:16] libhb: scan thread found 1 valid title(s)
[23:56:16] macgui: ScanCore scan done
[23:56:25] hb_init: starting libhb thread
[23:56:25] macgui: PreviewCore started encoding preview_temp.m4v
[23:56:25] macgui: PreviewCore with preset Fast 1080p30 (Modified)
[23:56:25] 1 job(s) to process
[23:56:25] starting job
[23:56:25] decomb filter thread started for segment 1
[23:56:25] decomb filter thread started for segment 0
[23:56:25] decomb filter thread started for segment 2
[23:56:25] decomb filter thread started for segment 3
[23:56:25] decomb filter thread started for segment 4
[23:56:25] decomb filter thread started for segment 5
[23:56:25] decomb filter thread started for segment 6
[23:56:25] decomb filter thread started for segment 7
[23:56:25] decomb filter thread started for segment 8
[23:56:25] decomb filter thread started for segment 9
[23:56:25] decomb filter thread started for segment 10
[23:56:25] decomb filter thread started for segment 11
[23:56:25] decomb check thread started for segment 0
[23:56:25] decomb check thread started for segment 1
[23:56:25] decomb check thread started for segment 2
[23:56:25] decomb check thread started for segment 3
[23:56:25] decomb check thread started for segment 4
[23:56:25] decomb check thread started for segment 5
[23:56:25] decomb check thread started for segment 6
[23:56:25] decomb check thread started for segment 7
[23:56:25] decomb check thread started for segment 8
[23:56:25] decomb check thread started for segment 9
[23:56:25] decomb check thread started for segment 10
[23:56:25] decomb check thread started for segment 11
[23:56:25] mask filter thread started for segment 0
[23:56:25] mask filter thread started for segment 1
[23:56:25] mask filter thread started for segment 2
[23:56:25] mask filter thread started for segment 3
[23:56:25] mask filter thread started for segment 4
[23:56:25] mask filter thread started for segment 5
[23:56:25] mask filter thread started for segment 6
[23:56:25] mask filter thread started for segment 7
[23:56:25] mask filter thread started for segment 8
[23:56:25] mask filter thread started for segment 9
[23:56:25] mask filter thread started for segment 10
[23:56:25] mask filter thread started for segment 11
[23:56:25] mask erode thread started for segment 0
[23:56:25] mask erode thread started for segment 1
[23:56:25] mask erode thread started for segment 2
[23:56:25] mask erode thread started for segment 3
[23:56:25] mask erode thread started for segment 4
[23:56:25] mask erode thread started for segment 5
[23:56:25] mask erode thread started for segment 6
[23:56:25] mask erode thread started for segment 7
[23:56:25] mask erode thread started for segment 8
[23:56:25] mask erode thread started for segment 9
[23:56:25] mask erode thread started for segment 10
[23:56:25] mask erode thread started for segment 11
[23:56:25] mask dilate thread started for segment 0
[23:56:25] mask dilate thread started for segment 1
[23:56:25] mask dilate thread started for segment 2
[23:56:25] mask dilate thread started for segment 3
[23:56:25] mask dilate thread started for segment 4
[23:56:25] mask dilate thread started for segment 5
[23:56:25] mask dilate thread started for segment 6
[23:56:25] mask dilate thread started for segment 7
[23:56:25] mask dilate thread started for segment 8
[23:56:25] mask dilate thread started for segment 9
[23:56:25] mask dilate thread started for segment 10
[23:56:25] mask dilate thread started for segment 11
[23:56:25] yadif thread started for segment 0
[23:56:25] yadif thread started for segment 1
[23:56:25] yadif thread started for segment 2
[23:56:25] yadif thread started for segment 3
[23:56:25] yadif thread started for segment 4
[23:56:25] yadif thread started for segment 5
[23:56:25] yadif thread started for segment 6
[23:56:25] yadif thread started for segment 7
[23:56:25] yadif thread started for segment 8
[23:56:25] yadif thread started for segment 9
[23:56:25] yadif thread started for segment 10
[23:56:25] yadif thread started for segment 11
[23:56:25] work: only 1 chapter, disabling chapter markers
[23:56:25] job configuration:
[23:56:25]  * source
[23:56:25]    + /Users/bradley/Desktop/IMG_2411.MOV
[23:56:25]    + title 1, start 00:00:0.00 stop 00:00:30.00
[23:56:25]    + container: mov,mp4,m4a,3gp,3g2,mj2
[23:56:25]    + data rate: 23988 kbps
[23:56:25]  * destination
[23:56:25]    + /Users/bradley/Library/Application Support/HandBrake//Previews/57426/preview_temp.m4v
[23:56:25]    + container: MPEG-4 (libavformat)
[23:56:25]      + align initial A/V stream timestamps
[23:56:25]  * video track
[23:56:25]    + decoder: h264
[23:56:25]      + bitrate 23883 kbps
[23:56:25]    + filters
[23:56:25]      + Comb Detect (mode=3:spatial-metric=2:motion-thresh=1:spatial-thresh=1:filter-mode=2:block-thresh=40:block-width=16:block-height=16)
[23:56:25]      + Decomb (mode=39)
[23:56:25]      + Framerate Shaper (mode=2:rate=27000000/900000)
[23:56:25]        + frame rate: 59.940 fps -> peak rate limited to 30.000 fps
[23:56:25]      + Crop and Scale (width=1920:height=1080:crop-top=0:crop-bottom=0:crop-left=0:crop-right=0)
[23:56:25]        + source: 1920 * 1080, crop (0/0/0/0): 1920 * 1080, scale: 1920 * 1080
[23:56:25]    + Output geometry
[23:56:25]      + storage dimensions: 1920 x 1080
[23:56:25]      + pixel aspect ratio: 1 : 1
[23:56:25]      + display dimensions: 1920 x 1080
[23:56:25]    + encoder: H.265 (libavcodec)
[23:56:25]      + preset:  default
[23:56:25]      + bitrate: 6000 kbps, pass: 0
[23:56:25]      + color profile: 1-1-1
[23:56:25]  * audio track 1
[23:56:25]    + decoder: Unknown (AAC LC) (1.0 ch) (track 1, id 0x1)
[23:56:25]      + bitrate: 91 kbps, samplerate: 44100 Hz
[23:56:25]    + mixdown: Mono
[23:56:25]    + dither: triangular
[23:56:25]    + encoder: AAC (Apple AudioToolbox)
[23:56:25]      + bitrate: 160 kbps, samplerate: 44100 Hz
[23:56:25] sync: expecting 1858 video frames
[23:56:25] encavcodecInit: H.265 (VideoToolbox)
[23:56:25] encavcodec: encoding with stored aspect 1/1
[hevc_videotoolbox @ 0x7fd6751a8c00] Error: cannot create compression session: -12908
[hevc_videotoolbox @ 0x7fd6751a8c00] Try -allow_sw 1. The hardware encoder may be busy, or not supported.
[23:56:25] encavcodecInit: avcodec_open failed
error: Failure to initialise thread 'FFMPEG encoder (libavcodec)'
[23:56:25] comb detect: heavy 0 | light 0 | uncombed 0 | total 0
[23:56:25] decomb: deinterlaced 0 | blended 0 | unfiltered 0 | total 0
[23:56:25] vfr: 0 frames output, 0 dropped and 0 duped for CFR/PFR
[23:56:25] vfr: lost time: 0 (0 frames)
[23:56:25] vfr: gained time: 0 (0 frames) (0 not accounted for)
[23:56:25] aac-decoder done: 0 frames, 0 decoder errors
[23:56:25] h264-decoder done: 0 frames, 0 decoder errors
[23:56:25] sync: got 0 frames, 1858 expected
[23:56:26] libhb: work result = 3
[23:56:26] macgui: PreviewCore work failed
@bradleysepos

This comment has been minimized.

Contributor

bradleysepos commented Sep 4, 2018

Maybe we should just not show the quality slider rather than fooling people into thinking it's true cq.

I agree with this, better to disable the quality mode controls.

A separate slider control with bit rate stops might be a good option; e.g., the bit rate field could be converted to a stepper that adjusts in 5 kbps increments, and the slider could adjust in 100 kbps increments while updating the stepped field.

@galad87

This comment has been minimized.

Contributor

galad87 commented Sep 4, 2018

I don't thing Apple supports Nvidia hardware encoders, and your cpu hasn't got qsv.
Can you run https://subler.org/downloads/VideoToolboxTest.zip and send me the output?

@bradleysepos

This comment has been minimized.

Contributor

bradleysepos commented Sep 4, 2018

@galad87

This comment has been minimized.

Contributor

galad87 commented Sep 4, 2018

I think I fixed it, hb_vt_h265_is_available() wasn't called. You shouldn't see the VideoToolbox HEVC encoder anymore.

@bradleysepos

This comment has been minimized.

Contributor

bradleysepos commented Sep 4, 2018

Confirmed fixed. Tests fine on Ubuntu Bionic as well.

@mackworth mackworth referenced this pull request Oct 2, 2018

Closed

Egpu/GPUs implemetation #336

@sr55 sr55 modified the milestones: 1.2.0, 1.3.0 Oct 3, 2018

@sr55

This comment has been minimized.

Member

sr55 commented Nov 4, 2018

Do we want to ship this with 1.2?

Regarding the quality option. I'm fine with just hiding it, since it may confuse/mis-lead by faking it.

@bradleysepos

This comment has been minimized.

Contributor

bradleysepos commented Nov 6, 2018

@galad87 Any chance you'll have time to disable the CQ controls for this so we can merge for 1.2.0?

@bradleysepos bradleysepos added this to the 1.2.0 milestone Nov 6, 2018

@galad87

This comment has been minimized.

Contributor

galad87 commented Nov 7, 2018

Yes, I'll merge this after #1656 is in.

@galad87

This comment has been minimized.

Contributor

galad87 commented Nov 15, 2018

Improved and committed in 5c127e8

@galad87 galad87 closed this Nov 15, 2018

@Luistrenker

This comment has been minimized.

Luistrenker commented Nov 24, 2018

h265 (toolbox) stops with error after some seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment