Skip to main content
Participant
August 21, 2013
Question

UDP video stream to Air for iOS - not working

  • August 21, 2013
  • 1 reply
  • 2450 views

Hi everyone.

My client has asked me to look at the possibility of writing an iOS app which will immediately start displaying a video from a UDP stream.

The emphasis here is on instant playback without load times, buffering, etc.

I'm using Flash Professional CS6, and Air for iOS (3.8).

THE PROBLEM -> Unfortunately, no matter what I have tried, I cannot get a video to display on my local development machine or test iPad.

I am using a simple FLV video which is streaming locally through VLC Media Player.

In actionscript, I am then connecting a DatagramSocket to this.

No problem here, as I can see that the DatagramSocket is reading in the video stream data when I run the following function:

private function dataReceived( event:DatagramSocketDataEvent ):void {

            //Read the data from the datagram

            txtHistory.appendText("\n Received from " + event.srcAddress + ":" + event.srcPort + "> " + event.data.readUTFBytes(event.data.bytesAvailable));

}

Ive made my complete AS3 file available for download here:

http://www.frogcdrom.com/clients/frog/UDPVidStreamReceiver.as

Please can anyone help me out?

Im pretty good with AS3, but pants at network stuff so totally out of my knowledge zone here.

But its a good job for a good client and ideally Id like to get it.

Thanks in advance of any help you can give.

This topic has been closed for replies.

1 reply

sinious
Legend
August 21, 2013

Have you tried using NetStream's appendBytes method?

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#appendBytes()

edit:

Ah I see you're doing that and also properly call ns.play(null) to get into data generation mode. I'm wondering if the missing NetConnection AMF packet that inits a RTMP is messing it up. Without this header being sent upon connection I don't believe it will work. The docs say:

The byte parser understands an FLV file with a header. After the header is parsed, appendBytes() expects all future calls to be continuations of the same real or virtual file.

At any rate you can see there is a warning that AIR for iOS cannot use H.264 video. Are you using a different codec? What format/codec are you using?

Participant
August 21, 2013

Thanks for the feedback.

I thought the codec might be the issue, but Ive checked that H.264 is not being used.

My two test video files are (according to VLC player info):

1. FLV video file. (VP6F video codec / MP3 audio codec)

2. MPG video file. (MPGA video codec / MPGV audio codec)

EDIT: sorry. Im not sure I understand the little bit youve added about the header. How can I utilise this?

sinious
Legend
August 22, 2013

Here's a general dive on RTMP. You can see the packet structure contains metadata in the header about the content that will follow. The NetStream link I put above talks about it as well when using appendBytes(). The byte(array) parser understands FLV files with a header. After the header is parsed (again, see RTMP and what the server sends (0x12) before invoking a play), it expects all future calls to appendBytes() to be a continuation of that file (or stream). In other words, the first call to appendBytes() is missing the header.

This is where I rely on FMS for the most part. I know it knows to send a header upon connection. If you're implementing your own streaming setup you're going to need to supply this just like a FMS RTMP connection would (in AMF). I haven't needed to do anything this custom but if you get the structure of an initial RTMP connection (sniff it with a fiddler2 or find a resource on the structure) and encode it in byteArray, send it first to appendBytes with the correct information about the video you're sending, it should work.

Otherwise it makes sense appendBytes is failing by just getting a chunk of binary without having a header (the instructions on what exactly the binary is and how to use it).

Strictly per the documentation, On2/VP6 should be fine, I use it for all my old f4v projects. I'm not sure about MPGA/V.