Code Monkey home page Code Monkey logo

androidscreencaster's Introduction

Android Screen Caster - Low Latency Screen Mirroring

AndroidScreenCaster is a live screen casting solution for Android devices, with efficient H.264 and WebM encoding via TCP and UDP. Experience low latency streaming to your browser or server for mobile games, presentations, or any other application where real-time screen mirroring is needed.

Motivation

As a test automation team leader, we needed to mirror live Android screens to web browsers for functional testing of mobile games. Our first approach, using MJPEG, was inefficient, slow, and produced large files. The second approach, using H.264 and VP8 codecs, was successful but lacked readily available code examples.

This project aims to save you time and provide a clear understanding of live screen casting on Android, with efficient media encoding and low latency.

DEMO

Demo

Tested Device

  • Samsung Galaxy S7 edge (Android 6.0)

Requirements

  • FFmpeg installed on the server

Screenshots

Screenshot

Quick Start

Server-side

  • Run the following command to start FFplay:

    ffplay -framerate 60 -i tcp://<your server ip here>:49152?listen

Client-side (Android App)

  1. Enter your remote host address (e.g., IP) in the app.
  2. Choose H.264 as the format.
  3. Tap "Start" and perform other tasks, allowing FFmpeg to receive enough media data.

FFmpeg Commands for Server-side

PLAY

TCP+H264

ffplay -framerate 60 -i tcp://<your server ip here>:49152?listen

TCP+VP8

ffplay -i tcp://<your server ip here>:49152?listen

UDP+H264

ffplay -framerate 60 -i udp://@:49152

UDP+VP8

ffplay -i udp://@:49152

RECORD

UDP+H264

ffmpeg -i udp://@:49152 -framerate 60 -codec:v libx264 -profile:v baseline -preset medium -b:v 250k -maxrate 250k -bufsize 500k -vf scale=-1:360 -an -threads 0 output.mp4

To increase playback speed, re-encode output.mp4:

ffmpeg -i output.mp4 -vf "setpts=(1/2)*PTS" fast_output.mp4

UDP+VP8

ffmpeg -i udp://@:49152 -c:v libvpx -b:v 1M -c:a libvorbis output.webm

Reference

scrcpy项目的编码配置项:

[server] DEBUG: MediaFormat: {color-format=2130708361, i-frame-interval=10, mime=video/avc, bitrate=8000000, frame-rate=60, repeat-previous-frame-after=100000}

[server] DEBUG: Audio MediaFormat: {sample-rate=48000, mime=audio/opus, channel-count=2, bitrate=128000}

androidscreencaster's People

Contributors

aliceljm1 avatar magicsih avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.