Efficient video recording

An Ubuntu phone has a command-line utility called mirscreencast which dumps screen frames to a file, meaning that in theory it’s possible to record a video of your phone’s screen. In practice, though, it doesn’t work for video; the phone is that busy (a) grabbing frames and (b) writing them to the phone’s storage that you can’t actually use it for jerkiness, and the resultant video includes about one frame in ten. To work around this, instead of saving the video onto the phone’s storage, you can send it over the network to a real machine.

1) Listening on a PC

On your computer: nc -l -p 1234 > out, which uses netcat to listen to port 1234 and send everything that comes in there to a file named out.

2) Record and send from the phone

On the phone: mirscreencast -n 60 -m /var/run/mir_socket --stdout --cap-interval 4 -s 384 640 | nc mycomputer 1234, which uses mirscreencast to record 1/4 of the frames (--cap-interval 4), which is 15fps (rather than the screen’s 60fps), and resize those frames to half their size (a Nexus 4 has a screen resolution of 768x1280, which halved is 384x640, and each frame is only a quarter of the size) and then send them with netcat to port 1234 on the computer. (Use your computer’s IP address instead of mycomputer, since Ubuntu phone won’t resolve computername.local names.)

3) Rendering to video file

Now that you have raw video frames in your out file, you'll want to encode them into a nicer format (like h264/x264). To do this, you'll need to pass your raw file to something like mencoder or avcon:

Using avconv:

Run avconv -f rawvideo -pix_fmt rgba -s 384x640 -r 15 -i out -c:v h264 out.mp4 (note the -pix_fmt rgba, the -s HxW for screen size, and -r 15 for framerate). If the converted video framerate is too high, you may need to specify the output fps. Add -filter:v "setpts=N/(fps*TB)", change fps with your preferred value, right before the output filename. For example: avconv -f rawvideo -pix_fmt rgba -s 384x640 -r 15 -i out -c:v h264 -filter:v "setpts=N/(25*TB)" out.mp4 See avconv documentation for further information.

Using mencoder:

Run mencoder -demuxer rawvideo -rawvideo fps=15:w=384:h=640:format=rgba -ovc x264 -o out.mp4 out (note the format=rgba, the w and h for screen size, and fps=15).

Touch/ScreenRecording (last edited 2015-01-14 17:13:31 by gcollura)