Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
900 views
in Technique[技术] by (71.8m points)

qt - Stream Android screen to video player

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.

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 PackMPC-HC64mpc-hc64_nvo.exe" - it's showing something like my screen, but image is totally broken.

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?

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.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 -

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...