wang-bin / QtAV

A cross-platform multimedia framework based on Qt and FFmpeg. 基于Qt和FFmpeg的跨平台高性能音视频播放框架. Recommand to use new sdk https://github.com/wang-bin/mdk-sdk
http://qtav.org
3.94k stars 1.5k forks source link

Play H264 Raw Bytestream from TCP #510

Open masterofeye opened 9 years ago

masterofeye commented 9 years ago

Hello,

i didn't find any possibility to use the player for take a raw bytestream.

My scenario: I get a decoded H264 raw bytestream from a webcam. I send them over TCP to the planned client and this should decode the bytestream and show them in a player.

How could i do this with QTAV?

Best regards MOE

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/26664956-play-h264-raw-bytestream-from-tcp?utm_campaign=plugin&utm_content=tracker%2F307703&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F307703&utm_medium=issues&utm_source=github).
wang-bin commented 9 years ago

https://github.com/wang-bin/QtAV/wiki/Play-Raw-Video-Streams

masterofeye commented 9 years ago

Hello, thx for the fast answer.

This play's a file. But i want to "play" (decode and so on) the receive TCP messages? I miss someone like ..setByteFrame in the player class .. to deliver the received frames or someone else. Can you follow my explanation?

wang-bin commented 9 years ago

it can play a url. You mean decoding the message to get a video frame?

masterofeye commented 9 years ago

i try to use the url ... http:\pcname:port... And get "Failed to open media" ... "Error number -5 occurred".

At this point there is a little mistake in the spelling for the debug Output and the window title -> "Invalid meida" in place of "Invalid media"

wang-bin commented 9 years ago

what about ffplay?

3electrons commented 8 years ago

@matsterofeye As url try tcp://localhost:port_number it works for me on current repo. I use RPI as video camera.

bonagin commented 8 years ago

@masterofeye , @wang-bin @3electrons did you finally find a solution streaming playing H264 Raw Bytestream from TCP programmatically ?

wang-bin commented 8 years ago

@bonagin play the url and set a frame rate

bonagin commented 8 years ago

@wang-bin

I did this:

QVariantHash fmt_opt; fmt_opt["format_whitelist"] = "rawvideo"; fmt_opt["video_size"] = "1280x720"; fmt_opt["framerate"] = 25; m_player->setOptionsForFormat(fmt_opt); m_player->play("tcp://127.0.0.1:8181");

I get this error : "avformat_open_input: url:'tcp://127.0.0.1:8181' ret:0" Then the program crashes.

Anything i am doing wrong ?

wang-bin commented 8 years ago

@bonagin That's for raw yuv stream. not h264 stream

bonagin commented 8 years ago

@wang-bin Can you please Advice with a piece of code as to how do for a h264 raw stream

bonagin commented 8 years ago

@wang-bin I mean Raw h264 encoded packet from a TCP socket.

I have also tried

` QVariantHash avfm_opt; avfm_opt["probesize"] = 512_1024; avfm_opt["fbsprobesize"] = 30; avfm_opt["framerate"] = 25; avfm_opt["rtbufsize"] = 512_1024;

QVariantHash opt;
opt["avformat"] = avfm_opt;
m_player->setOptionsForFormat(opt);
m_player->setIODevice(m_socket); 
m_player->play();

`

Still no luck

wang-bin commented 8 years ago

player.setFrameRate(25) and player.play(url)

Please read the bottom of this wiki https://github.com/wang-bin/QtAV/wiki/Play-Raw-Video-Streams

bonagin commented 8 years ago

@3electrons @wang-bin I think you are misunderstanding me, i am receiving video frames via an http payload, my server or socket is already connected to the particular port where the packets are being received. i just need a some sort of a function where i can pass the incoming h264 raw nal units to and it decodes the frame as a continuous video as it is being streamed.

bonagin commented 8 years ago

I think the code you gave me only applies when the stream is already being initiated by the client, in my case my Http server initiates the stream, then the client will respond with a HTTP OK string and some parameters followed by a payload which contains raw H264 data.

wang-bin commented 8 years ago

Currently it's not supported. Maybe I can add an callback to let user process AVPacket before getting the packet from AVDemuxer. What do you think?

bonagin commented 8 years ago

@wang-bin I think that would be fantastic. Please let me know as soon as you have that commit.

ealloradai commented 7 years ago

Hi all, For a research project we were developing an extension on H264 using "free" NAL types. We need to read those packets from the H264 stream before they are discarded as not relevant for video. The server use RTSP/RTP. In order to develop the client we were planing to use QtAV, can we benefit from those callback in order to access the h264 stream before "normal" processing? Thanks

sergey-suzdaltsev commented 5 years ago

You can play the H264 RAW streams this way: Create a server on the local port, eg. 1234, and restream h264 beatstream via this local port. Set 'source' property as 'tcp://localhost:1234' AVPlayer { id: player; source: 'tcp://localhost:1234'; }