Streaming webcam video in Flash using MP4 encoding

2019-03-31 12:41发布

问题:

One of the features of the Flash app I'm working on is to be able to stream a webcam to others. We're just using the built-in webcam support in Flash and sending it through FMS.

We've had some people ask for higher quality video, but we're already using the highest quality setting we can in Flash (setting quality to 100%).

My understanding is that in the newer flash players they added support for MPEG-4 encoding for the videos. I created a simple test Flex app to try and compare the video quality of the MP4 vs FLV encodings. However, I can't seem to get MP4 to work at all.

According to the Flex documentation the only thing I need to do to use MP4 instead of FLV is prepend "mp4:" to the name of the stream when calling publish:

Specify the stream name as a string with the prefix mp4: with or without the filename extension. The prefix indicates to the server that the file contains H.264-encoded video and AAC-encoded audio within the MPEG-4 Part 14 container format.

When I try this nothing happens. I don't get any events raised on the client side, no exceptions thrown, and my logging on the server side doesn't show any streams starting.

Here's the relevant code:

// These are all defined and created within the class.
private var nc:NetConnection;
private var sharing:Boolean;
private var pubStream:NetStream;
private var format:String;
private var streamName:String;
private var camera:Camera;

// called when the user clicks the start button
private function startSharing():void {
  if (!nc.connected) {
    return;
  }

  if (sharing) { return; }

  if(pubStream == null) {
    pubStream = new NetStream(nc);
    pubStream.attachCamera(camera);
  }
  startPublish();

  sharing = true;
}

private function startPublish():void {
  var name:String;

  if (this.format == "mp4") {
    name = "mp4:" + streamName;
  } else {
    name = streamName;
  }

  //pubStream.publish(name, "live");
  pubStream.publish(name, "record");
}

回答1:

Would be helpful to know the version of FMS you are running? It seems like you need at least FMS 3.0.2.



回答2:

Are you sure this applies to live streams and not only for recording? this 1 2 links suggest that while the player can decode sorenson, vp6 and h264, it can only encode in sorenson.

I'm in a similar situation, so I would like to have this clarified.

edit: what actually makes me doubt is that the documentation says flv and mp4, which arent codecs but containers, live streaming doesnt use containers, the encoded frames travel directly inside rtmp packets



回答3:

Flash Player doesn't encode using H.264, but Flash Media Server can record any codec in the F4V container. Flash Media Live Encoder can encode using H.264.

So basically you can't send h264 from web flash player (yet?)...