A live android screen caster which encoding media by h264,webm via TCP and UDP with low latency
I'm currently in charge of test automation team. We try to make possible functional testing for mobile games. While we're working on it, we needed to mirror live android screen to web browser. The first approach was MJPEG. We captured entire screen and sent it over network in every very short period. Surely, it was ineffiecient, slow and huge. The first approach was helpful anyway to prove our concept of system, though.
The second approach was encoding our media data by using well known codecs such as h264 and vp8. It ended up a success anyway. However, it was hard to find code examples. I mostly refer to android googlesource(specially media test cases). I hope this project helps you to save your time and understand concept of live screen casting on Android.
- Samsung Galaxy S7 edge (Android 6.0)
- ffmpeg on server (demonstrating works well)
ffplay -framerate 60 -i tcp://<your server ip here>:49152?listen
- Put your remote host address(eg.IP)
- Choose format as H.264
- Tap Start
- Do some other jobs to make ffmpeg receiving enough media data.
ffplay -framerate 60 -i tcp://<your server ip here>:49152?listen
ffplay -i tcp://<your server ip here>:49152?listen
ffplay -framerate 60 -i udp://@:49152
ffplay -i udp://@:49152
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
ffmpeg -i output.mp4 -vf "setpts=(1/2)*PTS" fast_output.mp4
ffmpeg -i udp://@:49152 -c:v libvpx -b:v 1M -c:a libvorbis output.webm