Commit 9ea6607d authored by Mikhail Mironov's avatar Mikhail Mironov Committed by Mark Thompson

Add HW H.264 and HEVC encoding for AMD GPUs based on AMF SDK

Requires AMF headers for at least version 1.4.4.1.
Signed-off-by: 's avatarMikhail Mironov <mikhail.mironov@amd.com>
Signed-off-by: 's avatarMark Thompson <sw@jkqxz.net>
parent 23db3a1a
......@@ -22,6 +22,7 @@ version <next>:
- video normalize filter
- audio lv2 wrapper filter
- VAAPI VP8 decoding
- AMD AMF H.264 and HEVC encoders
version 3.4:
......
......@@ -304,6 +304,7 @@ External library support:
--disable-zlib disable zlib [autodetect]
The following libraries provide various hardware acceleration features:
--disable-amf disable AMF video encoding code [autodetect]
--disable-audiotoolbox disable Apple AudioToolbox code [autodetect]
--disable-cuda disable dynamically linked Nvidia CUDA code [autodetect]
--enable-cuda-sdk enable CUDA features that require the CUDA SDK [no]
......@@ -1640,6 +1641,7 @@ EXTERNAL_LIBRARY_LIST="
"
HWACCEL_AUTODETECT_LIBRARY_LIST="
amf
audiotoolbox
crystalhd
cuda
......@@ -2783,12 +2785,14 @@ scale_npp_filter_deps="cuda libnpp"
scale_cuda_filter_deps="cuda_sdk"
thumbnail_cuda_filter_deps="cuda_sdk"
amf_deps_any="libdl LoadLibrary"
nvenc_deps="cuda"
nvenc_deps_any="libdl LoadLibrary"
nvenc_encoder_deps="nvenc"
h263_v4l2m2m_decoder_deps="v4l2_m2m h263_v4l2_m2m"
h263_v4l2m2m_encoder_deps="v4l2_m2m h263_v4l2_m2m"
h264_amf_encoder_deps="amf"
h264_crystalhd_decoder_select="crystalhd h264_mp4toannexb_bsf h264_parser"
h264_cuvid_decoder_deps="cuvid"
h264_cuvid_decoder_select="h264_mp4toannexb_bsf"
......@@ -2805,6 +2809,7 @@ h264_vaapi_encoder_deps="VAEncPictureParameterBufferH264"
h264_vaapi_encoder_select="cbs_h264 vaapi_encode"
h264_v4l2m2m_decoder_deps="v4l2_m2m h264_v4l2_m2m"
h264_v4l2m2m_encoder_deps="v4l2_m2m h264_v4l2_m2m"
hevc_amf_encoder_deps="amf"
hevc_cuvid_decoder_deps="cuvid"
hevc_cuvid_decoder_select="hevc_mp4toannexb_bsf"
hevc_mediacodec_decoder_deps="mediacodec"
......@@ -6196,6 +6201,11 @@ void f(void) { struct { const GUID guid; } s[] = { { NV_ENC_PRESET_HQ_GUID } };
int main(void) { return 0; }
EOF
enabled amf &&
check_cpp_condition "AMF/core/Version.h" \
"(AMF_VERSION_MAJOR << 48 | AMF_VERSION_MINOR << 32 | AMF_VERSION_RELEASE << 16 | AMF_VERSION_BUILD_NUM) >= 0x0001000400040001" ||
disable amf
# Funny iconv installations are not unusual, so check it after all flags have been set
if enabled libc_iconv; then
check_func_headers iconv.h iconv
......
......@@ -55,6 +55,7 @@ OBJS = ac3_parser.o \
OBJS-$(CONFIG_AANDCTTABLES) += aandcttab.o
OBJS-$(CONFIG_AC3DSP) += ac3dsp.o ac3.o ac3tab.o
OBJS-$(CONFIG_ADTS_HEADER) += adts_header.o mpeg4audio.o
OBJS-$(CONFIG_AMF) += amfenc.o
OBJS-$(CONFIG_AUDIO_FRAME_QUEUE) += audio_frame_queue.o
OBJS-$(CONFIG_AUDIODSP) += audiodsp.o
OBJS-$(CONFIG_BLOCKDSP) += blockdsp.o
......@@ -337,6 +338,7 @@ OBJS-$(CONFIG_H264_DECODER) += h264dec.o h264_cabac.o h264_cavlc.o \
h264_mb.o h264_picture.o \
h264_refs.o h264_sei.o \
h264_slice.o h264data.o
OBJS-$(CONFIG_H264_AMF_ENCODER) += amfenc_h264.o
OBJS-$(CONFIG_H264_CUVID_DECODER) += cuviddec.o
OBJS-$(CONFIG_H264_MEDIACODEC_DECODER) += mediacodecdec.o
OBJS-$(CONFIG_H264_MMAL_DECODER) += mmaldec.o
......@@ -356,6 +358,7 @@ OBJS-$(CONFIG_HAP_ENCODER) += hapenc.o hap.o
OBJS-$(CONFIG_HEVC_DECODER) += hevcdec.o hevc_mvs.o \
hevc_cabac.o hevc_refs.o hevcpred.o \
hevcdsp.o hevc_filter.o hevc_data.o
OBJS-$(CONFIG_HEVC_AMF_ENCODER) += amfenc_hevc.o
OBJS-$(CONFIG_HEVC_CUVID_DECODER) += cuviddec.o
OBJS-$(CONFIG_HEVC_MEDIACODEC_DECODER) += mediacodecdec.o
OBJS-$(CONFIG_HEVC_NVENC_ENCODER) += nvenc_hevc.o
......@@ -1065,6 +1068,7 @@ SKIPHEADERS += %_tablegen.h \
aacenc_quantization_misc.h \
$(ARCH)/vp56_arith.h \
SKIPHEADERS-$(CONFIG_AMF) += amfenc.h
SKIPHEADERS-$(CONFIG_D3D11VA) += d3d11va.h dxva2_internal.h
SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h
SKIPHEADERS-$(CONFIG_JNI) += ffjni.h
......
......@@ -576,6 +576,7 @@ static void register_all(void)
* above is available */
REGISTER_ENCODER(H263_V4L2M2M, h263_v4l2m2m);
REGISTER_ENCDEC (LIBOPENH264, libopenh264);
REGISTER_ENCODER(H264_AMF, h264_amf);
REGISTER_DECODER(H264_CUVID, h264_cuvid);
REGISTER_ENCODER(H264_NVENC, h264_nvenc);
REGISTER_ENCODER(H264_OMX, h264_omx);
......@@ -588,6 +589,7 @@ static void register_all(void)
REGISTER_ENCODER(NVENC_H264, nvenc_h264);
REGISTER_ENCODER(NVENC_HEVC, nvenc_hevc);
#endif
REGISTER_ENCODER(HEVC_AMF, hevc_amf);
REGISTER_DECODER(HEVC_CUVID, hevc_cuvid);
REGISTER_DECODER(HEVC_MEDIACODEC, hevc_mediacodec);
REGISTER_ENCODER(HEVC_NVENC, hevc_nvenc);
......
This diff is collapsed.
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_AMFENC_H
#define AVCODEC_AMFENC_H
#include <AMF/core/Factory.h>
#include <AMF/components/VideoEncoderVCE.h>
#include <AMF/components/VideoEncoderHEVC.h>
#include "libavutil/fifo.h"
#include "config.h"
#include "avcodec.h"
/**
* AMF trace writer callback class
* Used to capture all AMF logging
*/
typedef struct AmfTraceWriter {
AMFTraceWriterVtbl *vtbl;
AVCodecContext *avctx;
} AmfTraceWriter;
/**
* AMF encoder context
*/
typedef struct AmfContext {
AVClass *avclass;
// access to AMF runtime
amf_handle library; ///< handle to DLL library
AMFFactory *factory; ///< pointer to AMF factory
AMFDebug *debug; ///< pointer to AMF debug interface
AMFTrace *trace; ///< pointer to AMF trace interface
amf_uint64 version; ///< version of AMF runtime
AmfTraceWriter tracer; ///< AMF writer registered with AMF
AMFContext *context; ///< AMF context
//encoder
AMFComponent *encoder; ///< AMF encoder object
amf_bool eof; ///< flag indicating EOF happened
AMF_SURFACE_FORMAT format; ///< AMF surface format
AVBufferRef *hw_device_ctx; ///< pointer to HW accelerator (decoder)
AVBufferRef *hw_frames_ctx; ///< pointer to HW accelerator (frame allocator)
// helpers to handle async calls
int delayed_drain;
AMFSurface *delayed_surface;
AVFrame *delayed_frame;
// shift dts back by max_b_frames in timing
AVFifoBuffer *timestamp_list;
int64_t dts_delay;
// common encoder option options
int log_to_dbg;
// Static options, have to be set before Init() call
int usage;
int profile;
int level;
int preanalysis;
int quality;
int b_frame_delta_qp;
int ref_b_frame_delta_qp;
// Dynamic options, can be set after Init() call
int rate_control_mode;
int enforce_hrd;
int filler_data;
int enable_vbaq;
int skip_frame;
int qp_i;
int qp_p;
int qp_b;
int max_au_size;
int header_spacing;
int b_frame_ref;
int intra_refresh_mb;
int coding_mode;
int me_half_pel;
int me_quarter_pel;
int aud;
// HEVC - specific options
int gops_per_idr;
int header_insertion_mode;
int min_qp_i;
int max_qp_i;
int min_qp_p;
int max_qp_p;
int tier;
} AmfContext;
/**
* Common encoder initization function
*/
int ff_amf_encode_init(AVCodecContext *avctx);
/**
* Common encoder termination function
*/
int ff_amf_encode_close(AVCodecContext *avctx);
/**
* Ecoding one frame - common function for all AMF encoders
*/
int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame);
int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
/**
* Supported formats
*/
extern const enum AVPixelFormat ff_amf_pix_fmts[];
/**
* Error handling helper
*/
#define AMF_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
if (!(exp)) { \
av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
return ret_value; \
}
#endif //AVCODEC_AMFENC_H
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment