benuuts
benuuts

Reputation: 119

Live video from raw tcp packets

we are trying to make a small python app that display a live video from sniffed packets using scapy and ffplay. This is part of our master degree research project. The goal is to make a proof of concept app that spies on video transimitted over tcp.
We have a working script that writes into a .dat file and then we read it using ffplay. It works ok but have a lot of latency and we think we could do better : directly stream it into ffplay without the need to write raw data in a file.

Here's our script :

from scapy.all import * 
import os

export_dat = open("data.dat", "a")

def write_packet_raw(packet):
    export_dat.write(str(packet.getlayer(Raw)))

def realtime_packet():
    p = sniff(iface="wlan0", filter="tcp and (port 5555)", count=5000, prn=write_packet_raw)

realtime_packet()
export_dat.close()

And then we launch : ffplay -window_title Videostream -framedrop -infbuf -f h264 -i data.dat

Any idea on how we can achieve that ? thanks.

Upvotes: 0

Views: 652

Answers (1)

aergistal
aergistal

Reputation: 31209

Write to stdout in binary mode instead of a file and pipe the output to ffplay.

import sys
sys.stdout.buffer.write(...)
sys.stdout.flush()

Then run it like:

python3 sniff.py | ffplay -f h264 -i -

The - means stdin.

Upvotes: 2

Related Questions