jkuri / opencv-ffmpeg-rtmp-stream

OpenCV FFMpeg Live Video Stream over RTMP protocol.
MIT License
210 stars 59 forks source link

Cant Stream Higher Resolutions(Windows10)x64 #9

Closed batuhannzorlu closed 1 year ago

batuhannzorlu commented 1 year ago

Hi, I have built the project on windows10(x64), using prebuilt ffmpeg libraries. Project is woking smoothly, but the problem is i can not get higher resolutions than 800x600,(it works with lower resolutions). Application does not return anything to debug pic .

jkuri commented 1 year ago

Try running with --log option, it might produce some more information. By the way, it is possible that your camera doesn't support that resolution and fps combination, I noticed that already with my camera. Try changing framerate to 24 or some other value and let me know if it helps.

batuhannzorlu commented 1 year ago

I have double checked camera's FPS and resolution. And that is not the problem. My camera supports. Also i have tried the --log true flag but doesnt help either.(it gives the exact same output as 800x600.Doesnt display any error.)

jkuri commented 1 year ago

I honestly don’t know how to help you. You can try to play around with bitrate and profile parameters, but I am not sure.

On Tue, 2 Aug 2022 at 20:02, Batuhan @.***> wrote:

I have double checked camera's FPS and resolution. And that is not the problem. My camera supports. Also i have tried the --log true flag but doesnt help either.(it gives the exact same output as 800x600.Doesnt display any error.)

— Reply to this email directly, view it on GitHub https://github.com/jkuri/opencv-ffmpeg-rtmp-stream/issues/9#issuecomment-1203048239, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANWPNV2WZQ42XNTSC5EIHDVXFPCJANCNFSM55L6HCSA . You are receiving this because you commented.Message ID: @.***>

batuhannzorlu commented 1 year ago

i am writing this, for future readers, the code is buggy. The problem is appereantly related to memory allocation.

AVFrame *allocate_frame_buffer(AVCodecContext *codec_ctx, double width, double height)
{
  AVFrame *frame_ = av_frame_alloc();
  int i = av_image_get_buffer_size(codec_ctx->pix_fmt, width, height, 1);
  //std::vector<uint8_t> framebuf(av_image_get_buffer_size(codec_ctx->pix_fmt, width, height, 1));
  uint8_t* pFrmBufer = new uint8_t[i];
  av_image_fill_arrays(frame_->data, frame_->linesize, pFrmBufer/*framebuf.data()*/, codec_ctx->pix_fmt, width, height, 1);
  frame_->width = width;
  frame_->height = height;
  frame_->format = static_cast<int>(codec_ctx->pix_fmt);

  return frame_;
}

Just create the uint8_t pointer rather than vector, because it is a local variable(in stack ) and it is always deleted after out of the function. @jkuri please also update your function. thanks.

jkuri commented 1 year ago

hi, thanks for this! can you please create a pull request with that fix?