DJI Bridge App教程Swift中没有视频流 - Phantom 4 Pro

时间:2017-04-14 19:53:13

标签: swift video dji-sdk

我目前正在通过DJI Bridge App Tutorial。我正在使用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的视图集始终为黑色。下面是整个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

1 个答案:

答案 0 :(得分:1)

你应该尝试将VideoPreview.instance()设置为方便的地方并使用它。

此外,确保在将监听器添加到视频源时提供有效队列。

尝试这些并让我知道它是否有帮助。