First attempts at reading the video stream

A project log for Controlling a JJRC H37 Elfie quad from a PC

The JJRC Elfie Quadcopter comes with an Android/iOS app to control it from the phone. Can we control it from our own software?

adria.junyent-ferreadria.junyent-ferre 03/02/2017 at 23:330 Comments

Today I played a bit more with the quadcopter. My idea was to dump the video stream somehow and find out how the video was encoded. My idea was to create a TCP socket to port 8888, write the 106 byte magic message that I saw the mobile app send before the quadcopter starts spitting out what looks like a video stream and then read whatever comes from the quadcopter. The following Python script can do this:

import socket
import sys
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('', 8888))


data = s.recv(106) 
while n<1000: #write replace by while 1 if you want this to not stop
    data = s.recv(1024)
The result -almost- worked straightaway. You will notice in the code above that I discard the first 106 bytes that the quadcopter returns, this seems to correspond to one of these magic messages that the app and the quadcopter exchange and I have no idea what they mean. The rest of the data that comes from the quadcopter seems to be raw h264 video stored in "nal" format. I dumped the output I got and managed to play it in vlc using the following commands:
$ python > video.h264
$ vlc video.h264 --demux h264
The vlc successfully plays the video but complains about some errors in the headers.

My next step is to find a proper way to read the TCP stream and make some video player play it with the lowest possible lag. I'll keep you posted.