39

I am a vlogger and after getting HTC Desire HD, found out its camera was all I ever needed. However, I usually have to see myself while recording video, to control my facial expressions, and with a rear-facing camera it's just not possible.

I know ADB allows for screenshots, but is there a way to stream the screen output to my PC's display? Not necessarily at 20+ fps, just a couple frames per second will do.

Izzy
  • 91,166
  • 73
  • 343
  • 943
Unknown artist
  • 646
  • 1
  • 6
  • 13
  • Is this question really a duplicate? The other one only asks on how to mirror screen. This one asks to do that via ADB specifically – Ooker Jun 11 '21 at 11:00

4 Answers4

46

screenrecord

screenrecord is an internal Android executable that dumps screen to a file, and ffplay from ffmpeg happens to be able to play an H.264 encoded stream from stdin

First enable ADB USB access and then on Ubuntu:

sudo apt-get install adb ffmpeg    
adb exec-out screenrecord --output-format=h264 - |
   ffplay -framerate 60 -probesize 32 -sync video  -

You might have to make the screen move a bit before you see anything:

enter image description here

Uncut demo: https://www.youtube.com/watch?v=fVgeoMYm61Q

Explanation of parameters:

See also: Use adb screenrecord command to mirror Android screen to PC via USB

Tested on Ubuntu 20.04, Android 11, Pixel 3a.

  • 5
    The video starts faster with smaller probesize. I got good results with ffplay -framerate 60 -probesize 32 -sync video - the "-framerate 60" removes the delay effect and "-sync video" drops the frames instead of fast forwading them. – arbuz Jan 24 '18 at 00:30
  • 1
    Exactly what I was looking for! I didn't want to install an app just to grab a screenshot when security policies were restricting it. For the record, it worked for me on Ubuntu 18.04 with Android 7.0. – b_laoshi Jan 02 '19 at 01:54
  • @b_laoshi great, added the new working versions report to the answer. – Ciro Santilli OurBigBook.com Jan 02 '19 at 08:57
  • Anyone knows if this could be made working on Windows? In PowerShell I ran adb shell screenrecord --output-format=h264 - | ffplay -framerate 60 -probesize 32 -sync video - but no preview window appears. adb shell screenrecord --output-format=h264 - seems to work fine to stdout. – Constructor Aug 02 '20 at 14:31
  • @Constructor basic question, does ffplay work at all on your system? E.g. with a regular mp4 :-) – Ciro Santilli OurBigBook.com Aug 02 '20 at 14:32
  • Yes it did! Admittedly I don't use ffplay every day, but when I did ffplay some.mkv it works with a basic preview window (some video information: Stream #0:0: Video: h264 (High), yuv420p(progressive), 1296x972, 25 fps, 25 tbr, 1k tbn, 2k tbc (default), so it seems h264 is not the issue) – Constructor Aug 02 '20 at 15:11
  • @Constructor OK. Gotta debug further then. E.g. ensure stdout is going out and into ffplay compare that with input from file. – Ciro Santilli OurBigBook.com Aug 02 '20 at 15:17
  • Addition: You should use adb exec-out ... instead of adb shell ..., the latter seems to modify data for interactive shell purposes while exec-out doesn't. – Bowi Nov 10 '20 at 08:28
  • @Bowi thanks for this info, can you provide a thread talking about that in more detail? E.g. providing a sample specific output sequence that gets modified? – Ciro Santilli OurBigBook.com Nov 10 '20 at 10:33
  • 1
    @CiroSantilli郝海东冠状病六四事件法轮功, this: https://stackoverflow.com/a/31401447/6403504 and, basing on it, this: https://stackoverflow.com/a/13587203/6403504 – Bowi Nov 10 '20 at 10:42
  • 1
    Got it working on macOS Big Sur with Pixel 4 and Pixel 2. Awesome solution – Dmytro Rostopira Mar 23 '21 at 16:10
  • 1
    Sample command to play with the IINA player: adb shell screenrecord --output-format=h264 - | iina --stdin --keep-running --mpv-framerate=30 --mpv-untimed --mpv-framedrop=no --mpv-correct-pts=no – alleus Mar 23 '22 at 10:50
  • There is a limit of 3 minutes using the screenrecord command. You can use a loop to continuously run the command and stop the stream from freezing.

    adb exec-out "while true; do screenrecord --output-format=h264 -; done" | ffplay -flags low_delay -framerate 60 -probesize 32 -sync video -an -

    – FallenNode Sep 11 '23 at 18:50
12

Try the Android Screencast app.

See the XDA thread for more details.

Chahk
  • 19,505
  • 3
  • 56
  • 80
  • Looks nice and answers the question I put in my thread's title... But ironically, displays the black bar instead of camera output. I guess it's like print-screening Windows Media Player: you end up with everything except the video itself :( – Unknown artist Mar 29 '11 at 17:59
  • 2
    I'm not sure why you got that problem, but even if it worked appropriately it only gives you a 4-5 fps refresh rate, which is far from "Live". – Matt Mar 29 '11 at 18:55
  • 6
    I doubt you will be able to pipe output from your phone's camera to another device. Have you tried a more hardware based approach, like setting up a mirror? :) – Chahk Mar 29 '11 at 21:01
1

Some Android phones have TV Out capabilities, usually through USB or HDMI, but sometimes through the 3.5 audio jack. I don't think HTC Desire has any TV-Out capability though.

Lie Ryan
  • 19,073
  • 6
  • 65
  • 83
-1

Airdroid is all you need. Simple and easy to use. You're able to see your camera out put live but for some reason not able to record it. Your pc and android phone must be on the same WiFi network.

  • Airdroid works over WiFi AFAIK. OP wanted a solution for ADB (via USB). He also wanted to see the device screen live, i.e. with no or just marginal delay. If not added recently, Airdroid doesn't support that IMHO. – Izzy Sep 17 '14 at 10:07