c++ - Setting individual pixels of an RGB frame for ffmpeg encoding -


i'm trying change test pattern of ffmpeg streamer, trouble syncing libavformat/ffmpeg x264 , rtp , familiar rgb format. broader goal compute frames of streamed video on fly.

so replaced av_pix_fmt_monowhite av_pix_fmt_rgb24, "packed rgb 8:8:8, 24bpp, rgbrgb..." according http://libav.org/doxygen/master/pixfmt_8h.html .

to stuff pixel array called data, i've tried many variations on

for (int y=0; y<height; ++y) {   (int x=0; x<width; ++x) {     uint8_t* rgb = data + ((y*width + x) *3);     const double = x/double(width); //  const double j = y/double(height);     rgb[0] = 255*i;     rgb[1] = 0;     rgb[2] = 255*(1-i);   } } 

at heightxwidth= 80x60, version yields screenshot of red-to-blue stripes, when expect single blue-to-red horizontal gradient.

640x480 yields same 4-column pattern, far more horizontal stripes.

640x640, 160x160, etc, yield three columns, cyan-ish / magenta-ish / yellow-ish, same kind of horizontal stripiness.

vertical gradients behave more weirdly.

appearance unaffected av_pix_fmt_rgba attempt (4 not 3 bytes per pixel, alpha=255). unaffected port c c++.

the argument srcstrides passed sws_scale() length-1 array, containing single int height.

access each pixel of avframe asks same question in less detail, far unanswered.

the streamer emits 1 warning, doubt affects appearance:

[rtp @ 0x269c0a0] encoder did not produce proper pts, making up.

so. how set rgb value of pixel in frame sent sws_scale() (and x264_encoder_encode() , av_interleaved_write_frame())?

use avpicture_fill() described in encoding screenshot video using ffmpeg .

instead of passing data directly sws_scale(), this:

avframe* pic = avcodec_alloc_frame(); avpicture_fill((avpicture *)pic, data, av_pix_fmt_rgb24, width, height); 

and replace 2nd , 3rd args of sws_scale() with

pic->data, pic->linesize, 

then gradients above work properly, @ many resolutions.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -