首页 \ 问答 \ 使用MP4编码在Flash中流式传输网络摄像头视频(Streaming webcam video in Flash using MP4 encoding)

使用MP4编码在Flash中流式传输网络摄像头视频(Streaming webcam video in Flash using MP4 encoding)

我正在开发的Flash应用程序的一个功能是能够将网络摄像头传输给其他人。 我们只是在Flash中使用内置的网络摄像头支持并通过FMS发送它。

我们有一些人要求更高质量的视频,但我们已经在Flash中使用了最高质量的设置(设置质量达到100%)。

我的理解是,在较新的Flash播放器中,他们为视频添加了对MPEG-4编码的支持。 我创建了一个简单的测试Flex应用程序来尝试比较MP4与FLV编码的视频质量。 但是,我似乎无法让MP4工作。

根据Flex文档 ,使用MP4而不是FLV我需要做的唯一事情就是在调用publish时将“mp4:”添加到流的名称中:

将流名称指定为前缀为mp4的字符串:带或不带文件扩展名。 前缀向服务器指示该文件包含MPEG-4 Part 14容器格式内的H.264编码视频和AAC编码音频。

当我尝试这个没有任何反应。 我没有在客户端获得任何事件,没有抛出异常,并且我在服务器端的日志记录没有显示任何流启动。

这是相关的代码:

// 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");
}

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");
}

原文:https://stackoverflow.com/questions/583306
更新时间:2024-03-06 22:03

最满意答案

我找到了问题的答案,因此我发布了我的代码,用于在yiistrap中制作可拖动的模态窗口。 我希望它对其他人也有帮助。

<?php $this->beginWidget('bootstrap.widgets.TbModal', array(
    'id'=>'myModal',
    'fade' => false,
    'htmlOptions' => array('style' => 'width: 1253px; margin-left: -646px; margin-top: -95px; left: 610px; height: 648px'),
    'options' => array('backdrop' => 'static', 'keyboard' => true)
    )); 
?>
<script>
$(function(){$("#myModal").draggable().resizable();});
</script>
//Modal Header Part
//Modal Body Part
//Modal Footer Part

不要忘记包含jquery-ui.css。


I found answer to my problem and thus I am posting my code for making modal window draggable in yiistrap. I hope it will be helpful to others also.

<?php $this->beginWidget('bootstrap.widgets.TbModal', array(
    'id'=>'myModal',
    'fade' => false,
    'htmlOptions' => array('style' => 'width: 1253px; margin-left: -646px; margin-top: -95px; left: 610px; height: 648px'),
    'options' => array('backdrop' => 'static', 'keyboard' => true)
    )); 
?>
<script>
$(function(){$("#myModal").draggable().resizable();});
</script>
//Modal Header Part
//Modal Body Part
//Modal Footer Part

Don't forget to include jquery-ui.css.

相关问答

更多
  • 来自appendTo 文档 : Window将附加到的元素。 请注意,这不会限制给定元素中的窗口拖动 。 因此,Kendo窗口是浮动的,它们不受限于您追加的元素。 这意味着将确认窗口添加到HTML元素之前没有意义,然后append其append到同一元素。 From appendTo documentation: The element that the Window will be appended to. Note that this does not constrain the window drag ...
  • 我找到了问题的答案,因此我发布了我的代码,用于在yiistrap中制作可拖动的模态窗口。 我希望它对其他人也有帮助。 beginWidget('bootstrap.widgets.TbModal', array( 'id'=>'myModal', 'fade' => false, 'htmlOptions' => array('style' => 'width: 1253px; margin-left: -646px; margin-top: -95px; ...
  • 尝试这个: $(document).ready(function () { var myBookId = $('a[csrf="1"]').data('id'); $("#bookId").val(myBookId); }); 小提琴 Try this: $(document).ready(function () { var myBookId = $('a[csrf="1"]').data('id'); $("#bookId").val(myBookId); }); Fi ...
  • 当用户在可拖动区域上触发mousedown事件时,您可以添加jQuery脚本来触发mouseup事件。 你必须在模式窗口的html的头部添加这个: