1

The goal is to create a video stream from bitmap frames.

Current solution: I am streaming raw 24bpp bitmap data over tcp from my machine to a "remote" server, to distribute the frames to the clients. This works well when everything runs on my local machine.

Problem: The size of a frame is 1440000 (800*600*3) bytes, I only have a 2Mbps upstream and I need the video to be 25 frames per second with a resolution of 800x600.

Approach: So after a bit of research my approach would be to encode the bitmap frames into h264 and stream the resulting video.

Current situation: I compiled x264 and ffmpeg (for swscale, to convert RGB to YUV) and I am able to encode 24bpp bitmap Frames with x264. The last action in my test program is a call to x264_encoder_encode. The bitmap data in the test program is randomly generated for every frame.

Now to my question(s):

Where do I go from here? TCP, UDP, RTMP? Which data would be transfered? Do i just transmit the resulting frame from x264_encoder_encode? Which still has a size of ~140000 bytes, according to the return value of the function. That would result in (25*140000 = 3500000) 3,5 Mbps which is still greater than the 2Mpbs I have available.

While I dont really know how (yet!), I am confidend that this task is feasable. For example, here is a spreadsheet displaying needed bandwith for different resolutions for streaming platforms like twitch.tv (using RTMP).

My current x264_param (from this post) looks like this (just fyi):

x264_param_default_preset(&param, "veryfast", "zerolatency");
param.i_threads = 1;
param.i_width = width;
param.i_height = height;
param.i_fps_num = fps;
param.i_fps_den = 1;
// Intra refres:
param.i_keyint_max = fps;
param.b_intra_refresh = 1;
//Rate control:
param.rc.i_rc_method = X264_RC_CRF;
param.rc.f_rf_constant = 25;
param.rc.f_rf_constant_max = 35;
//For streaming:
param.b_repeat_headers = 1;
param.b_annexb = 1;
x264_param_apply_profile(&param, "baseline");

thank you in advance.

Community
  • 1
  • 1
Jones
  • 239
  • 1
  • 4
  • 11
  • Regarding the choice of transport protocol (UDP, TCP, RTMP), please precise if your network is a local or web. Because then the constraints are different. – RawBean Mar 29 '16 at 07:58
  • the goal is to stream it over the web – Jones Mar 29 '16 at 15:20
  • Hmmm. I'm sorry I couldn't give you a nice answer. But I could tell you that it sounds challenging since you will have to deal with missing packets (UDP), some of them could not arrive in the right order (TCP), and you will have to deal with a certain latency if you don't choose x265 parameters to skip P frames. I know company like www.digigram.com who sell complete solution for video streaming. For sure it's overkill for you but to give an idea I think it's a project that needs months, or at least weeks of development – RawBean Mar 29 '16 at 20:05

0 Answers0