FFmpeg
amfenc.h
Go to the documentation of this file.
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef AVCODEC_AMFENC_H
20 #define AVCODEC_AMFENC_H
21 
22 #include <AMF/core/Factory.h>
23 
24 #include <AMF/components/ColorSpace.h>
25 #include <AMF/components/VideoEncoderVCE.h>
26 #include <AMF/components/VideoEncoderHEVC.h>
27 #include <AMF/components/VideoEncoderAV1.h>
28 
29 #include "libavutil/fifo.h"
30 
31 #include "avcodec.h"
32 #include "hwconfig.h"
33 
34 #define MAX_LOOKAHEAD_DEPTH 41
35 
36 /**
37 * AMF trace writer callback class
38 * Used to capture all AMF logging
39 */
40 
41 typedef struct AmfTraceWriter {
42  AMFTraceWriterVtbl *vtbl;
45 
46 /**
47 * AMF encoder context
48 */
49 
50 typedef struct AmfContext {
52  // access to AMF runtime
53  amf_handle library; ///< handle to DLL library
54  AMFFactory *factory; ///< pointer to AMF factory
55  AMFDebug *debug; ///< pointer to AMF debug interface
56  AMFTrace *trace; ///< pointer to AMF trace interface
57 
58  amf_uint64 version; ///< version of AMF runtime
59  AmfTraceWriter tracer; ///< AMF writer registered with AMF
60  AMFContext *context; ///< AMF context
61  //encoder
62  AMFComponent *encoder; ///< AMF encoder object
63  amf_bool eof; ///< flag indicating EOF happened
64  AMF_SURFACE_FORMAT format; ///< AMF surface format
65 
66  AVBufferRef *hw_device_ctx; ///< pointer to HW accelerator (decoder)
67  AVBufferRef *hw_frames_ctx; ///< pointer to HW accelerator (frame allocator)
68 
72 
73  // helpers to handle async calls
75  AMFSurface *delayed_surface;
77 
78  // shift dts back by max_b_frames in timing
82  amf_bool use_b_frame;
83 
84  // common encoder option options
85 
87 
88  // Static options, have to be set before Init() call
89  int usage;
90  int profile;
91  int level;
92  int latency;
93  int preencode;
94  int quality;
97 
98  // Dynamic options, can be set after Init() call
99 
105  int qp_i;
106  int qp_p;
107  int qp_b;
115  int aud;
121 
122  // HEVC - specific options
123 
126  int min_qp_i;
127  int max_qp_i;
128  int min_qp_p;
129  int max_qp_p;
130  int tier;
131 
132  // AV1 - specific options
133 
134  enum AMF_VIDEO_ENCODER_AV1_ALIGNMENT_MODE_ENUM align;
135  enum AMF_VIDEO_ENCODER_AV1_AQ_MODE_ENUM aq_mode;
136 
137  // Preanalysis - specific options
138 
149  int pa_ltr;
155 
156 
157 } AmfContext;
158 
159 extern const AVCodecHWConfigInternal *const ff_amfenc_hw_configs[];
160 
161 /**
162 * Common encoder initization function
163 */
165 /**
166 * Common encoder termination function
167 */
169 
170 /**
171 * Ecoding one frame - common function for all AMF encoders
172 */
173 int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
174 
175 /**
176 * Supported formats
177 */
178 extern const enum AVPixelFormat ff_amf_pix_fmts[];
179 
181 
182 /**
183 * Error handling helper
184 */
185 #define AMF_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
186  if (!(exp)) { \
187  av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
188  return ret_value; \
189  }
190 
191 #endif //AVCODEC_AMFENC_H
AmfContext::header_spacing
int header_spacing
Definition: amfenc.h:109
hwconfig.h
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AmfContext::factory
AMFFactory * factory
pointer to AMF factory
Definition: amfenc.h:54
AmfContext::hwsurfaces_in_queue_max
int hwsurfaces_in_queue_max
Definition: amfenc.h:70
AmfContext::trace
AMFTrace * trace
pointer to AMF trace interface
Definition: amfenc.h:56
AmfContext::profile
int profile
Definition: amfenc.h:90
AmfContext::qp_i
int qp_i
Definition: amfenc.h:105
ff_amf_receive_packet
int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Ecoding one frame - common function for all AMF encoders.
Definition: amfenc.c:644
int64_t
long long int64_t
Definition: coverity.c:34
AmfContext::ref_b_frame_delta_qp
int ref_b_frame_delta_qp
Definition: amfenc.h:96
AmfContext::pa_paq_mode
int pa_paq_mode
Definition: amfenc.h:151
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
AmfContext::quality
int quality
Definition: amfenc.h:94
AmfContext::qvbr_quality_level
int qvbr_quality_level
Definition: amfenc.h:118
AmfContext::aq_mode
enum AMF_VIDEO_ENCODER_AV1_AQ_MODE_ENUM aq_mode
Definition: amfenc.h:135
AmfTraceWriter::vtbl
AMFTraceWriterVtbl * vtbl
Definition: amfenc.h:42
AmfContext::library
amf_handle library
handle to DLL library
Definition: amfenc.h:53
AmfContext::qp_b
int qp_b
Definition: amfenc.h:107
AmfContext::enable_vbaq
int enable_vbaq
Definition: amfenc.h:103
AmfContext::level
int level
Definition: amfenc.h:91
AmfContext::skip_frame
int skip_frame
Definition: amfenc.h:104
AmfContext::delayed_frame
AVFrame * delayed_frame
Definition: amfenc.h:76
fifo.h
AmfContext::pa_max_qp
int pa_max_qp
Definition: amfenc.h:146
AmfContext::pa_high_motion_quality_boost_mode
int pa_high_motion_quality_boost_mode
Definition: amfenc.h:153
AmfContext::enforce_hrd
int enforce_hrd
Definition: amfenc.h:101
ff_amfenc_hw_configs
const AVCodecHWConfigInternal *const ff_amfenc_hw_configs[]
Definition: amfenc.c:970
AmfContext::delayed_surface
AMFSurface * delayed_surface
Definition: amfenc.h:75
AmfContext::rate_control_mode
int rate_control_mode
Definition: amfenc.h:100
AmfContext::pa_ltr
int pa_ltr
Definition: amfenc.h:149
AmfContext::use_b_frame
amf_bool use_b_frame
Definition: amfenc.h:82
AmfContext::preanalysis
int preanalysis
Definition: amfenc.h:139
AmfContext::latency
int latency
Definition: amfenc.h:92
AmfContext::filler_data
int filler_data
Definition: amfenc.h:102
AmfContext::avclass
AVClass * avclass
Definition: amfenc.h:51
AmfContext::debug
AMFDebug * debug
pointer to AMF debug interface
Definition: amfenc.h:55
AmfContext::pa_lookahead_buffer_depth
int pa_lookahead_buffer_depth
Definition: amfenc.h:150
AmfContext::min_qp_i
int min_qp_i
Definition: amfenc.h:126
AmfContext::pa_caq_strength
int pa_caq_strength
Definition: amfenc.h:147
AmfContext::min_qp_p
int min_qp_p
Definition: amfenc.h:128
AmfTraceWriter::avctx
AVCodecContext * avctx
Definition: amfenc.h:43
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
AmfContext::hw_frames_ctx
AVBufferRef * hw_frames_ctx
pointer to HW accelerator (frame allocator)
Definition: amfenc.h:67
AmfContext::preencode
int preencode
Definition: amfenc.h:93
AmfContext::max_au_size
int max_au_size
Definition: amfenc.h:108
AmfContext::forced_idr
int forced_idr
Definition: amfenc.h:120
AmfContext::timestamp_list
AVFifo * timestamp_list
Definition: amfenc.h:79
AmfContext::submitted_frame
int submitted_frame
Definition: amfenc.h:81
AmfContext::hwsurfaces_in_queue
int hwsurfaces_in_queue
Definition: amfenc.h:69
AmfContext::pa_frame_sad
int pa_frame_sad
Definition: amfenc.h:148
AmfContext::me_half_pel
int me_half_pel
Definition: amfenc.h:113
AmfTraceWriter
AMF trace writer callback class Used to capture all AMF logging.
Definition: amfenc.h:41
AmfContext::format
AMF_SURFACE_FORMAT format
AMF surface format.
Definition: amfenc.h:64
AVFifo
Definition: fifo.c:35
AmfContext::pa_taq_mode
int pa_taq_mode
Definition: amfenc.h:152
AmfContext::pa_static_scene_detection_sensitivity
int pa_static_scene_detection_sensitivity
Definition: amfenc.h:144
AmfContext::pa_static_scene_detection
int pa_static_scene_detection
Definition: amfenc.h:143
AmfContext::query_timeout_supported
int query_timeout_supported
Definition: amfenc.h:71
AVCodecHWConfigInternal
Definition: hwconfig.h:25
AmfContext::dts_delay
int64_t dts_delay
Definition: amfenc.h:80
ff_amf_pix_fmts
enum AVPixelFormat ff_amf_pix_fmts[]
Supported formats.
Definition: amfenc.c:105
AmfContext::usage
int usage
Definition: amfenc.h:89
AmfContext::encoder
AMFComponent * encoder
AMF encoder object.
Definition: amfenc.h:62
AmfContext::pa_scene_change_detection
int pa_scene_change_detection
Definition: amfenc.h:141
AmfContext::coding_mode
int coding_mode
Definition: amfenc.h:112
AmfContext::gops_per_idr
int gops_per_idr
Definition: amfenc.h:124
AmfContext::pa_adaptive_mini_gop
int pa_adaptive_mini_gop
Definition: amfenc.h:154
AmfContext::b_frame_delta_qp
int b_frame_delta_qp
Definition: amfenc.h:95
AmfContext::max_consecutive_b_frames
int max_consecutive_b_frames
Definition: amfenc.h:116
AmfContext::intra_refresh_mb
int intra_refresh_mb
Definition: amfenc.h:111
AmfContext::max_qp_i
int max_qp_i
Definition: amfenc.h:127
ff_amf_encode_close
int ff_amf_encode_close(AVCodecContext *avctx)
Common encoder termination function.
Definition: amfenc.c:434
avcodec.h
AmfContext::max_b_frames
int max_b_frames
Definition: amfenc.h:117
AmfContext::tier
int tier
Definition: amfenc.h:130
AmfContext::me_quarter_pel
int me_quarter_pel
Definition: amfenc.h:114
AmfContext::max_qp_p
int max_qp_p
Definition: amfenc.h:129
AmfContext::align
enum AMF_VIDEO_ENCODER_AV1_ALIGNMENT_MODE_ENUM align
Definition: amfenc.h:134
AVCodecContext
main external API structure.
Definition: avcodec.h:451
AmfContext::header_insertion_mode
int header_insertion_mode
Definition: amfenc.h:125
AmfContext::version
amf_uint64 version
version of AMF runtime
Definition: amfenc.h:58
AmfContext::qp_p
int qp_p
Definition: amfenc.h:106
ff_amf_get_color_profile
int ff_amf_get_color_profile(AVCodecContext *avctx)
Definition: amfenc.c:935
AmfContext::pa_activity_type
int pa_activity_type
Definition: amfenc.h:140
ff_amf_encode_init
int ff_amf_encode_init(AVCodecContext *avctx)
Common encoder initization function.
Definition: amfenc.c:559
AmfContext::log_to_dbg
int log_to_dbg
Definition: amfenc.h:86
AmfContext::aud
int aud
Definition: amfenc.h:115
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AmfContext::hw_high_motion_quality_boost
int hw_high_motion_quality_boost
Definition: amfenc.h:119
AmfContext::eof
amf_bool eof
flag indicating EOF happened
Definition: amfenc.h:63
AVPacket
This structure stores compressed data.
Definition: packet.h:516
AmfContext::hw_device_ctx
AVBufferRef * hw_device_ctx
pointer to HW accelerator (decoder)
Definition: amfenc.h:66
AmfContext::b_frame_ref
int b_frame_ref
Definition: amfenc.h:110
AmfContext
AMF encoder context.
Definition: amfenc.h:50
AmfContext::tracer
AmfTraceWriter tracer
AMF writer registered with AMF.
Definition: amfenc.h:59
AmfContext::pa_initial_qp
int pa_initial_qp
Definition: amfenc.h:145
AmfContext::context
AMFContext * context
AMF context.
Definition: amfenc.h:60
AmfContext::pa_scene_change_detection_sensitivity
int pa_scene_change_detection_sensitivity
Definition: amfenc.h:142
AmfContext::delayed_drain
int delayed_drain
Definition: amfenc.h:74