20#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0602
22#define _WIN32_WINNT 0x0602
43 ID3D11DeviceContext* d3d_context;
44 IMFDXGIDeviceManager *dxgiManager;
75#define MF_TIMEBASE (AVRational){1, 10000000}
77#define MF_INVALID_TIME AV_NOPTS_VALUE
86 while (!(
c->async_need_input ||
c->async_have_output ||
c->draining_done ||
c->async_marker)) {
87 IMFMediaEvent *ev =
NULL;
88 MediaEventType ev_id = 0;
89 HRESULT hr = IMFMediaEventGenerator_GetEvent(
c->async_events, 0, &ev);
95 IMFMediaEvent_GetType(ev, &ev_id);
99 c->async_need_input = 1;
102 c->async_have_output = 1;
105 c->draining_done = 1;
112 IMFMediaEvent_Release(ev);
136 IMFSample_SetSampleTime(
sample, stime);
147 HRESULT hr = IMFSample_GetSampleTime(
sample, &
pts);
169 hr = IMFAttributes_GetBlobSize(
type, &MF_MT_USER_DATA, &sz);
170 if (!FAILED(hr) && sz > 0) {
190 if (!
c->out_info.cbSize && !
c->out_stream_provides_samples) {
191 hr = IMFAttributes_GetUINT32(
type, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, &sz);
194 "assuming %d bytes instead.\n", (
int)sz);
195 c->out_info.cbSize = sz;
207 hr = IMFAttributes_GetBlobSize(
type, &MF_MT_MPEG_SEQUENCE_HEADER, &sz);
208 if (!FAILED(hr) && sz > 0) {
212 hr = IMFAttributes_GetBlob(
type, &MF_MT_MPEG_SEQUENCE_HEADER, extradata, sz,
NULL);
232 hr = IMFTransform_GetOutputCurrentType(
c->mft,
c->out_stream_id, &
type);
244 }
else if (
c->is_audio) {
251 IMFMediaType_Release(
type);
266 hr = IMFSample_GetTotalLength(
sample, &
len);
273 hr = IMFSample_ConvertToContiguousBuffer(
sample, &
buffer);
279 IMFMediaBuffer_Release(
buffer);
285 IMFMediaBuffer_Unlock(
buffer);
286 IMFMediaBuffer_Release(
buffer);
291 hr = IMFAttributes_GetUINT32(
sample, &MFSampleExtension_CleanPoint, &t32);
292 if (
c->is_audio || (!FAILED(hr) && t32 != 0))
295 hr = IMFAttributes_GetUINT64(
sample, &MFSampleExtension_DecodeTimestamp, &t);
303 c->reorder_delay = avpkt->
pts - avpkt->
dts;
304 avpkt->
dts -=
c->reorder_delay;
305 avpkt->
pts -=
c->reorder_delay;
322 c->in_info.cbAlignment);
339 hr =
func->MFCreateDXGIDeviceManager(&
c->resetToken, &
c->dxgiManager);
345 hr = IMFDXGIDeviceManager_ResetDevice(
c->dxgiManager, (IUnknown*)
c->device_hwctx->device,
c->resetToken);
351 hr = IMFTransform_ProcessMessage(
c->mft, MFT_MESSAGE_SET_D3D_MANAGER, (ULONG_PTR)
c->dxgiManager);
365 ID3D11Texture2D *d3d11_texture =
NULL;
374 if (!
c->dxgiManager) {
375 hr = initialize_dxgi_manager(avctx);
381 d3d11_texture = (ID3D11Texture2D*)
frame->data[0];
382 subIdx = (int)(intptr_t)
frame->data[1];
384 if (!d3d11_texture) {
395 hr =
func->MFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D, (IUnknown*)d3d11_texture, subIdx, 0, &
buffer);
398 IMFSample_Release(
sample);
405 IMFMediaBuffer_Release(
buffer);
406 IMFSample_Release(
sample);
410 IMFMediaBuffer_Release(
buffer);
432 c->in_info.cbAlignment);
438 IMFSample_Release(
sample);
444 IMFMediaBuffer_Release(
buffer);
445 IMFSample_Release(
sample);
451 IMFMediaBuffer_SetCurrentLength(
buffer,
size);
452 IMFMediaBuffer_Unlock(
buffer);
453 IMFMediaBuffer_Release(
buffer);
455 IMFSample_Release(
sample);
525 if (
c->async_events) {
528 if (!
c->async_need_input)
532 IMFSample_SetUINT32(
sample, &MFSampleExtension_Discontinuity, TRUE);
534 hr = IMFTransform_ProcessInput(
c->mft,
c->in_stream_id,
sample, 0);
535 if (hr == MF_E_NOTACCEPTING) {
537 }
else if (FAILED(hr)) {
541 c->async_need_input = 0;
542 }
else if (!
c->draining) {
543 hr = IMFTransform_ProcessMessage(
c->mft, MFT_MESSAGE_COMMAND_DRAIN, 0);
549 c->async_need_input = 0;
561 MFT_OUTPUT_DATA_BUFFER out_buffers;
569 if (
c->async_events) {
572 if (!
c->async_have_output ||
c->draining_done) {
578 if (!
c->out_stream_provides_samples) {
581 c->out_info.cbAlignment);
586 out_buffers = (MFT_OUTPUT_DATA_BUFFER) {
587 .dwStreamID =
c->out_stream_id,
592 hr = IMFTransform_ProcessOutput(
c->mft, 0, 1, &out_buffers, &st);
594 if (out_buffers.pEvents)
595 IMFCollection_Release(out_buffers.pEvents);
598 *out_sample = out_buffers.pSample;
603 if (out_buffers.pSample)
604 IMFSample_Release(out_buffers.pSample);
606 if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) {
608 c->draining_done = 1;
610 }
else if (hr == MF_E_TRANSFORM_STREAM_CHANGE) {
618 c->async_have_output = 0;
630 c->async_have_output = 0;
632 if (ret >= 0 && !*out_sample)
644 if (!
c->frame->buf[0]) {
650 if (
c->frame->buf[0]) {
656 if (
c->is_video &&
c->codec_api) {
658 ICodecAPI_SetValue(
c->codec_api, &ff_CODECAPI_AVEncVideoForceKeyFrame,
FF_VAL_VT_UI4(1));
662 if(!
c->stream_started)
664 HRESULT hr = IMFTransform_ProcessMessage(
c->mft, MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, 0);
670 hr = IMFTransform_ProcessMessage(
c->mft, MFT_MESSAGE_NOTIFY_START_OF_STREAM, 0);
676 c->stream_started = 1;
681 IMFSample_Release(
sample);
692 IMFSample_Release(
sample);
708 hr = IMFAttributes_GetUINT32(
type, &MF_MT_AUDIO_SAMPLES_PER_SECOND, &t);
712 hr = IMFAttributes_GetUINT32(
type, &MF_MT_AUDIO_NUM_CHANNELS, &t);
716 hr = IMFAttributes_GetGUID(
type, &MF_MT_SUBTYPE, &tg);
718 if (IsEqualGUID(&
c->main_subtype, &tg))
723 hr = IMFAttributes_GetUINT32(
type, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, &t);
727 score |= (1LL << 31) -
diff;
729 score |= (1LL << 30) +
diff;
733 hr = IMFAttributes_GetUINT32(
type, &MF_MT_AAC_PAYLOAD_TYPE, &t);
734 if (!FAILED(hr) && t != 0)
763 hr = IMFAttributes_GetUINT32(
type, &MF_MT_AUDIO_SAMPLES_PER_SECOND, &t);
767 hr = IMFAttributes_GetUINT32(
type, &MF_MT_AUDIO_NUM_CHANNELS, &t);
785 hr = IMFAttributes_GetUINT32(
type, &MF_MT_AUDIO_SAMPLES_PER_SECOND, &t);
791 hr = IMFAttributes_GetUINT32(
type, &MF_MT_AUDIO_NUM_CHANNELS, &t);
807 hr = IMFAttributes_GetGUID(
type, &MF_MT_SUBTYPE, &tg);
809 if (IsEqualGUID(&
c->main_subtype, &tg))
822 IMFAttributes_SetUINT32(
type, &MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
843 IMFAttributes_SetUINT32(
type, &MF_MT_MPEG2_PROFILE,
profile);
846 IMFAttributes_SetUINT32(
type, &MF_MT_AVG_BITRATE, avctx->
bit_rate);
853 if (
c->opt_enc_rc >= 0)
854 ICodecAPI_SetValue(
c->codec_api, &ff_CODECAPI_AVEncCommonRateControlMode,
FF_VAL_VT_UI4(
c->opt_enc_rc));
856 if (
c->opt_enc_quality >= 0)
857 ICodecAPI_SetValue(
c->codec_api, &ff_CODECAPI_AVEncCommonQuality,
FF_VAL_VT_UI4(
c->opt_enc_quality));
883 ICodecAPI_SetValue(
c->codec_api, &ff_CODECAPI_AVEncH264CABACEnable,
FF_VAL_VT_BOOL(1));
885 if (
c->opt_enc_scenario >= 0)
886 ICodecAPI_SetValue(
c->codec_api, &ff_CODECAPI_AVScenarioInfo,
FF_VAL_VT_UI4(
c->opt_enc_scenario));
889 ICodecAPI_SetValue(
c->codec_api, &ff_CODECAPI_AVLowLatencyMode,
FF_VAL_VT_UI4(1));
930 IMFAttributes_SetUINT32(
type, &MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
948 IMFMediaType *out_type =
NULL;
950 int out_type_index = -1;
958 hr = IMFTransform_GetOutputAvailableType(
c->mft,
c->out_stream_id, n, &
type);
959 if (hr == MF_E_NO_MORE_TYPES || hr == E_NOTIMPL)
961 if (hr == MF_E_TRANSFORM_TYPE_NOT_SET) {
977 }
else if (
c->is_audio) {
981 if (score > out_type_score) {
983 IMFMediaType_Release(out_type);
985 out_type_score = score;
987 IMFMediaType_AddRef(out_type);
990 IMFMediaType_Release(
type);
996 hr =
c->functions.MFCreateMediaType(&out_type);
1006 }
else if (
c->is_audio) {
1014 hr = IMFTransform_SetOutputType(
c->mft,
c->out_stream_id, out_type, 0);
1017 }
else if (hr == MF_E_TRANSFORM_TYPE_NOT_SET) {
1028 IMFMediaType_Release(out_type);
1037 IMFMediaType *in_type =
NULL;
1039 int in_type_index = -1;
1043 for (n = 0; ; n++) {
1047 hr = IMFTransform_GetInputAvailableType(
c->mft,
c->in_stream_id, n, &
type);
1048 if (hr == MF_E_NO_MORE_TYPES || hr == E_NOTIMPL)
1050 if (hr == MF_E_TRANSFORM_TYPE_NOT_SET) {
1066 }
else if (
c->is_audio) {
1070 if (score > in_type_score) {
1072 IMFMediaType_Release(in_type);
1074 in_type_score = score;
1076 IMFMediaType_AddRef(in_type);
1079 IMFMediaType_Release(
type);
1094 }
else if (
c->is_audio) {
1102 hr = IMFTransform_SetInputType(
c->mft,
c->in_stream_id, in_type, 0);
1105 }
else if (hr == MF_E_TRANSFORM_TYPE_NOT_SET) {
1116 IMFMediaType_Release(in_type);
1126 int need_input = 1, need_output = 1;
1128 for (n = 0; n < 2 && (need_input || need_output); n++) {
1133 need_input = ret < 1;
1137 need_output = ret < 1;
1139 if (need_input || need_output) {
1141 need_input, need_output);
1153 hr = IMFTransform_GetInputStreamInfo(
c->mft,
c->in_stream_id, &
c->in_info);
1157 (
int)
c->in_info.cbSize, (
int)
c->in_info.cbAlignment);
1159 hr = IMFTransform_GetOutputStreamInfo(
c->mft,
c->out_stream_id, &
c->out_info);
1162 c->out_stream_provides_samples =
1163 (
c->out_info.dwFlags & MFT_OUTPUT_STREAM_PROVIDES_SAMPLES) ||
1164 (
c->out_info.dwFlags & MFT_OUTPUT_STREAM_CAN_PROVIDE_SAMPLES);
1166 (
int)
c->out_info.cbSize, (
int)
c->out_info.cbAlignment,
1167 c->out_stream_provides_samples ?
" (provides samples)" :
"");
1179 IMFAttributes *attrs;
1185 if (!(
c->is_video &&
c->opt_enc_hw))
1188 hr = IMFTransform_GetAttributes(
c->mft, &attrs);
1194 hr = IMFAttributes_GetUINT32(attrs, &MF_TRANSFORM_ASYNC, &v);
1205 hr = IMFAttributes_SetUINT32(attrs, &MF_TRANSFORM_ASYNC_UNLOCK, TRUE);
1211 hr = IMFTransform_QueryInterface(
c->mft, &IID_IMFMediaEventGenerator, (
void **)&
c->async_events);
1220 IMFAttributes_Release(attrs);
1225 const AVCodec *codec,
int use_hw)
1229 MFT_REGISTER_TYPE_INFO reg = {0};
1238 reg.guidSubtype = *subtype;
1241 reg.guidMajorType = MFMediaType_Audio;
1242 category = MFT_CATEGORY_AUDIO_ENCODER;
1244 reg.guidMajorType = MFMediaType_Video;
1245 category = MFT_CATEGORY_VIDEO_ENCODER;
1267 c->is_video = !
c->is_audio;
1270 if (
c->is_video &&
c->opt_enc_hw)
1276 c->main_subtype = *subtype;
1278 if ((ret =
mf_create(avctx, &
c->functions, &
c->mft, avctx->
codec, use_hw)) < 0)
1284 hr = IMFTransform_QueryInterface(
c->mft, &IID_ICodecAPI, (
void **)&
c->codec_api);
1289 hr = IMFTransform_GetStreamIDs(
c->mft, 1, &
c->in_stream_id, 1, &
c->out_stream_id);
1290 if (hr == E_NOTIMPL) {
1291 c->in_stream_id =
c->out_stream_id = 0;
1292 }
else if (FAILED(hr)) {
1305 int sleep = 10000, total = 0;
1307 while (total < 70*1000) {
1324 avctx->
extradata ?
"Got" :
"Didn't get", total / 1000);
1331#define LOAD_MF_FUNCTION(context, func_name) \
1332 context->functions.func_name = (void *)dlsym(context->library, #func_name); \
1333 if (!context->functions.func_name) { \
1334 av_log(context, AV_LOG_ERROR, "DLL mfplat.dll failed to find function "\
1336 return AVERROR_UNKNOWN; \
1342#define LOAD_MF_FUNCTION(context, func_name) \
1343 context->functions.func_name = func_name; \
1344 if (!context->functions.func_name) { \
1345 av_log(context, AV_LOG_ERROR, "Failed to find function " #func_name \
1347 return AVERROR_UNKNOWN; \
1359 c->library = dlopen(
"mfplat.dll", 0);
1361 c->d3d_dll = dlopen(
"D3D11.dll", 0);
1390 ICodecAPI_Release(
c->codec_api);
1392 if (
c->async_events)
1393 IMFMediaEventGenerator_Release(
c->async_events);
1397 IMFDXGIDeviceManager_Release(
c->dxgiManager);
1404 dlclose(
c->library);
1406 dlclose(
c->d3d_dll);
1432#define OFFSET(x) offsetof(MFContext, x)
1434#define MF_ENCODER(MEDIATYPE, NAME, ID, OPTS, FMTS, CAPS, DEFAULTS) \
1435 static const AVClass ff_ ## NAME ## _mf_encoder_class = { \
1436 .class_name = #NAME "_mf", \
1437 .item_name = av_default_item_name, \
1439 .version = LIBAVUTIL_VERSION_INT, \
1441 const FFCodec ff_ ## NAME ## _mf_encoder = { \
1442 .p.priv_class = &ff_ ## NAME ## _mf_encoder_class, \
1443 .p.name = #NAME "_mf", \
1444 CODEC_LONG_NAME(#ID " via MediaFoundation"), \
1445 .p.type = AVMEDIA_TYPE_ ## MEDIATYPE, \
1446 .p.id = AV_CODEC_ID_ ## ID, \
1447 .priv_data_size = sizeof(MFContext), \
1449 .close = mf_close, \
1450 FF_CODEC_RECEIVE_PACKET_CB(mf_receive_packet), \
1453 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
1454 .defaults = DEFAULTS, \
1458 CODEC_SAMPLEFMTS(AV_SAMPLE_FMT_S16),
1460 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HYBRID | \
1461 AV_CODEC_CAP_DR1 | AV_CODEC_CAP_VARIABLE_FRAME_SIZE,
1467#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1469 {
"rate_control",
"Select rate control mode",
OFFSET(opt_enc_rc),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE, .unit =
"rate_control"},
1470 {
"default",
"Default mode", 0,
AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0,
VE, .unit =
"rate_control"},
1480 {
"scenario",
"Select usage scenario",
OFFSET(opt_enc_scenario),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE, .unit =
"scenario"},
1481 {
"default",
"Default scenario", 0,
AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0,
VE, .unit =
"scenario"},
1501 CODEC_PIXFMTS(AV_PIX_FMT_NV12, AV_PIX_FMT_YUV420P, AV_PIX_FMT_D3D11),
1504 CODEC_PIXFMTS(AV_PIX_FMT_NV12, AV_PIX_FMT_YUV420P),
1507 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HYBRID | \
static const FFCodecDefault defaults[]
#define AV_PROFILE_H264_MAIN
#define AV_PROFILE_H264_HIGH
static enum AVPixelFormat pix_fmt
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_EOF
End of file.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters.
int av_image_copy_to_buffer(uint8_t *dst, int dst_size, const uint8_t *const src_data[4], const int src_linesize[4], enum AVPixelFormat pix_fmt, int width, int height, int align)
Copy image data from an image into a buffer.
@ AV_PICTURE_TYPE_I
Intra.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
AVSampleFormat
Audio sample formats.
#define AV_NOPTS_VALUE
Undefined timestamp value.
An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
common internal api header.
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Memory handling functions.
enum AVPixelFormat ff_media_type_to_pix_fmt(IMFAttributes *type)
enum AVSampleFormat ff_media_type_to_sample_fmt(IMFAttributes *type)
HRESULT ff_MFSetAttributeSize(IMFAttributes *pattr, REFGUID guid, UINT32 uw, UINT32 uh)
IMFSample * ff_create_memory_sample(MFFunctions *f, void *fill_data, size_t size, size_t align)
const CLSID * ff_codec_to_mf_subtype(enum AVCodecID codec)
#define ff_MFSetAttributeRatio
int ff_instantiate_mf(void *log, MFFunctions *f, GUID category, MFT_REGISTER_TYPE_INFO *in_type, MFT_REGISTER_TYPE_INFO *out_type, int use_hw, IMFTransform **res)
void ff_media_type_dump(void *log, IMFMediaType *type)
void ff_free_mf(MFFunctions *f, IMFTransform **mft)
#define FF_VAL_VT_BOOL(v)
@ ff_METransformNeedInput
@ ff_METransformHaveOutput
@ ff_METransformDrainComplete
@ ff_eAVEncCommonRateControlMode_UnconstrainedVBR
@ ff_eAVEncCommonRateControlMode_LowDelayVBR
@ ff_eAVEncCommonRateControlMode_CBR
@ ff_eAVEncCommonRateControlMode_PeakConstrainedVBR
@ ff_eAVEncCommonRateControlMode_GlobalVBR
@ ff_eAVEncCommonRateControlMode_GlobalLowDelayVBR
@ ff_eAVEncCommonRateControlMode_Quality
@ ff_eAVEncH264VProfile_High
@ ff_eAVEncH264VProfile_Main
@ ff_eAVEncH264VProfile_Base
@ ff_eAVScenarioInfo_CameraRecord
@ ff_eAVScenarioInfo_Archive
@ ff_eAVScenarioInfo_DisplayRemoting
@ ff_eAVScenarioInfo_VideoConference
@ ff_eAVScenarioInfo_LiveStreaming
@ ff_eAVScenarioInfo_DisplayRemotingWithFeatureMap
static int mf_create(void *log, MFFunctions *f, IMFTransform **mft, const AVCodec *codec, int use_hw)
static int mf_encv_output_adjust(AVCodecContext *avctx, IMFMediaType *type)
static int process_software_frame(AVCodecContext *avctx, const AVFrame *frame, IMFSample **out_sample)
static int mf_negotiate_types(AVCodecContext *avctx)
static int mf_output_type_get(AVCodecContext *avctx)
static int mf_setup_context(AVCodecContext *avctx)
static void mf_sample_set_pts(AVCodecContext *avctx, IMFSample *sample, int64_t av_pts)
static int64_t mf_from_mf_time(AVCodecContext *avctx, LONGLONG stime)
static int mf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
static int mf_wait_events(AVCodecContext *avctx)
static int64_t mf_enca_output_score(AVCodecContext *avctx, IMFMediaType *type)
static int64_t mf_sample_get_pts(AVCodecContext *avctx, IMFSample *sample)
static int mf_load_library(AVCodecContext *avctx)
static int mf_send_sample(AVCodecContext *avctx, IMFSample *sample)
static int64_t mf_sample_get_duration(AVCodecContext *avctx, IMFSample *sample)
static int mf_v_avframe_to_sample(AVCodecContext *avctx, const AVFrame *frame, IMFSample **out_sample)
static int64_t mf_enca_input_score(AVCodecContext *avctx, IMFMediaType *type)
static int mf_enca_input_adjust(AVCodecContext *avctx, IMFMediaType *type)
static av_cold int mf_init(AVCodecContext *avctx)
static LONGLONG mf_to_mf_time(AVCodecContext *avctx, int64_t av_pts)
static int mf_enca_output_type_get(AVCodecContext *avctx, IMFMediaType *type)
static int mf_encv_input_adjust(AVCodecContext *avctx, IMFMediaType *type)
static int mf_init_encoder(AVCodecContext *avctx)
#define LOAD_MF_FUNCTION(context, func_name)
#define MF_ENCODER(MEDIATYPE, NAME, ID, OPTS, FMTS, CAPS, DEFAULTS)
static int mf_choose_input_type(AVCodecContext *avctx)
static int mf_sample_to_avpacket(AVCodecContext *avctx, IMFSample *sample, AVPacket *avpkt)
static int mf_receive_sample(AVCodecContext *avctx, IMFSample **out_sample)
static int mf_close(AVCodecContext *avctx)
static int mf_encv_output_type_get(AVCodecContext *avctx, IMFMediaType *type)
static const AVOption venc_opts[]
static int mf_avframe_to_sample(AVCodecContext *avctx, const AVFrame *frame, IMFSample **out_sample)
static int64_t mf_encv_output_score(AVCodecContext *avctx, IMFMediaType *type)
static int mf_a_avframe_to_sample(AVCodecContext *avctx, const AVFrame *frame, IMFSample **out_sample)
static int mf_unlock_async(AVCodecContext *avctx)
static int64_t mf_encv_input_score(AVCodecContext *avctx, IMFMediaType *type)
static int mf_choose_output_type(AVCodecContext *avctx)
static int mf_enca_output_adjust(AVCodecContext *avctx, IMFMediaType *type)
static AVRational mf_get_tb(AVCodecContext *avctx)
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int rc_buffer_size
decoder bitstream buffer size
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
int global_quality
Global quality for codecs which cannot change it per frame.
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
enum AVMediaType codec_type
int has_b_frames
Size of the frame reordering buffer in the decoder.
int64_t bit_rate
the average bitrate
const struct AVCodec * codec
int sample_rate
samples per second
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
int64_t rc_max_rate
maximum bitrate
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
This struct is allocated as AVHWDeviceContext.hwctx.
This structure describes decoded (raw) audio or video data.
This struct describes a set or pool of "hardware" frames (i.e.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Rational number (pair of numerator and denominator).
MFT_OUTPUT_STREAM_INFO out_info
MFT_INPUT_STREAM_INFO in_info
IMFMediaEventGenerator * async_events
int out_stream_provides_samples
int av_usleep(unsigned usec)
Sleep for a period of time.
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)