qt 调用 ffmpeg 录音,遇到了权限问题折腾了挺长时间,记录下一个可用的方法,
在qt 创建的项目根目录创建 Info.plist
文件
xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<true/>
<!-----上面的字段估计没有用 -->
<!-- 权限字段 -->
<key>NSCameraUsageDescription</key>
<string>This app needs camera access to capture photos and videos</string>
<key>NSCameraUseContinuityCameraDeviceType</key>
<true/>
<!-- <key>NSCameraUsageDescription</key>
<string>需要相机权限来拍摄照片</string> -->
<key>NSMicrophoneUsageDescription</key>
<string>需要麦克风权限来录制音频</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>需要位置权限来提供定位服务</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>需要访问照片库来保存和读取图片</string>
</dict>
</plist>
.pro
文件
.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
FFMPEG_HOME = /usr/local/Cellar/ffmpeg/7.1.1_2
INCLUDEPATH += $${FFMPEG_HOME}/include
LIBS += -L $${FFMPEG_HOME}/lib \
-lavdevice \
-lavformat \
-lavcodec \
-lavutil
# 设置 Info.plist 文件
QMAKE_INFO_PLIST = $$PWD/Info.plist
终于可以正常的拉起麦克风了