FFmpeg
Data Structures | Macros | Functions | Variables
mfenc.c File Reference
#include "encode.h"
#include "mf_utils.h"
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "libavutil/time.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  MFContext
 

Macros

#define COBJMACROS
 
#define _WIN32_WINNT   0x0602
 
#define MF_TIMEBASE   (AVRational){1, 10000000}
 
#define MF_INVALID_TIME   AV_NOPTS_VALUE
 
#define OFFSET(x)   offsetof(MFContext, x)
 
#define MF_ENCODER(MEDIATYPE, NAME, ID, OPTS, EXTRA)
 
#define AFMTS
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 
#define VFMTS
 

Functions

static int mf_choose_output_type (AVCodecContext *avctx)
 
static int mf_setup_context (AVCodecContext *avctx)
 
static int mf_wait_events (AVCodecContext *avctx)
 
static AVRational mf_get_tb (AVCodecContext *avctx)
 
static LONGLONG mf_to_mf_time (AVCodecContext *avctx, int64_t av_pts)
 
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 int64_t mf_sample_get_pts (AVCodecContext *avctx, IMFSample *sample)
 
static int mf_enca_output_type_get (AVCodecContext *avctx, IMFMediaType *type)
 
static int mf_encv_output_type_get (AVCodecContext *avctx, IMFMediaType *type)
 
static int mf_output_type_get (AVCodecContext *avctx)
 
static int mf_sample_to_avpacket (AVCodecContext *avctx, IMFSample *sample, AVPacket *avpkt)
 
static IMFSample * mf_a_avframe_to_sample (AVCodecContext *avctx, const AVFrame *frame)
 
static IMFSample * mf_v_avframe_to_sample (AVCodecContext *avctx, const AVFrame *frame)
 
static IMFSample * mf_avframe_to_sample (AVCodecContext *avctx, const AVFrame *frame)
 
static int mf_send_sample (AVCodecContext *avctx, IMFSample *sample)
 
static int mf_receive_sample (AVCodecContext *avctx, IMFSample **out_sample)
 
static int mf_receive_packet (AVCodecContext *avctx, AVPacket *avpkt)
 
static int64_t mf_enca_output_score (AVCodecContext *avctx, IMFMediaType *type)
 
static int mf_enca_output_adjust (AVCodecContext *avctx, IMFMediaType *type)
 
static int64_t mf_enca_input_score (AVCodecContext *avctx, IMFMediaType *type)
 
static int mf_enca_input_adjust (AVCodecContext *avctx, IMFMediaType *type)
 
static int64_t mf_encv_output_score (AVCodecContext *avctx, IMFMediaType *type)
 
static int mf_encv_output_adjust (AVCodecContext *avctx, IMFMediaType *type)
 
static int64_t mf_encv_input_score (AVCodecContext *avctx, IMFMediaType *type)
 
static int mf_encv_input_adjust (AVCodecContext *avctx, IMFMediaType *type)
 
static int mf_choose_input_type (AVCodecContext *avctx)
 
static int mf_negotiate_types (AVCodecContext *avctx)
 
static int mf_unlock_async (AVCodecContext *avctx)
 
static int mf_create (void *log, IMFTransform **mft, const AVCodec *codec, int use_hw)
 
static int mf_init (AVCodecContext *avctx)
 
static int mf_close (AVCodecContext *avctx)
 
 MF_ENCODER (AUDIO, aac, AAC, NULL, AFMTS)
 
 MF_ENCODER (AUDIO, ac3, AC3, NULL, AFMTS)
 
 MF_ENCODER (AUDIO, mp3, MP3, NULL, AFMTS)
 
 MF_ENCODER (VIDEO, h264, H264, venc_opts, VFMTS)
 
 MF_ENCODER (VIDEO, hevc, HEVC, venc_opts, VFMTS)
 

Variables

static const AVOption venc_opts []
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 19 of file mfenc.c.

◆ _WIN32_WINNT

#define _WIN32_WINNT   0x0602

Definition at line 22 of file mfenc.c.

◆ MF_TIMEBASE

#define MF_TIMEBASE   (AVRational){1, 10000000}

Definition at line 58 of file mfenc.c.

◆ MF_INVALID_TIME

#define MF_INVALID_TIME   AV_NOPTS_VALUE

Definition at line 60 of file mfenc.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(MFContext, x)

Definition at line 1146 of file mfenc.c.

◆ MF_ENCODER

#define MF_ENCODER (   MEDIATYPE,
  NAME,
  ID,
  OPTS,
  EXTRA 
)
Value:
static const AVClass ff_ ## NAME ## _mf_encoder_class = { \
.class_name = #NAME "_mf", \
.item_name = av_default_item_name, \
.option = OPTS, \
.version = LIBAVUTIL_VERSION_INT, \
}; \
const AVCodec ff_ ## NAME ## _mf_encoder = { \
.priv_class = &ff_ ## NAME ## _mf_encoder_class, \
.name = #NAME "_mf", \
.long_name = NULL_IF_CONFIG_SMALL(#ID " via MediaFoundation"), \
.type = AVMEDIA_TYPE_ ## MEDIATYPE, \
.id = AV_CODEC_ID_ ## ID, \
.priv_data_size = sizeof(MFContext), \
.init = mf_init, \
.close = mf_close, \
.receive_packet = mf_receive_packet, \
EXTRA \
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | \
};

Definition at line 1148 of file mfenc.c.

◆ AFMTS

#define AFMTS
Value:
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, \
AV_SAMPLE_FMT_NONE },

Definition at line 1172 of file mfenc.c.

◆ VE

Definition at line 1180 of file mfenc.c.

◆ VFMTS

#define VFMTS
Value:
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, \
AV_PIX_FMT_YUV420P, \
AV_PIX_FMT_NONE },

Definition at line 1207 of file mfenc.c.

Function Documentation

◆ mf_choose_output_type()

static int mf_choose_output_type ( AVCodecContext avctx)
static

Definition at line 728 of file mfenc.c.

Referenced by mf_negotiate_types(), and mf_receive_sample().

◆ mf_setup_context()

static int mf_setup_context ( AVCodecContext avctx)
static

Definition at line 932 of file mfenc.c.

Referenced by mf_init(), and mf_receive_sample().

◆ mf_wait_events()

static int mf_wait_events ( AVCodecContext avctx)
static

Definition at line 62 of file mfenc.c.

Referenced by mf_receive_sample(), and mf_send_sample().

◆ mf_get_tb()

static AVRational mf_get_tb ( AVCodecContext avctx)
static

Definition at line 101 of file mfenc.c.

Referenced by mf_from_mf_time(), and mf_to_mf_time().

◆ mf_to_mf_time()

static LONGLONG mf_to_mf_time ( AVCodecContext avctx,
int64_t  av_pts 
)
static

Definition at line 110 of file mfenc.c.

Referenced by mf_a_avframe_to_sample(), mf_sample_set_pts(), and mf_v_avframe_to_sample().

◆ mf_sample_set_pts()

static void mf_sample_set_pts ( AVCodecContext avctx,
IMFSample *  sample,
int64_t  av_pts 
)
static

Definition at line 117 of file mfenc.c.

Referenced by mf_avframe_to_sample().

◆ mf_from_mf_time()

static int64_t mf_from_mf_time ( AVCodecContext avctx,
LONGLONG  stime 
)
static

Definition at line 124 of file mfenc.c.

Referenced by mf_sample_get_pts(), and mf_sample_to_avpacket().

◆ mf_sample_get_pts()

static int64_t mf_sample_get_pts ( AVCodecContext avctx,
IMFSample *  sample 
)
static

Definition at line 129 of file mfenc.c.

Referenced by mf_sample_to_avpacket().

◆ mf_enca_output_type_get()

static int mf_enca_output_type_get ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 138 of file mfenc.c.

Referenced by mf_output_type_get().

◆ mf_encv_output_type_get()

static int mf_encv_output_type_get ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 178 of file mfenc.c.

Referenced by mf_output_type_get().

◆ mf_output_type_get()

static int mf_output_type_get ( AVCodecContext avctx)
static

Definition at line 201 of file mfenc.c.

Referenced by mf_init(), and mf_setup_context().

◆ mf_sample_to_avpacket()

static int mf_sample_to_avpacket ( AVCodecContext avctx,
IMFSample *  sample,
AVPacket avpkt 
)
static

Definition at line 231 of file mfenc.c.

Referenced by mf_receive_packet().

◆ mf_a_avframe_to_sample()

static IMFSample* mf_a_avframe_to_sample ( AVCodecContext avctx,
const AVFrame frame 
)
static

Definition at line 286 of file mfenc.c.

Referenced by mf_avframe_to_sample().

◆ mf_v_avframe_to_sample()

static IMFSample* mf_v_avframe_to_sample ( AVCodecContext avctx,
const AVFrame frame 
)
static

Definition at line 302 of file mfenc.c.

Referenced by mf_avframe_to_sample().

◆ mf_avframe_to_sample()

static IMFSample* mf_avframe_to_sample ( AVCodecContext avctx,
const AVFrame frame 
)
static

Definition at line 348 of file mfenc.c.

Referenced by mf_receive_packet().

◆ mf_send_sample()

static int mf_send_sample ( AVCodecContext avctx,
IMFSample *  sample 
)
static

Definition at line 365 of file mfenc.c.

Referenced by mf_receive_packet().

◆ mf_receive_sample()

static int mf_receive_sample ( AVCodecContext avctx,
IMFSample **  out_sample 
)
static

Definition at line 403 of file mfenc.c.

Referenced by mf_receive_packet().

◆ mf_receive_packet()

static int mf_receive_packet ( AVCodecContext avctx,
AVPacket avpkt 
)
static

Definition at line 483 of file mfenc.c.

◆ mf_enca_output_score()

static int64_t mf_enca_output_score ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 528 of file mfenc.c.

Referenced by mf_choose_output_type().

◆ mf_enca_output_adjust()

static int mf_enca_output_adjust ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 568 of file mfenc.c.

Referenced by mf_choose_output_type().

◆ mf_enca_input_score()

static int64_t mf_enca_input_score ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 578 of file mfenc.c.

Referenced by mf_choose_input_type().

◆ mf_enca_input_adjust()

static int mf_enca_input_adjust ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 602 of file mfenc.c.

Referenced by mf_choose_input_type().

◆ mf_encv_output_score()

static int64_t mf_encv_output_score ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 628 of file mfenc.c.

Referenced by mf_choose_output_type().

◆ mf_encv_output_adjust()

static int mf_encv_output_adjust ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 644 of file mfenc.c.

Referenced by mf_choose_output_type().

◆ mf_encv_input_score()

static int64_t mf_encv_input_score ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 706 of file mfenc.c.

Referenced by mf_choose_input_type().

◆ mf_encv_input_adjust()

static int mf_encv_input_adjust ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 715 of file mfenc.c.

Referenced by mf_choose_input_type().

◆ mf_choose_input_type()

static int mf_choose_input_type ( AVCodecContext avctx)
static

Definition at line 817 of file mfenc.c.

Referenced by mf_negotiate_types().

◆ mf_negotiate_types()

static int mf_negotiate_types ( AVCodecContext avctx)
static

Definition at line 905 of file mfenc.c.

Referenced by mf_init().

◆ mf_unlock_async()

static int mf_unlock_async ( AVCodecContext avctx)
static

Definition at line 960 of file mfenc.c.

Referenced by mf_init().

◆ mf_create()

static int mf_create ( void *  log,
IMFTransform **  mft,
const AVCodec codec,
int  use_hw 
)
static

Definition at line 1009 of file mfenc.c.

Referenced by mf_init().

◆ mf_init()

static int mf_init ( AVCodecContext avctx)
static

Definition at line 1038 of file mfenc.c.

◆ mf_close()

static int mf_close ( AVCodecContext avctx)
static

Definition at line 1126 of file mfenc.c.

◆ MF_ENCODER() [1/5]

MF_ENCODER ( AUDIO  ,
aac  ,
AAC  ,
NULL  ,
AFMTS   
)

◆ MF_ENCODER() [2/5]

MF_ENCODER ( AUDIO  ,
ac3  ,
AC3  ,
NULL  ,
AFMTS   
)

◆ MF_ENCODER() [3/5]

MF_ENCODER ( AUDIO  ,
mp3  ,
MP3  ,
NULL  ,
AFMTS   
)

◆ MF_ENCODER() [4/5]

MF_ENCODER ( VIDEO  ,
h264  ,
H264  ,
venc_opts  ,
VFMTS   
)

◆ MF_ENCODER() [5/5]

MF_ENCODER ( VIDEO  ,
hevc  ,
HEVC  ,
venc_opts  ,
VFMTS   
)

Variable Documentation

◆ venc_opts

const AVOption venc_opts[]
static
Initial value:
= {
{"rate_control", "Select rate control mode", OFFSET(opt_enc_rc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "rate_control"},
{ "default", "Default mode", 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, VE, "rate_control"},
{ "cbr", "CBR mode", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVEncCommonRateControlMode_CBR}, 0, 0, VE, "rate_control"},
{ "pc_vbr", "Peak constrained VBR mode", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVEncCommonRateControlMode_PeakConstrainedVBR}, 0, 0, VE, "rate_control"},
{ "u_vbr", "Unconstrained VBR mode", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVEncCommonRateControlMode_UnconstrainedVBR}, 0, 0, VE, "rate_control"},
{ "quality", "Quality mode", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVEncCommonRateControlMode_Quality}, 0, 0, VE, "rate_control" },
{ "ld_vbr", "Low delay VBR mode", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVEncCommonRateControlMode_LowDelayVBR}, 0, 0, VE, "rate_control"},
{ "g_vbr", "Global VBR mode", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVEncCommonRateControlMode_GlobalVBR}, 0, 0, VE, "rate_control" },
{ "gld_vbr", "Global low delay VBR mode", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVEncCommonRateControlMode_GlobalLowDelayVBR}, 0, 0, VE, "rate_control"},
{"scenario", "Select usage scenario", OFFSET(opt_enc_scenario), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "scenario"},
{ "default", "Default scenario", 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, VE, "scenario"},
{ "display_remoting", "Display remoting", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVScenarioInfo_DisplayRemoting}, 0, 0, VE, "scenario"},
{ "video_conference", "Video conference", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVScenarioInfo_VideoConference}, 0, 0, VE, "scenario"},
{ "archive", "Archive", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVScenarioInfo_Archive}, 0, 0, VE, "scenario"},
{ "live_streaming", "Live streaming", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVScenarioInfo_LiveStreaming}, 0, 0, VE, "scenario"},
{ "camera_record", "Camera record", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVScenarioInfo_CameraRecord}, 0, 0, VE, "scenario"},
{ "display_remoting_with_feature_map", "Display remoting with feature map", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVScenarioInfo_DisplayRemotingWithFeatureMap}, 0, 0, VE, "scenario"},
{"quality", "Quality", OFFSET(opt_enc_quality), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100, VE},
{"hw_encoding", "Force hardware encoding", OFFSET(opt_enc_hw), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VE},
{NULL}
}

Definition at line 1181 of file mfenc.c.

AVCodec
AVCodec.
Definition: codec.h:197
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:41
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
AVCodec::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: codec.h:223
ff_eAVEncCommonRateControlMode_Quality
@ ff_eAVEncCommonRateControlMode_Quality
Definition: mf_utils.h:107
ff_eAVEncCommonRateControlMode_CBR
@ ff_eAVEncCommonRateControlMode_CBR
Definition: mf_utils.h:104
OFFSET
#define OFFSET(x)
Definition: mfenc.c:1146
mf_receive_packet
static int mf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Definition: mfenc.c:483
ff_eAVEncCommonRateControlMode_GlobalVBR
@ ff_eAVEncCommonRateControlMode_GlobalVBR
Definition: mf_utils.h:109
ff_eAVScenarioInfo_LiveStreaming
@ ff_eAVScenarioInfo_LiveStreaming
Definition: mf_utils.h:118
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
ff_eAVEncCommonRateControlMode_PeakConstrainedVBR
@ ff_eAVEncCommonRateControlMode_PeakConstrainedVBR
Definition: mf_utils.h:105
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
ff_eAVScenarioInfo_Archive
@ ff_eAVScenarioInfo_Archive
Definition: mf_utils.h:117
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
ff_eAVScenarioInfo_DisplayRemoting
@ ff_eAVScenarioInfo_DisplayRemoting
Definition: mf_utils.h:115
ff_eAVEncCommonRateControlMode_UnconstrainedVBR
@ ff_eAVEncCommonRateControlMode_UnconstrainedVBR
Definition: mf_utils.h:106
ff_eAVScenarioInfo_DisplayRemotingWithFeatureMap
@ ff_eAVScenarioInfo_DisplayRemotingWithFeatureMap
Definition: mf_utils.h:120
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:49
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
VE
#define VE
Definition: mfenc.c:1180
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:61
MFContext
Definition: mfenc.c:32
AV_PIX_FMT_NV12
@ 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...
Definition: pixfmt.h:89
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
mf_init
static int mf_init(AVCodecContext *avctx)
Definition: mfenc.c:1038
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
mf_close
static int mf_close(AVCodecContext *avctx)
Definition: mfenc.c:1126
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:77
ff_eAVScenarioInfo_CameraRecord
@ ff_eAVScenarioInfo_CameraRecord
Definition: mf_utils.h:119
ff_eAVScenarioInfo_VideoConference
@ ff_eAVScenarioInfo_VideoConference
Definition: mf_utils.h:116
AV_CODEC_CAP_HYBRID
#define AV_CODEC_CAP_HYBRID
Codec is potentially backed by a hardware implementation, but not necessarily.
Definition: codec.h:164
ID
#define ID(x)
Definition: cast5.c:29
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
ff_eAVEncCommonRateControlMode_GlobalLowDelayVBR
@ ff_eAVEncCommonRateControlMode_GlobalLowDelayVBR
Definition: mf_utils.h:110
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
ff_eAVEncCommonRateControlMode_LowDelayVBR
@ ff_eAVEncCommonRateControlMode_LowDelayVBR
Definition: mf_utils.h:108