Skip to content

Commit

Permalink
Merge pull request jellyfin#28 from nyanmisaka/amfupdate
Browse files Browse the repository at this point in the history
Update AMF encoder to support Linux
  • Loading branch information
JustAMan authored Feb 27, 2020
2 parents 8261463 + 6b2eb2c commit 4ea47bf
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 4 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
jellyfin-ffmpeg (4.2.1-6) unstable; urgency=medium

* Update AMD AMF files to support Linux

-- nyanmisaka <[email protected]> Tue, 25 Feb 2020 17:33:28 +0800

jellyfin-ffmpeg (4.2.1-5) unstable; urgency=medium

* Add support for Debian Bullseye (testing)
Expand Down
100 changes: 100 additions & 0 deletions debian/patches/0002-Update-AMF-files-to-support-Linux.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Index: jellyfin-ffmpeg/libavcodec/amfenc.c
===================================================================
--- jellyfin-ffmpeg.orig/libavcodec/amfenc.c
+++ jellyfin-ffmpeg/libavcodec/amfenc.c
@@ -213,6 +213,7 @@ static int amf_init_from_dxva2_device(AV
static int amf_init_context(AVCodecContext *avctx)
{
AmfContext *ctx = avctx->priv_data;
+ AMFContext1 *context1 = NULL;
AMF_RESULT res;
av_unused int ret;

@@ -311,8 +312,20 @@ static int amf_init_context(AVCodecConte
if (res == AMF_OK) {
av_log(avctx, AV_LOG_VERBOSE, "AMF initialisation succeeded via D3D9.\n");
} else {
- av_log(avctx, AV_LOG_ERROR, "AMF initialisation failed via D3D9: error %d.\n", res);
- return AVERROR(ENOSYS);
+ AMFGuid guid = IID_AMFContext1();
+ res = ctx->context->pVtbl->QueryInterface(ctx->context, &guid, (void**)&context1);
+ AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "CreateContext1() failed with error %d\n", res);
+
+ res = context1->pVtbl->InitVulkan(context1, NULL);
+ context1->pVtbl->Release(context1);
+ if (res != AMF_OK) {
+ if (res == AMF_NOT_SUPPORTED)
+ av_log(avctx, AV_LOG_ERROR, "AMF via Vulkan is not supported on the given device.\n");
+ else
+ av_log(avctx, AV_LOG_ERROR, "AMF failed to initialise on the given Vulkan device: %d.\n", res);
+ return AVERROR(ENOSYS);
+ }
+ av_log(avctx, AV_LOG_VERBOSE, "AMF initialisation succeeded via Vulkan.\n");
}
}
}
@@ -438,7 +451,7 @@ static int amf_copy_buffer(AVCodecContex
int64_t timestamp = AV_NOPTS_VALUE;
int64_t size = buffer->pVtbl->GetSize(buffer);

- if ((ret = ff_alloc_packet2(avctx, pkt, size, 0)) < 0) {
+ if ((ret = av_new_packet(pkt, size)) < 0) {
return ret;
}
memcpy(pkt->data, buffer->pVtbl->GetNative(buffer), size);
Index: jellyfin-ffmpeg/libavcodec/amfenc_h264.c
===================================================================
--- jellyfin-ffmpeg.orig/libavcodec/amfenc_h264.c
+++ jellyfin-ffmpeg/libavcodec/amfenc_h264.c
@@ -366,6 +366,7 @@ static const AVCodecDefault defaults[] =
{ "b", "2M" },
{ "g", "250" },
{ "slices", "1" },
+ { "flags", "+loop"},
{ NULL },
};

Index: jellyfin-ffmpeg/libavcodec/amfenc_hevc.c
===================================================================
--- jellyfin-ffmpeg.orig/libavcodec/amfenc_hevc.c
+++ jellyfin-ffmpeg/libavcodec/amfenc_hevc.c
@@ -69,7 +69,7 @@ static const AVOption options[] = {
{ "gop", "", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_HEADER_INSERTION_MODE_GOP_ALIGNED }, 0, 0, VE, "hdrmode" },
{ "idr", "", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_HEADER_INSERTION_MODE_IDR_ALIGNED }, 0, 0, VE, "hdrmode" },

- { "gops_per_idr", "GOPs per IDR 0-no IDR will be inserted", OFFSET(gops_per_idr), AV_OPT_TYPE_INT, { .i64 = 60 }, 0, INT_MAX, VE },
+ { "gops_per_idr", "GOPs per IDR 0-no IDR will be inserted", OFFSET(gops_per_idr), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, VE },
{ "preanalysis", "Enable preanalysis", OFFSET(preanalysis), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE},
{ "vbaq", "Enable VBAQ", OFFSET(enable_vbaq), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE},
{ "enforce_hrd", "Enforce HRD", OFFSET(enforce_hrd), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE},
@@ -136,7 +136,7 @@ static av_cold int amf_encode_init_hevc(
AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_TIER, ctx->tier);

profile_level = avctx->level;
- if (profile_level == 0) {
+ if (profile_level == FF_LEVEL_UNKNOWN) {
profile_level = ctx->level;
}
if (profile_level != 0) {
@@ -144,7 +144,7 @@ static av_cold int amf_encode_init_hevc(
}
AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QUALITY_PRESET, ctx->quality);
// Maximum Reference Frames
- if (avctx->refs != 0) {
+ if (avctx->refs != -1) {
AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_NUM_REFRAMES, avctx->refs);
}
// Aspect Ratio
@@ -254,10 +254,10 @@ static av_cold int amf_encode_init_hevc(
}

if (ctx->qp_p != -1) {
- AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QP_I, ctx->qp_p);
+ AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QP_P, ctx->qp_p);
}
if (ctx->qp_i != -1) {
- AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QP_P, ctx->qp_i);
+ AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QP_I, ctx->qp_i);
}
AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_SKIP_FRAME_ENABLE, ctx->skip_frame);

1 change: 1 addition & 0 deletions debian/patches/series
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
0001_fix-segment-muxer.patch
0002-Update-AMF-files-to-support-Linux.patch
10 changes: 6 additions & 4 deletions docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ popd

# Download and setup AMD AMF headers from AMD official github repo
# https://www.ffmpeg.org/general.html#AMD-AMF_002fVCE
wget -O amf_headers.zip https://github.com/GPUOpen-LibrariesAndSDKs/AMF/archive/master.zip
unzip amf_headers.zip -d amf_headers
cd "amf_headers/AMF-master/amf/public/include/"
mkdir -p "/usr/include/AMF/" && cp -r * "/usr/include/AMF/"
apt-get update
yes | apt-get install subversion
svn checkout https://github.com/GPUOpen-LibrariesAndSDKs/AMF/trunk/amf/public/include
pushd include
mkdir -p /usr/include/AMF && mv * /usr/include/AMF
popd

# Move to source directory
pushd ${SOURCE_DIR}
Expand Down

0 comments on commit 4ea47bf

Please sign in to comment.