3

I've signed up to the Go Pro Developer program and set up the camera so that I can receive raw data. Ultimately I want to serve this data in a live stream via HLS.

The app currently creates a .m3u8 file and chunks the data I'm receiving into new .ts files every five seconds. However when I attempt to play this stream, nothing is played so I'm not convinced that the data I'm saving as "ts" is actually in the right format.

I gather that each time the function below is called, the data passed represents one or more TS packets, but are those packets being saved in the right format please?

I've checked the format of the .m3u8 file with mediastreamvalidator but it doesn't give any clues about any faults with the ts files.


I converted an example from the documentation into Swift and added a little of my own code as follows:

func output(_ output: GPCameraPlayerOutput!, didOutputBuffer bytes: UnsafePointer<UInt8>!, length: Int) {

    // TS packets are always 188 bytes
    for i in stride(from: 0, to: length, by: CameraPreviewViewController.TSPacketSize) {

        /First byte should be the "sync byte"
        if Int(bytes[i]) != CameraPreviewViewController.SyncByte {
            continue //Sync byte expected
        }

        let pid = (Int(bytes[i + 1] & 0x1F)) << 8 | Int(bytes[i + 2]) //read the next 13 bits as an int
        if pid == CameraPreviewViewController.H264 {
            //parse video data
            let packet : UnsafePointer<UInt8> = bytes.advanced(by: i)
            currentTSOutputStream.write(packet, maxLength: CameraPreviewViewController.TSPacketSize)

            [clipped - occasionally save the ts stream and start a new one]

        }
        else if pid == CameraPreviewViewController.ACC {
            //ignore audio data
        }
        else {
            print ("Unknown Data: \(pid)")
        }
    }
}

I've also tried saving all of the packets but with no change.

James Webster
  • 31,873
  • 11
  • 70
  • 114
  • Can you provide a sample capture? In any case you can't just filter the video packets in an MPEG-TS stream, there are other PIDs besides A/V which carry information about the programs/streams. You also shouldn't segment an MPEG-TS stream at random. There should be at least an IDR frame per segment, preferably at the start. – aergistal Sep 19 '17 at 15:36

0 Answers0