[FFmpeg-devel] [AMD-AMF] What does these code in amfenc.c actually mean?

Schwarzer cnschwarzer at qq.com
Sat Dec 24 18:27:13 EET 2022


I'm using h264_amf in my project, and want to use D3D11 pixel format to encode video in D3D11Texture2D to elinimate copy between GPU and CPU.
I found the performance is very poor, comparing to obs-project which also use AMF as an encoder. After comparing and debugging through codes, I found these code strange and seems does nothing useful to encoding job:


In branch 5.1.2
amfenc.c
Line 659
if (hw_surface) {
    AMFBuffer *frame_ref_storage_buffer;

    // input HW surfaces can be vertically aligned by 16; tell AMF the real size
    surface->pVtbl->SetCrop(surface, 0, 0, frame->width, frame->height);

    frame_ref_storage_buffer = amf_create_buffer_with_frame_ref(frame, ctx->context);
    AMF_RETURN_IF_FALSE(ctx, frame_ref_storage_buffer != NULL, AVERROR(ENOMEM), "create_buffer_with_frame_ref() returned NULL\n");

    res = amf_set_property_buffer(surface, L"av_frame_ref", frame_ref_storage_buffer);
    AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "SetProperty failed for \"av_frame_ref\" with error %d\n", res);
    ctx->hwsurfaces_in_queue++;
    frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
}



Line 707
buffer->pVtbl->Release(buffer);

if (data->pVtbl->HasProperty(data, L"av_frame_ref")) {
    AMFBuffer *frame_ref_storage_buffer;
    res = amf_get_property_buffer(data, L"av_frame_ref", &frame_ref_storage_buffer);
    AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetProperty failed for \"av_frame_ref\" with error %d\n", res);
    amf_release_buffer_with_frame_ref(frame_ref_storage_buffer);
    ctx->hwsurfaces_in_queue--;
}

data->pVtbl->Release(data);








Schwarzer
cnschwarzer at qq.com



 


More information about the ffmpeg-devel mailing list