最近搞新專案,需要在C++層里實作各種音視頻邏輯,在網上下載了FFmpeg等庫放入Android Studio后,出現各種問題,現在都匯總記錄下~
1.外接UVC協議的攝像頭時,插上攝像頭后,有顯示設備串列,但是就沒有畫面出來,外接攝像頭是用了開源庫的LibUvcCamera日志也報這樣的錯:
[506*UVCCamera.cpp:172:connect]:could not open camera:err=-1
E/AndroidRuntime: FATAL EXCEPTION: BaseActivity
Process: com.serenegiant.usbcameratest0, PID: 7753
java.lang.UnsupportedOperationException: open failed:result=-1
at com.serenegiant.usb.UVCCamera.open(UVCCamera.java:204)
at com.serenegiant.usbcameratest0.MainActivity$2$1.run(MainActivity.java:149)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
查了很多資料,都說更換NDK版本,但是我試了不行,后來又查了很多資料,在外國一論壇有個大神說toolchain版本有關,然后看了原始碼編譯的Application.mk剛好注釋掉了,所以我去掉注釋讓其生效:
NDK_TOOLCHAIN_VERSION := 4.9
發現沒有報錯,也能正常顯示畫面了,下面附上Application.mk修改后的完整代碼:
#/*
# * UVCCamera
# * library and sample to access to UVC web camera on non-rooted Android device
# *
# * Copyright (c) 2014-2017 saki t_saki@serenegiant.com
# *
# * File name: Application.mk
# *
# * Licensed under the Apache License, Version 2.0 (the "License");
# * you may not use this file except in compliance with the License.
# * You may obtain a copy of the License at
# *
# * http://www.apache.org/licenses/LICENSE-2.0
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *
# * All files in the folder are under this Apache License, Version 2.0.
# * Files in the jni/libjpeg, jni/libusb, jin/libuvc, jni/rapidjson folder may have a different license, see the respective files.
#*/
# This is just for mips, if you really needs MSA, un-comment and build with GCC.
# Note: Supporting GCC on NDK is already deprecated and GCC will be removed from NDK soon.
NDK_TOOLCHAIN_VERSION := 4.9
APP_PLATFORM := android-14
#APP_ABI := armeabi armeabi-v7a x86 mips
APP_ABI := armeabi-v7a
#APP_OPTIM := debug
APP_OPTIM := release
2.接著ffmpeg和meadiaCodec相關的庫:
error: no type named 'shared_ptr' in namespace 'std'
解決辦法,在對應檔案加入:#include<memory>
error: no type named 'condition_variable' in namespace 'std'
在報錯檔案加入:#include <condition_variable>
error: use of undeclared identifier 'free'
在報錯檔案頭加入:#include <stdlib.h>
最后編譯時,因為有很多庫相互依賴,會出現這樣錯誤:
More than one file was found with OS independent path 'lib/arm64-v8a/libyuv.so'. If you are using jniLibs and CMake IMPORTED targets
則需在build.gradle加入如下這句:
packagingOptions {
pickFirst 'lib/arm64-v8a/libffmpeg.so'
pickFirst 'lib/arm64-v8a/libyuv.so'
pickFirst 'lib/armeabi-v7a/libyuv.so'
pickFirst 'lib/armeabi-v7a/libffmpeg.so'
}
我這里是提示了才加的,沒提示的不用加,
packagingOptions放在android目錄里即可
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/304568.html
標籤:其他
下一篇:AS開發實驗一:仿微信界面
