Skip to content

I am reading h264 Data with UDP and I need to convert it to Video #1

@uguraltinsoy

Description

@uguraltinsoy

I am reading h264 Data via UDP and I need to convert it to Video. I have seen your H264Decoder and can you help me how to use it?

The Data I read from UdpSocket is raw data and how can I decode it with H264 and convert it to image. I found your github library stackoverflow
forums developer here I have my full codes

import Foundation
import AVFoundation
import CoreMedia
import VideoDecoder
import SwiftUI
import Network
import Combine
import CocoaAsyncSocket
import VideoToolbox

class UDPManager: NSObject, ObservableObject, GCDAsyncUdpSocketDelegate {
    private let host: String
    private let port: UInt16
    private var socket: GCDAsyncUdpSocket?
    @Published var videoOutput: CMSampleBuffer?
    
    init(host: String, port: UInt16) {
        self.host = host
        self.port = port
    }
    
    func connectUDP() {
        do {
            socket = GCDAsyncUdpSocket(delegate: self, delegateQueue: .global())
            try socket?.bind(toPort: port)
            try socket?.enableBroadcast(true)
            try socket?.enableReusePort(true)
            try socket?.beginReceiving()
            
        } catch {
            print("UDP soketi oluşturma hatası: \(error)")
        }
    }
    
    func closeUDP() {
        socket?.close()
    }
    
    func udpSocket(_ sock: GCDAsyncUdpSocket, didConnectToAddress address: Data) {
        print("UDP Bağlandı.")
    }
    
    func udpSocket(_ sock: GCDAsyncUdpSocket, didNotConnect error: Error?) {
        print("UDP soketi bağlantı hatası: \(error?.localizedDescription ?? "Bilinmeyen hata")")
    }
    
    func udpSocket(_ sock: GCDAsyncUdpSocket, didReceive data: Data, fromAddress address: Data, withFilterContext filterContext: Any?) {
        if !data.isEmpty {
            //  Raw Data
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions