Open ken626014896 opened 3 years ago
你需要main里调用javaVM(void)或者SetGlobalOption("jvm", void),值为QAndroidJniEnvironment::javaVM()。一般的android app是在JNI_OnLoad调用。
好的谢谢,现在可以硬解了,但是好像一卡一卡的,还没cpu流畅,手机本地播放器倒是很流畅,请问这个是为什么,缓存吗,感觉加了也没影响
可能是qt的paintgl调得太慢了。你可以对比下这个例子里的效果 https://github.com/wang-bin/mdk-android
我也遇到了,Android TV上视频很慢,声音是正常的,感觉像是渲染上慢了
请问如果要使用qt来写,不使用原生java开发,要怎么解决这个渲染的问题
我加了测量渲染一帧gpu、cpu耗时的代码到时候可以看下哪里出的问题,不过还没加接口
用最新sdk,在JNI_OnLoad
加上
setLogHandler([](LogLevel v, const char* msg){
if (v < LogLevel::Info)
__android_log_print(ANDROID_LOG_WARN, "MDK-JNI", "%s", msg);
else
__android_log_print(ANDROID_LOG_DEBUG, "MDK-JNI", "%s", msg);
});
SetGlobalOption("profiler.gpu", 1);
SetGlobalOption("logLevel", "all");
播放时会在logcat里输出这样的log
>393 00:00:01.1/00:01:34 buffered 16950ms/137971KB 235101KB/s 13fps@1.00 diff |-293|>5ms update 36/92ms, draw 3/9ms gpu 1695/1713us
包含绘制帧率、调用间隔、一帧的cpu耗时、gpu耗时,看看有什么异常的。可以贴个完整的log
D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @8 11-02 09:47:14.155 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >469 00:00:00.3/00:01:34 buffered 3795ms/34102KB 29KB/s 35fps@1.00 diff |-93|>5ms update 45/74ms, draw 19/90ms gpu 42966/70659us 11-02 09:47:14.258 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @5 11-02 09:47:14.489 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >709 00:00:00.6/00:01:34 buffered 3503ms/31951KB 23KB/s 29fps@1.00 diff |-41|>5ms update 42/74ms, draw 11/90ms gpu 33764/70659us 11-02 09:47:14.532 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @10 11-02 09:47:14.639 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >1029 00:00:00.9/00:01:34 buffered 3797ms/38194KB 100409KB/s 25fps@1.00 diff |-69|>5ms update 44/74ms, draw 3/6ms gpu 31904/70659us 11-02 09:47:14.824 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @10 11-02 09:47:14.896 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >1348 00:00:01.2/00:01:34 buffered 3878ms/37496KB 49KB/s 24fps@1.00 diff |-55|>5ms update 45/75ms, draw 3/6ms gpu 29122/29210us 11-02 09:47:15.138 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @7 11-02 09:47:15.298 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >1588 00:00:01.5/00:01:34 buffered 3461ms/34798KB 23KB/s 25fps@1.00 diff |-3|<5ms update 46/79ms, draw 3/5ms gpu 29119/29195us 11-02 09:47:15.417 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @4 11-02 09:47:15.620 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >1908 00:00:01.8/00:01:34 buffered 3925ms/39239KB 183208KB/s 23fps@1.00 diff |-72|>5ms update 45/83ms, draw 3/5ms gpu 29115/29195us 11-02 09:47:15.697 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @3 11-02 09:47:15.778 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @3 11-02 09:47:16.018 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >2228 00:00:02.1/00:01:34 buffered 3795ms/39091KB 122KB/s 23fps@1.00 diff |-59|>5ms update 50/83ms, draw 3/6ms gpu 29114/29195us 11-02 09:47:16.021 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @3 11-02 09:47:16.256 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >2548 00:00:02.4/00:01:34 buffered 3586ms/34830KB 23KB/s 22fps@1.00 diff |-87|>5ms update 52/83ms, draw 4/6ms gpu 30190/32028us 11-02 09:47:16.359 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @8 11-02 09:47:16.413 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @3 11-02 09:47:16.537 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @8 11-02 09:47:16.658 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >2868 00:00:02.7/00:01:34 buffered 3968ms/39985KB 194162KB/s 23fps@1.00 diff |-73|>5ms update 56/100ms, draw 4/6ms gpu 31105/32051us 11-02 09:47:16.661 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @8 11-02 09:47:16.901 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >3108 00:00:03.0/00:01:34 buffered 4003ms/39373KB 7500KB/s 24fps@1.00 diff |-21|>5ms update 55/100ms, draw 4/9ms gpu 32029/32098us 11-02 09:47:16.970 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @8 11-02 09:47:17.145 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >3428 00:00:03.3/00:01:34 buffered 3712ms/37163KB 23KB/s 24fps@1.00 diff |-49|>5ms update 55/100ms, draw 4/9ms gpu 32031/32098us 11-02 09:47:17.222 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @8 11-02 09:47:17.379 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >3670 00:00:03.6/00:01:34 buffered 3503ms/34447KB 30KB/s 25fps@1.00 diff |+1|<5ms update 46/72ms, draw 5/10ms gpu 32027/32047us 11-02 09:47:17.501 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >3989 00:00:03.9/00:01:34 buffered 3946ms/40865KB 244641KB/s 23fps@1.00 diff |-68|>5ms update 45/72ms, draw 5/12ms gpu 31865/32047us 11-02 09:47:17.782 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @6 11-02 09:47:17.942 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >4229 00:00:04.2/00:01:34 buffered 4010ms/38359KB 7500KB/s 25fps@1.00 diff |-16|>5ms update 47/76ms, draw 4/12ms gpu 30769/32047us 11-02 09:47:18.037 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @3 11-02 09:47:18.180 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >4511 00:00:04.4/00:01:34 buffered 3712ms/36077KB 24KB/s 23fps@1.00 diff |-48|>5ms update 47/82ms, draw 4/12ms gpu 29853/32033us 11-02 09:47:18.338 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @10 11-02 09:47:18.386 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @6 11-02 09:47:18.520 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >4788 00:00:04.7/00:01:34 buffered 3461ms/33912KB 23KB/s 22fps@1.00 diff |-74|>5ms update 52/85ms, draw 4/5ms gpu 29123/29388us 11-02 09:47:18.612 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @10 11-02 09:47:18.666 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >5071 00:00:05.0/00:01:34 buffered 3861ms/37407KB 122926KB/s 23fps@1.00 diff |-24|>5ms update 52/90ms, draw 4/7ms gpu 31971/40521us 11-02 09:47:18.899 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @4 11-02 09:47:19.064 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >5348 00:00:05.3/00:01:34 buffered 3837ms/38218KB 54KB/s 26fps@1.00 diff |-9|>5ms update 50/90ms, draw 4/7ms gpu 32194/40521us 11-02 09:47:19.187 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >5668 00:00:05.6/00:01:34 buffered 3670ms/35723KB 23KB/s 24fps@1.00 diff |-37|>5ms update 40/81ms, draw 3/7ms gpu 31466/40521us 11-02 09:47:19.463 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @3 11-02 09:47:19.539 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >5922 00:00:05.9/00:01:34 buffered 3420ms/33419KB 23KB/s 23fps@1.00 diff |+13|>5ms update 40/70ms, draw 4/7ms gpu 29109/29188us 11-02 09:47:19.773 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @5 11-02 09:47:19.941 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >6229 00:00:06.2/00:01:34 buffered 4010ms/37503KB 7500KB/s 22fps@1.00 diff |-14|>5ms update 49/87ms, draw 4/7ms gpu 29105/29113us 11-02 09:47:20.065 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >6511 00:00:06.5/00:01:34 buffered 3712ms/35197KB 24KB/s 23fps@1.00 diff |-4|<5ms update 47/87ms, draw 4/6ms gpu 29110/29192us 11-02 09:47:20.337 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >6798 00:00:06.7/00:01:34 buffered 3503ms/32575KB 30KB/s 24fps@1.00 diff |+9|>5ms update 39/68ms, draw 4/9ms gpu 29110/29192us 11-02 09:47:20.636 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >7071 00:00:07.0/00:01:34 buffered 3882ms/36798KB 57769KB/s 23fps@1.00 diff |-22|>5ms update 40/79ms, draw 4/9ms gpu 29106/29114us 11-02 09:47:20.902 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @9 11-02 09:47:20.980 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >7348 00:00:07.3/00:01:34 buffered 3837ms/33646KB 55KB/s 24fps@1.00 diff |-7|>5ms update 45/82ms, draw 4/9ms gpu 29107/29117us 11-02 09:47:21.163 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @5 11-02 09:47:21.296 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >7590 00:00:07.5/00:01:34 buffered 3628ms/31789KB 23KB/s 24fps@1.00 diff |+2|<5ms update 44/82ms, draw 4/7ms gpu 30203/32053us 11-02 09:47:21.425 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >7908 00:00:07.8/00:01:34 buffered 3586ms/33771KB 14778KB/s 23fps@1.00 diff |-66|>5ms update 44/82ms, draw 4/7ms gpu 30411/32114us 11-02 09:47:21.706 24625 24682 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >8889 00:00:08.9/00:01:34 buffered 2986ms/36844KB 226430KB/s 23fps@1.00 11-02 09:47:22.736 24625 24683 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >9188 00:00:09.2/00:01:34 buffered 2687ms/36837KB 226430KB/s 23fps@1.00 11-02 09:47:22.985 24625 24683 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >9444 00:00:09.5/00:01:34 buffered 2431ms/36831KB 226430KB/s 23fps@1.00 11-02 09:47:23.294 24625 24683 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >9721 00:00:09.7/00:01:34 buffered 2154ms/36824KB 226430KB/s 23fps@1.00 11-02 09:47:23.545 24625 24683 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >9999 00:00:10.0/00:01:34 buffered 1877ms/36818KB 226430KB/s 23fps@1.00 11-02 09:47:23.855 24625 24683 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >10297 00:00:10.3/00:01:34 buffered 1578ms/36811KB 226430KB/s 23fps@1.00 11-02 09:47:24.107 24625 24683 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >10553 00:00:10.6/00:01:34 buffered 1322ms/36805KB 226430KB/s 23fps@1.00 11-02 09:47:24.415 24625 24683 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >10852 00:00:10.9/00:01:34 buffered 1023ms/36798KB 226430KB/s 23fps@1.00 11-02 09:47:24.666 24625 24683 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >11129 00:00:11.2/00:01:34 buffered 746ms/36791KB 226430KB/s 23fps@1.00 11-02 09:47:24.976 24625 24683 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >11407 00:00:11.4/00:01:34 buffered 469ms/36785KB 226430KB/s 23fps@1.00 11-02 09:47:25.228 24625 24683 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI >11684 00:00:11.7/00:01:34 buffered 191ms/36778KB 226430KB/s 23fps@1.00 11-02 09:47:25.535 24625 24683 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI buffering progress 0% 11-02 09:47:25.697 24625 24683 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI default 0xe62c4a40 FrameReader::update MediaStatus 0X124=>0X114 11-02 09:47:25.697 24625 24683 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI ++++++++++++BUFFERING START++++++++++++ 11-02 09:47:25.697 24625 24683 D testMdk : D testMdk : ANDROID_LOG_DEBUG, MDK-JNI D : PlayerBase::stop() from IPlayer D AudioTrack: stop() called with 578560 frames delivered
这个视频解着解着就卡住了,以上是视频的参数
谢谢你的log,从log看渲染一帧gpu耗时特别长,解码出帧速度比渲染快,渲染器里缓存的帧来不急渲染就被覆盖了,比如
D testMdk : ANDROID_LOG_DEBUG, MDK-JNI release MediaCodec output buffer which was not rendered @5
可以尝试增加缓存的帧数看看这种log会不会减少 SetGlobalOption("videoout.buffer_frames", 16);
,默认是4
这个视频解着解着就卡住了,以上是视频的参数
解码器参数是怎么设的?已知的是java=1会导致一些h264解不出正确画面,原因还不清楚,可以用java=0。
方便的话完整的log上传一份。可以的话视频也给一个我看看能否复现。
I zygote : Late-enabling -Xcheck:jni
W ResourceType: No package identifier when getting name for resource number 0x00000000
W ResourceType: No package identifier when getting name for resource number 0x00000000
E InterceptorFactory: NameNotFoundException
E InterceptorFactory: android.content.pm.PackageManager$NameNotFoundException: com.miui.contentcatcher
E InterceptorFactory: at android.app.ApplicationPackageManager.getPackageInfoAsUser(ApplicationPackageManager.java:174)
E InterceptorFactory: at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:145)
E InterceptorFactory: at miui.contentcatcher.InterceptorFactory.getInterceptorPackageInfo(InterceptorFactory.java:80)
E InterceptorFactory: at miui.contentcatcher.InterceptorFactory.initInterceptorClass(InterceptorFactory.java:99)
E InterceptorFactory: at miui.contentcatcher.InterceptorFactory.createInterceptor(InterceptorFactory.java:41)
E InterceptorFactory: at miui.contentcatcher.InterceptorProxy$H.handleMessage(InterceptorProxy.java:323)
E InterceptorFactory: at android.os.Handler.dispatchMessage(Handler.java:106)
E InterceptorFactory: at android.os.Looper.loop(Looper.java:173)
E InterceptorFactory: at android.os.HandlerThread.run(HandlerThread.java:65)
W System : ClassLoader referenced unknown path:
D AccessibilityManager: AccessibilityManager status: mPackageName = org.qtproject.example.testMDK, mOptimizeEnabled = false, mIsEnabled = false, mIsUiAutomationEnabled = false, mIsInterestedPackage =false
D Qt JAVA : Class org.qtproject.qt5.android.multimedia.QtMultimediaUtils does not implement setActivity method
I QtCore : Start
I Qt : qt started
I MDK : MDK 0.17.0 (git 52a28d0) - Multimedia Development Kit. Copyright (c) 2016-2022 WangBin(QtAV author)
log 里的update表示两次绘制的平均间隔,看上去间隔有点长,40~50多毫秒,这样帧率比解码慢,会有一部分帧没渲染。你试试用定时器来渲染
试下最新的包有没有流畅点。顺便贴下log
好的,这两天我试试,之前一直在忙其他东西
这个是解码设备 SetGlobalOption("profiler.gpu", 1); SetGlobalOption("logLevel", "all"); setMirrorVertically(true); SetGlobalOption("videoout.buffer_frames", 16); // internal_player->setFrameRate(25);
internal_player->setDecoders(MediaType::Video, {"MFT:d3d=11:copy=0", "D3D11", "DXVA", "CUDA", "FFmpeg"});
SetGlobalOption("jvm", QAndroidJniEnvironment::javaVM());
internal_player->setDecoders(MediaType::Video,{"AMediaCodec:java=0:copy=0:surface=1:async=0","FFmpeg"});
// internal_player->setBufferRange(0,1000,true);
internal_player->setAspectRatio(0);
// internal_player->setMute(true);
更新到最新sdk后,之前那个视频有时候播放不了,播放的了也很不流畅
这个是播放不了的log
I zygote : Late-enabling -Xcheck:jni
W ResourceType: No package identifier when getting name for resource number 0x00000000
W ResourceType: No package identifier when getting name for resource number 0x00000000
E InterceptorFactory: NameNotFoundException
E InterceptorFactory: android.content.pm.PackageManager$NameNotFoundException: com.miui.contentcatcher
E InterceptorFactory: at android.app.ApplicationPackageManager.getPackageInfoAsUser(ApplicationPackageManager.java:174)
E InterceptorFactory: at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:145)
E InterceptorFactory: at miui.contentcatcher.InterceptorFactory.getInterceptorPackageInfo(InterceptorFactory.java:80)
E InterceptorFactory: at miui.contentcatcher.InterceptorFactory.initInterceptorClass(InterceptorFactory.java:99)
E InterceptorFactory: at miui.contentcatcher.InterceptorFactory.createInterceptor(InterceptorFactory.java:41)
E InterceptorFactory: at miui.contentcatcher.InterceptorProxy$H.handleMessage(InterceptorProxy.java:323)
E InterceptorFactory: at android.os.Handler.dispatchMessage(Handler.java:106)
E InterceptorFactory: at android.os.Looper.loop(Looper.java:173)
E InterceptorFactory: at android.os.HandlerThread.run(HandlerThread.java:65)
W System : ClassLoader referenced unknown path:
D AccessibilityManager: AccessibilityManager status: mPackageName = org.qtproject.example.testMDK, mOptimizeEnabled = false, mIsEnabled = false, mIsUiAutomationEnabled = false, mIsInterestedPackage =false
D Qt JAVA : Class org.qtproject.qt5.android.multimedia.QtMultimediaUtils does not implement setActivity method
I QtCore : Start
I Qt : qt started
I MDK : MDK 0.18.0 (git cef23ef) - Multimedia Development Kit. Copyright (c) 2016-2022 WangBin(QtAV author)
卡住的原因出在qt的update不一定会触发重绘,于是渲染器里的视频帧没有全部被渲染,不渲染就不能被解码器回收,解码器就无法输出新的帧。在渲染性能跟不上的时候容易出现,windows上也复现了。 可以在renderVideo()后面再直接调一次update()应该能解决问题
D pushclient: mdk log opening video decoder: AMediaCodec:java=1:copy=0:surface=1:async=1:cache_output=16... D pushclient: mdk log CodecForMimeType: video/avc, profile: 2, level: -1 D pushclient: mdk log JMI ERROR: java vm is null D pushclient: mdk log JMI ERROR: java vm is null D pushclient: mdk log ERROR! failed to setup decoder: video
这个是打印信息,请问java vm is null是什么意思
我的是qt5.12 ndk是r21