【问题标题】:Live streaming doesn't work直播不工作
【发布时间】:2012-07-10 18:38:10
【问题描述】:

我正在使用 FFmpeg 捕获我的屏幕:

ffmpeg -f dshow -i video="UScreenCapture" -r 5 -s 640x480 -acodec libmp3lame -ac 1 -vcodec mpeg 4 -vtag divx -q 10 -f mpegts tcp://127.0.0.1:1234

所以让它流到某个地方。接受者脚本:

 error_reporting(E_ALL); /* Allow the script to hang around waiting for connections. */
 set_time_limit(30); /* Turn on implicit output flushing so we see what we're getting as it comes in. */
 ob_implicit_flush();


$address = '127.0.0.1';
$port = 1234;
$outfile = dirname(__FILE__)."/output.flv";
$ofp = fopen($outfile, 'wb');

 if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) { echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n"; sleep (5); die; }
 if (socket_bind($sock, $address, $port) === false) { echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; sleep (5); die; }
 if (socket_listen($sock, 5) === false) { echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; sleep (5); die; }
 if (($msgsock = socket_accept($sock)) === false) { echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; sleep (5); break; }
 do {
    $a = '';
    socket_recv ($msgsock, $a, 65536, MSG_WAITALL);
    fwrite ($ofp, $a);
    //echo strlen($a)."\r\n";
 } while (true);

似乎把东西保存到磁盘了。现在来了html:

我真的不知道该怎么做,但基于一个例子:

<video src="/output.flv"></video>

但它什么也没做。如果我想流式传输实时传入的内容,那有什么问题?

【问题讨论】:

  • 哪个浏览器?请注意,目前,不同的浏览器支持不同的编解码器。还要注意通过 PHP 设置正确的 MIME 类型,这对我来说导致了 FF 的问题。
  • 它的firefox,我没有在其他浏览器上尝试过。但它将是一个实时流(没有开始/结束),所以它可能会错过文件标识符标题?也许它需要静态格式?
  • 它不适用于任何浏览器

标签: php ffmpeg video-streaming html5-video


【解决方案1】:

HTML 5 视频将不支持 Flv 格式 HTML5 将仅支持以下格式视频

.mp4 = H.264 + AAC
.ogg/.ogv = Theora + Vorbis
.webm = VP8 + Vorbis

在以下站点学习 HTML5 视频基础知识 HTML5 video basics

如果你想播放flv,你必须使用flv或Flex程序或一些flv播放器,如flowplayer

【讨论】:

    猜你喜欢
    • 2011-10-31
    • 2018-02-20
    • 1970-01-01
    • 2014-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    相关资源
    最近更新 更多