libobjc / SGPlayer

A powerful media play framework for iOS, macOS, and tvOS.
MIT License
2.14k stars 417 forks source link

如何开启硬解呢? #109

Closed debugly closed 5 years ago

debugly commented 5 years ago

设置了也没用, [[[SGOptions sharedOptions] decoder] setHardwareDecodeH264:YES]; self.player = [[SGPlayer alloc] init];

播放时 CPU 占用高达70% 左右。

* thread #2, queue = 'NSOperationQueue 0x101444560 (QOS: USER_INTERACTIVE)', stop reason = step in
  * frame #0: 0x00000001002c478e SGPlayer`avcodec_send_packet(avctx=0x000000010303be00, avpkt=0x0000000101418670) at decode.c:679:36 [opt]
    frame #1: 0x000000010004ee59 SGPlayer`-[SGCodecContext decode:](self=0x000060000179c040, _cmd="decode:", packet=0x00006000033054a0) at SGCodecContext.m:84:18
    frame #2: 0x000000010004b059 SGPlayer`-[SGAudioDecoder processPacket:](self=0x0000600001794900, _cmd="processPacket:", packet=0x00006000033054a0) at SGAudioDecoder.m:130:21
    frame #3: 0x000000010004a97f SGPlayer`-[SGAudioDecoder decode:](self=0x0000600001794900, _cmd="decode:", packet=0x00006000033054a0) at SGAudioDecoder.m:88:40
    frame #4: 0x0000000100054147 SGPlayer`-[SGDecodeLoop runningThread](self=0x0000600002c30e80, _cmd="runningThread") at SGDecodeLoop.m:305:32
    frame #5: 0x00007fff2e2be2bc CoreFoundation`__invoking___ + 140
    frame #6: 0x00007fff2e2be15f CoreFoundation`-[NSInvocation invoke] + 305
    frame #7: 0x00007fff30abbf13 Foundation`-[NSInvocationOperation main] + 37
    frame #8: 0x00007fff30b822c0 Foundation`__NSOPERATION_IS_INVOKING_MAIN__ + 17
    frame #9: 0x00007fff309e7af4 Foundation`-[NSOperation start] + 731
    frame #10: 0x00007fff30b826ce Foundation`__NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 17
    frame #11: 0x00007fff30a10ed8 Foundation`__NSOQSchedule_f + 182
    frame #12: 0x0000000101019793 libdispatch.dylib`_dispatch_call_block_and_release + 12
    frame #13: 0x000000010101a76f libdispatch.dylib`_dispatch_client_callout + 8
    frame #14: 0x000000010101d5c9 libdispatch.dylib`_dispatch_continuation_pop + 585
    frame #15: 0x000000010101c6bd libdispatch.dylib`_dispatch_async_redirect_invoke + 769
    frame #16: 0x000000010102e331 libdispatch.dylib`_dispatch_root_queue_drain + 334
    frame #17: 0x000000010102eda3 libdispatch.dylib`_dispatch_worker_thread2 + 127
    frame #18: 0x00000001010a604d libsystem_pthread.dylib`_pthread_wqthread + 220
    frame #19: 0x00000001010a5ef3 libsystem_pthread.dylib`start_wqthread + 15
(lldb) 
debugly commented 5 years ago

进展:

我发现 homebrew 编译的 ffmepg 是支持 videotoolbox 的:

 ffmpeg -hwaccels
ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
  configuration: 
  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
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
Hardware acceleration methods:
videotoolbox

但是使用项目里的 build 脚本config出来的头文件里找到 CONFIG_H264_VIDEOTOOLBOX_HWACCEL 为 0 ,所以在确定 pix fmt 的代码里,就没有把 AV_PIX_FMT_VIDEOTOOLBOX 加进去,导致最终没走硬解。

config 选项里可以看出,videotoolbox 是自动选择的,至于为啥选择不使用,还没查出原因,不知道跟我使用 mac 10.15 beta 版有没有关系! --disable-videotoolbox disable VideoToolbox code [autodetect]

debugly commented 5 years ago

降级到 10.14 编译后 CONFIG_H264_VIDEOTOOLBOX_HWACCEL 变成 1 了,支持硬解了!看来是 mac 10.15 beta 的问题....