【问题标题】:Google Glass stream video to serverGoogle Glass 将视频流式传输到服务器
【发布时间】:2014-01-19 22:01:50
【问题描述】:

我正在尝试为 Google Glass 构建一个应用程序,该应用程序可以流式传输到服务器并让客户端通过网络浏览器查看流式传输。到目前为止,我似乎需要通过 RTSP 到媒体服务器(如 Wowza)执行此操作,然后有一个 Web 服务器托管一些查看 RTMP 流的视频播放器,但我运气不佳。

使用 libstreaming (https://github.com/fyhertz/libstreaming) 我永远无法查看流。

我也有兴趣使用 WebRTC 做一些事情,以便我可以制作类似于环聊的解决方案,但我不确定是否有任何库支持此功能。

感谢任何帮助。

【问题讨论】:

标签: android video-streaming rtsp webrtc google-glass


【解决方案1】:

自 1 月以来,libsreaming 已被修复为在 Glass 上工作。它的 RTSP 视频可以很容易地在 VLC 播放器或插件中查看。下面的代码不包括自动生成的存根。

public class MainActivity extends Activity implements SurfaceHolder.Callback, Session.Callback {

private int mRtspPort = -1;

private ServiceConnection mRtspServerConnection = new ServiceConnection() {

    private static final int RTSP_PORT = 1234;

    @Override
    public void onServiceConnected(ComponentName className, IBinder binder) {
        RtspServer s = ((RtspServer.LocalBinder) binder).getService();
        s.setPort(RTSP_PORT);
        mRtspPort = s.getPort();
    }
  };

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.activity_main);

    // Configures the SessionBuilder
    SessionBuilder.getInstance()
            .setSurfaceView((SurfaceView) findViewById(R.id.surface))
            .setCallback(this)
            .setPreviewOrientation(90)
            .setContext(getApplicationContext())
            .setAudioEncoder(SessionBuilder.AUDIO_NONE)
            .setVideoEncoder(SessionBuilder.VIDEO_H264)
            .setVideoQuality(new VideoQuality(320, 240, 20, 500000));

    // Starts the RTSP server
    bindService(new Intent(this, RtspServer.class), mRtspServerConnection, Context.BIND_AUTO_CREATE);
}

@Override
public void onResume() {
    super.onResume();
    mResumed = true;
    displayConnectString();
    SessionBuilder.getInstance().getSurfaceView().setAspectRatioMode(SurfaceView.ASPECT_RATIO_PREVIEW);
    SessionBuilder.getInstance().getSurfaceView().getHolder().addCallback(this);
}

private void displayConnectString() {
    WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
    int ip = wifiInfo.getIpAddress();
    String ipAddress = Formatter.formatIpAddress(ip);
    ((TextView) findViewById(R.id.connectInfo)).setText("rtsp://" + ipAddress + ":" + mRtspPort);
}

@Override
public void onDestroy() {
    super.onDestroy();
    unbindService(mRtspServerConnection);
}

@Override
public void onSessionStarted() {
    ((TextView) findViewById(R.id.connectInfo)).setText("");
}

@Override
public void onSessionStopped() {
    displayConnectString();
}
}

【讨论】:

  • 你能拿到音频吗?
  • @Why-K-Rum:我不关心音频。我不知道音频是否容易。 请注意,Google Glass 已对 KitKat 进行了重大升级,它改变了视频录制的游戏规则(可能使用 MediaCodec)
  • 嗨@AlexCohn,我不能在玻璃上处理这段代码。我显示 0.0.0.0 ip...我通过蓝牙和 MyGlass 应用程序连接到网络...对此有什么建议吗?如果我在手机或平板电脑上使用此代码,我可以工作并在 VLC 中查看流媒体。另一个问题,这仅适用于本地网络,当我禁用 wifi 并使用 3G/LTE 时,这不起作用,为什么?非常感谢!
  • @Bae: 1. 在这段代码中,我们向 WiFi Manager 询问 IP 地址。也许您可以从 BT Manager 获得地址。有一件事是肯定的,0.0.0.0 不好。 2. 我的手机提供商过滤 RTMP;此外,Google Campus 的 WiFi 也对其进行了过滤;因此,我需要一个私人 WiFi 接入点来实现从 Glass 到 PC 的流式传输。
  • @Why-K-Rum: 对于示例 1,您的设备就像一个 RTSP 服务器,所以当您在平板电脑中运行它并像我之前所说的那样在 VLC 中进行连接时(Ctrl+N并使用 rtsp://ip.of.the.tablet:PORT,其中端口在代码中设置为 1234),您的 VLC 是客户端,您的平板电脑开始将相机流式传输到您的 VLC。所以我正在使用示例 1。我也尝试在平板电脑中使用 示例 2,但我在 VLC 中只看到绿屏,当我尝试在我的玻璃杯中使用它时(示例 2),我在 VLC 中看不到任何东西,因为我没有't get the IP of my glass (因为它与我的手机配对)
猜你喜欢
  • 1970-01-01
  • 2012-10-02
  • 1970-01-01
  • 1970-01-01
  • 2012-01-22
  • 2011-07-01
  • 2013-05-11
  • 2012-01-24
  • 1970-01-01
相关资源
最近更新 更多