视频从Android设备分流到LAMP服务器 [英] Video streaming from Android device to LAMP Server

查看:196
本文介绍了视频从Android设备分流到LAMP服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从这个点开始:<一href="http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system" rel="nofollow">http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system 我试图创建一个应用程序从手机摄像头的视频流保存到远程服务器。 (我发现在谷歌code为Android一部分几个例子:IPCAMERA换机器人,spydroid-IPCAMERA等)

starting from this point: http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system I'm trying to create an application to save a video stream from mobile camera to a remote server. (I found several examples in google code for android part: ipcamera-for-android, spydroid-ipcamera, etc..)

我读了一些答案,在这里和周围的网络,但无法找到有关如何在服务器端读和保存数据流的解决方案。

I read some answers here and around the network, but can not find the solution about how to "read" and save the stream of data on the server side.

我的Java知识很差,所以我宁愿能(使用服务器套接字,或其他东西)在PHP创建服务器端脚本。有人可以帮助这部分?

My knowledge of java is poor, so I'd rather be able to create server-side script in PHP (using server sockets, or other stuffs). Someone can help on this part?

更新

使用的工具,如mplayer的/ ffmpeg的mencorer我能够保存视频流我的小知识......例如使用IPCAMERA换机器人,并使用服务器端的nanohttp服务器:

using my little knowledge of tools such as mplayer / ffmpeg mencorer I'm able to save the video stream ...for example using ipcamera-for-android and its nanohttp server using on server side:

ffmpeg-i "http://{ip of android phone}:8080/live.flv" /my/server/path/stream.flv

然而,只能在局域网中使用, 我需要移动连接的服务器,而不是反之亦然。

However, can only be used in LAN, I need that mobile connect server and not viceversa.

更新2

一些进展..使用服务器端此脚本

Some progress.. using this script on server side

#!/usr/bin/php5
<?php
$handle = fopen("stream.3gp","w");
$socket = stream_socket_server("tcp://192.168.0.102:9000", $errno, $errstr);
if ($socket)
{
 echo "start listening\n";
 while ( $conn = stream_socket_accept($socket, 180))
  {
    echo "phone connected\n";
    while ($chunk = stream_socket_recvfrom($conn, 1500))
    {
        fwrite($handle,$chunk);
    }
  }
}

  fclose($handle);
  fclose($socket);
?>

不过,3GP文件还没有播放。

however, 3gp file is not yet playable..

更新3

#!/usr/bin/php5
<?php


$socket = stream_socket_server("tcp://192.168.0.102:9000", $errno, $errstr);
$file = "saved.3gp";
$threegp_header = "\x00\x00\x00\x18\x66\x74\x79\x70\x33\x67\x70\x34\x00\x00\x03\x00\x33\x67\x70\x34\x33\x67\x70\x36";
$four_bytes = "\x00\x00\x00\x00";

if (!$socket) {

  echo "$errstr ($errno)\n";

} else {

  echo "server start listening\n";

  while ( $conn = @stream_socket_accept($socket, 180))
  {
        echo "phone connected\n";

    $handle = fopen($file,"w");

    //mediaRecorder gives invalid stream header, so I replace it discarding first 32 byte, replacing with 28 good byte (standard 3gp header plus 4 empty bytes)
    $discard = stream_get_contents($conn, 32);
    fwrite($handle, $threegp_header);
    fwrite($handle, $four_bytes);

    //then confinue to write stream on file until phone stop streaming
        while(!feof($conn))
        {
        fwrite($handle, stream_get_contents($conn, 1500));
        }
    echo "phone disconnected\n";
    fclose($handle);

    //then i had to update 3gp header (bytes 25 to 28) with the offset where moov atom starts
    $handle = fopen($file,"c"); 
    $output = shell_exec('grep -aobE "moov" '.$file);
    $moov_pos = preg_replace('/moov:(\d+)/i', '\\1', $output);
    $moov_pos_ex = strtoupper(str_pad(dechex($moov_pos - 24), 8, "0", STR_PAD_LEFT));
    fwrite($handle, $threegp_header);
    $tmp = '';
        foreach(str_split($moov_pos_ex,2) as $hex)
        {
                 $tmp .= pack('C*', hexdec($hex));
        }
    fwrite($handle, $tmp);
    fclose($handle);


  }
  echo "phone disconnected\n";


}
  @fclose($handle);
  fclose($socket);
?>

一些实验后,这一次VLC / mplayer的似乎可以发挥它..还存在一些问题与音频(但我想我已经什么不对Android上侧)

after some experiments, this time vlc/mplayer seems that can play it.. still some problems with audio (but i think i've something wrong on android side)

推荐答案

你可能会想使用PHP的的服务器套接字功能

You're probably going to want to use PHP's server socket functionality.

这里有一个方便的教程它经过你需要做的,以实现数据流。

Here's a handy tutorial which goes through what you need to do in order to implement data streaming.

这篇关于视频从Android设备分流到LAMP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆