Skip to content

Commit

Permalink
WIP: Use native camera image format for all processing
Browse files Browse the repository at this point in the history
  • Loading branch information
webgeek1234 committed May 31, 2024
1 parent afe994a commit c043667
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/zm_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ bool Image::EncodeJpeg(JOCTET *outbuffer, int *outbuffer_size, AVCodecContext *p
av_frame_ptr frame = av_frame_ptr{zm_av_frame_alloc()};
AVPacket *pkt;

if (av_image_get_buffer_size(AV_PIX_FMT_YUVJ420P, width, height, 32) > Size()) {
if (av_image_get_buffer_size(AV_PIX_FMT_YUVJ420P, width, height, 32) > static_cast<int>(Size())) {
Error("Output buffer not large enough");
return false;
}
Expand All @@ -1639,6 +1639,12 @@ bool Image::EncodeJpeg(JOCTET *outbuffer, int *outbuffer_size, AVCodecContext *p
PopulateFrame(frame.get());
}

if (frame.get()->format != AV_PIX_FMT_YUV420P) {
Error("Jpeg frame format incorrect, got %d", frame.get()->format);
av_frame_unref(frame.get());
return false;
}

pkt = av_packet_alloc();

avcodec_send_frame(p_jpegcodeccontext, frame.get());
Expand Down Expand Up @@ -5460,7 +5466,9 @@ __attribute__((noinline)) void std_deinterlace_4field_abgr(uint8_t* col1, uint8_
}

AVPixelFormat Image::AVPixFormat() const {
if ( colours == ZM_COLOUR_RGB32 ) {
if ( subpixelorder == ZM_SUBPIX_ORDER_YUV420P) {
return AV_PIX_FMT_YUV420P;
} else if ( colours == ZM_COLOUR_RGB32 ) {
return AV_PIX_FMT_RGBA;
} else if ( colours == ZM_COLOUR_RGB24 ) {
if ( subpixelorder == ZM_SUBPIX_ORDER_BGR) {
Expand Down
3 changes: 2 additions & 1 deletion src/zm_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2932,7 +2932,8 @@ bool Monitor::Decode() {
int ret = packet->decode(camera->getVideoCodecContext());
if (ret > 0 and !zm_terminate) {
if (packet->in_frame and !packet->image) {
packet->image = new Image(camera_width, camera_height, camera->Colours(), camera->SubpixelOrder());
unsigned int subpix = packet->in_frame->format == AV_PIX_FMT_YUV420P ? ZM_SUBPIX_ORDER_YUV420P : camera->SubpixelOrder();
packet->image = new Image(camera_width, camera_height, camera->Colours(), subpix);

if (convert_context || this->setupConvertContext(packet->in_frame.get(), packet->image)) {
if (!packet->image->Assign(packet->in_frame.get(), convert_context, dest_frame.get())) {
Expand Down

0 comments on commit c043667

Please sign in to comment.