
Originally Posted by
miohtama
Hi miohtama ! Well remembered ! \o/
A long time ago I was interested in decoding the streaming sent by movino and I wrote the following (ugly) code. In fact, movino uses a compression similar to libjpeg. You will see jpeg images without tables in jpeg header. I did not studied how libjpeg is implemented and my test stopped at this point but I think it can be a good starting point for you. It is GPL3 
Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Marcelo Barros de Almeida <marcelobarrosalmeida@gmail.com>
# License: GPL3
from socket import *
from struct import *
from threading import *
from time import *
def save_jpeg_header(payload):
#p = payload.find('\xff\xc0')
#hdr = payload
pass
def save_jpeg(hdr,img):
p = img.find('\xff\xc0')
data = img[:p] + hdr[2:-2] + img[p:]
fn = ctime(time()) + '.jpg'
f = open(fn,'wb')
f.write(data)
f.close()
def process_cmd(s,cmd,payload):
hdr = ''
cmd_lst = { 0:'Garbage',
1:'YUV frame',
2:'PCM audio',
3:'JPEG header',
4:'JPEG frame',
5:'μlaw audio',
6:'AMR audio',
7:'Start MTU measurement',
8:'Stop MTU measurement',
9:'Video file',
10:'MPEG frame',
11:'Video chunk',
12:'Theora header',
13:'Theora frame',
14:'Handshake',
15:'Stream info',
16:'Stream closed' }
print "CMD=%d (%s)" % (cmd,cmd_lst[cmd])
print "PAYLOAD=%d" % len(payload)
if cmd == 8:
s.sendall(mtu())
if cmd == 3:
hdr = payload
#save_jpeg_header(payload)
if cmd == 4:
save_jpeg(hdr,payload[4:])
def recv_tsk(s):
data=''
while True:
#print "waiting data"
inp = s.recv(1024);
if not inp:
break
data = data + inp
#print "already received %d bytes" % len(data)
# complete header ?
if len(data) < 5:
continue
(cmd,sz) = unpack(">BL",data[:5])
# complete payload ?
if len(data) - 5 < sz:
continue
payload = data[5:5+sz]
data = data[5+sz:]
process_cmd(s,cmd,payload)
def mtu():
return pack(">BLL",1,4,1024)
def handshake():
return pack(">BLBB",2,2,1,1)
def ping():
return pack(">BL",3,0)
def movino(s):
rcv = Thread(target=recv_tsk,args=(s,))
rcv.start()
print "Sendign handshake"
s.sendall(handshake())
#sleep(5)
#s.sendall(ping())
while True: pass
s = socket(AF_INET,SOCK_STREAM)
s.bind(("",30710))
s.listen(10)
while True:
comm,addr = s.accept()
movino(comm)
comm.close()