process video frame
| 2061 | |
| 2062 | // process video frame |
| 2063 | void FFmpegWriter::process_video_packet(std::shared_ptr<Frame> frame) { |
| 2064 | // Source dimensions (RGBA) |
| 2065 | int src_w = frame->GetWidth(); |
| 2066 | int src_h = frame->GetHeight(); |
| 2067 | |
| 2068 | // Skip empty frames (1×1) |
| 2069 | if (src_w == 1 && src_h == 1) |
| 2070 | return; |
| 2071 | |
| 2072 | // Point persistent_src_frame->data to RGBA pixels |
| 2073 | const uchar* pixels = frame->GetPixels(); |
| 2074 | if (!persistent_src_frame) { |
| 2075 | persistent_src_frame = av_frame_alloc(); |
| 2076 | if (!persistent_src_frame) |
| 2077 | throw OutOfMemory("Could not allocate persistent_src_frame", path); |
| 2078 | persistent_src_frame->format = AV_PIX_FMT_RGBA; |
| 2079 | persistent_src_frame->width = src_w; |
| 2080 | persistent_src_frame->height = src_h; |
| 2081 | persistent_src_frame->linesize[0] = src_w * 4; |
| 2082 | } |
| 2083 | persistent_src_frame->data[0] = const_cast<uint8_t*>( |
| 2084 | reinterpret_cast<const uint8_t*>(pixels) |
| 2085 | ); |
| 2086 | |
| 2087 | // Prepare persistent_dst_frame + buffer on first use |
| 2088 | if (!persistent_dst_frame) { |
| 2089 | persistent_dst_frame = av_frame_alloc(); |
| 2090 | if (!persistent_dst_frame) |
| 2091 | throw OutOfMemory("Could not allocate persistent_dst_frame", path); |
| 2092 | |
| 2093 | // Decide destination pixel format: NV12 if HW accel is on, else encoder’s pix_fmt |
| 2094 | AVPixelFormat dst_fmt = video_codec_ctx->pix_fmt; |
| 2095 | #if USE_HW_ACCEL |
| 2096 | if (hw_en_on && hw_en_supported) { |
| 2097 | dst_fmt = AV_PIX_FMT_NV12; |
| 2098 | } |
| 2099 | #endif |
| 2100 | persistent_dst_frame->format = dst_fmt; |
| 2101 | persistent_dst_frame->width = info.width; |
| 2102 | persistent_dst_frame->height = info.height; |
| 2103 | |
| 2104 | persistent_dst_size = av_image_get_buffer_size( |
| 2105 | dst_fmt, info.width, info.height, 1 |
| 2106 | ); |
| 2107 | if (persistent_dst_size < 0) |
| 2108 | throw ErrorEncodingVideo("Invalid destination image size", -1); |
| 2109 | |
| 2110 | persistent_dst_buffer = static_cast<uint8_t*>( |
| 2111 | av_malloc(persistent_dst_size) |
| 2112 | ); |
| 2113 | if (!persistent_dst_buffer) |
| 2114 | throw OutOfMemory("Could not allocate persistent_dst_buffer", path); |
| 2115 | |
| 2116 | av_image_fill_arrays( |
| 2117 | persistent_dst_frame->data, |
| 2118 | persistent_dst_frame->linesize, |
| 2119 | persistent_dst_buffer, |
| 2120 | dst_fmt, |
nothing calls this directly
no test coverage detected