title: Streaming webcam video in Flash using MP4 encoding
body: <p>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.</p>
  
  <p>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%).</p>
  
  <p>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.</p>
  
  <p>According to the <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/net/NetStream.html#publish()" rel="nofollow noreferrer">Flex documentation</a> 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:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>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.</p>
  
  <p>Here's the relevant code:</p>
  
  <pre><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");
  }
  </code></pre>