diff options
Diffstat (limited to 'src/encoder/video/vaapi.c')
-rw-r--r-- | src/encoder/video/vaapi.c | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/src/encoder/video/vaapi.c b/src/encoder/video/vaapi.c index d558785..c7ccd26 100644 --- a/src/encoder/video/vaapi.c +++ b/src/encoder/video/vaapi.c @@ -92,6 +92,10 @@ static bool gsr_video_encoder_vaapi_setup_textures(gsr_video_encoder_vaapi *self if(self->prime.fourcc == VA_FOURCC_NV12 || self->prime.fourcc == VA_FOURCC_P010) { const uint32_t *formats = self->prime.fourcc == VA_FOURCC_NV12 ? formats_nv12 : formats_p010; const int div[2] = {1, 2}; // divide UV texture size by 2 because chroma is half size + const float border_colors[2][4] = { + {0.0f, 0.0f, 0.0f, 1.0f}, + {0.5f, 0.5f, 0.0f, 1.0f} + }; self->params.egl->glGenTextures(2, self->target_textures); for(int i = 0; i < 2; ++i) { @@ -121,10 +125,11 @@ static bool gsr_video_encoder_vaapi_setup_textures(gsr_video_encoder_vaapi *self } self->params.egl->glBindTexture(GL_TEXTURE_2D, self->target_textures[i]); - self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + self->params.egl->glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border_colors[i]); + self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + self->params.egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); while(self->params.egl->glGetError()) {} while(self->params.egl->eglGetError() != EGL_SUCCESS){} @@ -167,32 +172,21 @@ static bool gsr_video_encoder_vaapi_start(gsr_video_encoder *encoder, AVCodecCon } else { video_codec_context->height = FFALIGN(video_codec_context->height, 16); } + } else { + video_codec_context->width = FFALIGN(video_codec_context->width, 2); + video_codec_context->height = FFALIGN(video_codec_context->height, 2); } - const int crop_top = (video_codec_context->height - frame->height) / 2; - const int crop_left = (video_codec_context->width - frame->width) / 2; - if(crop_top != 0 || crop_left != 0) { + if(FFALIGN(video_codec_context->width, 2) != FFALIGN(frame->width, 2) || FFALIGN(video_codec_context->height, 2) != FFALIGN(frame->height, 2)) { fprintf(stderr, "gsr warning: gsr_video_encoder_vaapi_start: black bars have been added to the video because of a bug in AMD drivers/hardware. Record with h264 codec instead (-k h264) to get around this issue\n"); -#if 0 - #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 10, 100) - const int crop_bottom = crop_top; - const int crop_right = crop_left; - fprintf(stderr, "gsr info: cropping metadata has been added to the file to try and workaround this issue. Video players that support this will remove the black bars when the video is playing\n"); - const int frame_cropping_data_size = 4 * sizeof(uint32_t); - uint8_t *frame_cropping = av_malloc(frame_cropping_data_size); - if(frame_cropping) { - AV_WL32(frame_cropping + 0, crop_top); - AV_WL32(frame_cropping + 4, crop_bottom); - AV_WL32(frame_cropping + 8, crop_left); - AV_WL32(frame_cropping + 12, crop_right); - const bool sidedata_added = av_packet_side_data_add(&video_stream->codecpar->coded_side_data, &video_stream->codecpar->nb_coded_side_data, AV_PKT_DATA_FRAME_CROPPING, frame_cropping, frame_cropping_data_size, 0) != NULL; - if(!sidedata_added) - av_free(frame_cropping); - } - #endif -#endif } + if(video_codec_context->width < 128) + video_codec_context->width = 128; + + if(video_codec_context->height < 128) + video_codec_context->height = 128; + frame->width = video_codec_context->width; frame->height = video_codec_context->height; |