我目前正在学习 DJI Bridge App 教程。我将 Swift 与导入 VideoPreviewer 的桥头一起使用。应用程序编译得很好。我可以连接到产品。我可以注册。桥接应用程序工作正常。但我被视频流卡住了。你有什么想法吗?
方法
"func videoFeed(_ videoFeed: DJIVideoFeed, didUpdateVideoData videoData: Data)
被正确调用。从 Data 对象读取字节时。我收到了一些价值观。比将这些值发送到 VidePreviewer 作为
func videoFeed(_ videoFeed: DJIVideoFeed, didUpdateVideoData videoData: Data) {
var result = videoData.withUnsafeBytes { (pointer: UnsafePointer<UInt8>) -> UInt8 in
return pointer.pointee
}
print (result)
print("Stream info:\(VideoPreviewer.instance().currentStreamInfo.frameRate)")
VideoPreviewer.instance().push(&result, length: Int32(videoData.count))
print(VideoPreviewer.instance().isDefaultPreviewer)
}"
然而这是正确的吗?DJIVideoStreamBasicInfo(frameSize: (0.0, 0.0), frameRate: 15, encoderType: 1)。print(result)返回值-----但是frameSize是0.0,0.0会是这个问题吗?----- 结果是为VideoPreviewer设置的View总是黑色的。下面是整个 DJICameraViewController.swift 的整个 Swift 文件的代码,它可以编译并运行。
导入 UIKit 导入 DJISDK
DJICameraViewController 类:UIViewController、DJISDKManagerDelegate、DJICameraDelegate、DJIBaseProductDelegate、DJIVideoFeedListener {
var camera: DJICamera!
@IBOutlet weak var fpvPreviewView: UIView!
@IBOutlet weak var recordBtn: UIButton!
@IBOutlet weak var changeWorkModeSegmentControl: UISegmentedControl!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.registerApp()
VideoPreviewer.instance().setView(self.fpvPreviewView)
}
override func viewWillDisappear(_ animated: Bool){
super.viewWillDisappear(animated)
VideoPreviewer.instance().setView(nil)
DJISDKManager.videoFeeder()?.primaryVideoFeed.remove(self)
}
func registerApp(){
DJISDKManager.registerApp(with: self)
}
func appRegisteredWithError(_ error:Error?)
{
var message: String = "Application is registered."
if (error != nil) {
message = "Register App Failed!"
} else {
message = "Application is registered."
DJISDKManager.enableBridgeMode(withBridgeAppIP: "192.168.2.2")
DJISDKManager.startConnectionToProduct()
VideoPreviewer.instance().start()
}
DispatchQueue.main.async {
let alert = UIAlertController(title: "Alert", message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
/* after product is recognized. FetchCamera method is called by method productConnected */
func fetchCamera() -> DJICamera? {
if ((DJISDKManager.product()) == nil){
return nil
}
if (DJISDKManager.product()!.isKind(of: DJIAircraft.self)){
print("Have UAV")
return ((DJISDKManager.product() as? DJIAircraft)?.camera)!
}
return nil
}
/* DJIBaseProductDelegate method called when product is recognized */
func productConnected(_ product: DJIBaseProduct?) {
print("Product recognized")
if ((product) != nil) {
product?.delegate = self
camera = self.fetchCamera()
if (camera != nil) {
camera.delegate = self
DJISDKManager.videoFeeder()?.primaryVideoFeed.add(self, with: nil)
}
}
}
func videoFeed(_ videoFeed: DJIVideoFeed, didUpdateVideoData videoData: Data) {
var result = videoData.withUnsafeBytes { (pointer: UnsafePointer<UInt8>) -> UInt8 in
return pointer.pointee
}
print (result)
print("Stream info:\(VideoPreviewer.instance().currentStreamInfo.frameRate)")
VideoPreviewer.instance().push(&result, length: Int32(videoData.count))
print(VideoPreviewer.instance().isDefaultPreviewer)
}
}
从 Xcode 控制台下面的代码打印输出如下
`print("Stream info:\(videoPreview.currentStreamInfo.frameRate)")
VideoPreviewer.instance().push(&result, length: Int32(videoData.count))
print(videoPreview.currentStreamInfo)
print(videoPreview.isDefaultPreviewer)`
上面打印代码打印的输出:
开始:
Stream info:0
DJIVideoStreamBasicInfo(frameSize: (0.0, 0.0), frameRate: 0, encoderType: 0)
true
136
第二:
Stream info:0
[h264 @ 0x102024210] sps_id 32 out of range
VUI timing infomation not present, set to default:29.97fps
[h264 @ 0x102024210] sps_id 32 out of range
VUI timing infomation not present, set to default:29.97fps
[h264 @ 0x102024210] missing picture in access unit with size 958351
DJIVideoStreamBasicInfo(frameSize: (0.0, 0.0), frameRate: 0, encoderType: 0)
true
65
第三:
Stream info:15
DJIVideoStreamBasicInfo(frameSize: (0.0, 0.0), frameRate: 15, encoderType: 1)
true
119
有时会弹出:
Stream info:15
[h264 @ 0x102024210] SEI type 103 size 1712 truncated at 288
[h264 @ 0x102024210] sps_id 32 out of range
VUI timing infomation not present, set to default:29.97fps
[h264 @ 0x102024210] missing picture in access unit with size 111113
DJIVideoStreamBasicInfo(frameSize: (0.0, 0.0), frameRate: 15, encoderType:
[h264 @ 0x102024810] SEI type 103 size 1712 truncated at 279
其他时间弹出:
Stream info:15
DJIVideoStreamBasicInfo(frameSize: (0.0, 0.0), frameRate: 15, encoderType: 1)
[h264 @ 0x102024810] sps_id 32 out of range
true
[h264 @ 0x102024810] sps_id 32 out of range
[h264 @ 0x102024810] sps_id 32 out of range
[h264 @ 0x102024810] sps_id 32 out of range
[h264 @ 0x102024810] sps_id 32 out of range
0[h264 @ 0x102024810]
sps_id 32 out of range