将Android屏幕流式传输到视频播放器 [英] Stream Android screen to video player

查看:922
本文介绍了将Android屏幕流式传输到视频播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在笔记本电脑上使用Windows 7 64位,在三星Galaxy S4设备上使用Android 5.0.1。
我正在尝试使用以下代码通过adb传输设备的屏幕:
adb shell screenrecord --output-format = h264-| vlc-
我有vlc v2.2.4
但它什么也没显示。

I'm using Windows 7 64 bit on my laptop and Android 5.0.1 on my Samsung Galaxy S4 device. I'm trying to stream my device's screen via adb using following code: adb shell screenrecord --output-format=h264 - | vlc - I have vlc v2.2.4 But it doesn't show anything.

但是如果我使用媒体播放器经典版,随附带有以下代码的k-lite巨型编解码器包v12.3.5:
adb shell screenrecord --output-format = h264-| C:\Program Files(x86)\K-Lite编解码器包\MPC-HC64\mpc-hc64_nvo.exe-它显示了类似我的屏幕的图像,但是图像完全坏掉了。

But if I use media player classic, which comes with k-lite mega codec pack v12.3.5 with the following code: adb shell screenrecord --output-format=h264 - | "C:\Program Files (x86)\K-Lite Codec Pack\MPC-HC64\mpc-hc64_nvo.exe" - it's showing something like my screen, but image is totally broken.

如果我使用 adb shell screenrecord --output-format = h264 /sdcard/screenrecord.mp4 进行记录我的设备屏幕上,将其从设备中拉出,然后使用经典的媒体播放器将其打开,那么视频就可以了。但是,即使在这种情况下,vlc也无法打开。

And if I use adb shell screenrecord --output-format=h264 /sdcard/screenrecord.mp4 to record my devices screen, pull it from device and open it with media player classic, then it video is totally fine. However, vlc can't open even in this case.

可能是什么问题?为什么我可以观看录制的视频,但不能观看流式视频?

What might be the problem? Why I can watch recorded videos, but cannot watch streamed video?

还有另一个后续问题。我找到了adb-server的命令来获取设备的屏幕截图。它是 adb shell screencap 命令的替代方法。我可以通过Qt框架中的QTcpSocket使用该命令。

And one more follow-up question. I found adb-server's command to get device's screenshot. It's alternative to the adb shell screencap command. I can use that command via QTcpSocket in Qt framework.

但是,我找不到 adb shell screenrecord 的替代adb服务器。在这种情况下,我需要使用QProcess来运行命令,并以某种方式将输出转发到QMediaPlayer。到目前为止,我未能成功,因为我发现 QMediaPlayer :: setMedia 接受 QMediaSource QIODevice 。我发现QProcess是从 QIODevice 继承的,并尝试将其作为 QMediaPlayer ::: setMedia 的参数提供,但是我的程序退出,错误代码为1。如何将 QProcess 的输出转发到 QMediaPlayer

However, I couldn't find adb server alternative to adb shell screenrecord. In this case I need to use QProcess to run commands and somehow forward output to QMediaPlayer. So far I couldn't succeed in it, cuz as I found QMediaPlayer::setMedia accepts QMediaSource or QIODevice. I found that QProcess is inherited from QIODevice and tried to supply it as an argument to QMediaPlayer:::setMedia, but my program exited with error code 1. How can I forward QProcess's output to QMediaPlayer?

推荐答案

为了支持交互式 adb shell 命令, shell_service 使用 pty 。它有助于处理所有交互式用户输入,例如光标键的按下等。但是使用 pty 的副作用是它会破坏进程的二进制输出。这就是为什么在主机端捕获 adb shell screenrecord 的输出会导致文件损坏的原因。以前,解决此问题的唯一方法是对文件进行后处理,以删除这些多余的字符。但是前段时间,Google添加了 shell 命令的另一个版本,该版本不具有交互模式,因此不需要使用 pty 。他们称其为 exec-out

In order to support the interactive adb shell command the shell_service uses pty. It helps to take care of all interactive user input like cursor key presses, etc. But the side effect of using pty is that it mangles binary output of the process. This is why capturing the output of adb shell screenrecord on the host side results in a corrupted file. Previously the only way to fix that was to post-process the file to remove those extra characters. But some time ago Google has added another version of the shell command which does not have the interactive mode and therefore does not need to use the pty. They called it exec-out.

因此,为了捕获文件而不会损坏,应该使用

So in order to capture a file without corruption you should use

adb exec-out screenrecord --output-format=h264 -

这篇关于将Android屏幕流式传输到视频播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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