OpenVisualCloud / SVT-HEVC

SVT HEVC encoder. Scalable Video Technology (SVT) is a software-based video coding technology that is highly optimized for Intel® Xeon® processors. Using the open source SVT-HEVC encoder, it is possible to spread video encoding processing across multiple Intel® Xeon® processors to achieve a real advantage of processing efficiency.
Other
507 stars 169 forks source link

Can't apply patch on FFmpeg 6.0 #641

Closed dpasqualin closed 1 year ago

dpasqualin commented 1 year ago

I tried applying the patch from master on FFmpeg 6.0 but I get an error:

patch -p1 < master-0001-lavc-svt_hevc-add-libsvt-hevc-encoder-wrapper.patch

Hunk #1 succeeded at 291 (offset 3 lines).
Hunk #2 FAILED at 1764.
Hunk #3 FAILED at 3287.
Hunk #4 FAILED at 6492.
3 out of 4 hunks FAILED -- saving rejects to file configure.rej
patching file libavcodec/Makefile
Hunk #1 succeeded at 1128 (offset 65 lines).
patching file libavcodec/allcodecs.c
Hunk #1 FAILED at 772.
1 out of 1 hunk FAILED -- saving rejects to file libavcodec/allcodecs.c.rej
patching file libavcodec/libsvt_hevc.c

Rejected files below:

configure.rej

--- configure
+++ configure
@@ -1764,6 +1765,7 @@ EXTERNAL_LIBRARY_LIST="
     gnutls
     jni
     ladspa
+    libsvthevc
     libaom
     libass
     libbluray
@@ -3287,6 +3289,7 @@ libx264_encoder_select="atsc_a53"
 libx264rgb_encoder_deps="libx264 x264_csp_bgr"
 libx264rgb_encoder_select="libx264_encoder"
 libx265_encoder_deps="libx265"
+libsvt_hevc_encoder_deps="libsvthevc"
 libxavs_encoder_deps="libxavs"
 libxavs2_encoder_deps="libxavs2"
 libxvid_encoder_deps="libxvid"
@@ -6492,6 +6495,7 @@ enabled mmal              && { check_lib mmal interface/mmal/mmal.h mmal_port_co
                                  check_lib mmal interface/mmal/mmal.h mmal_port_connect -lmmal_core -lmmal_util -lmmal_vc_client -lbcm_host; } ||
                                die "ERROR: mmal not found" &&
                                check_func_headers interface/mmal/mmal.h "MMAL_PARAMETER_VIDEO_MAX_NUM_CALLBACKS"; }
+enabled libsvthevc        && require_pkg_config libsvthevc SvtHevcEnc EbApi.h EbInitHandle
 enabled openal            && { { for al_extralibs in "${OPENAL_LIBS}" "-lopenal" "-lOpenAL32"; do
                                check_lib openal 'AL/al.h' alGetError "${al_extralibs}" && break; done } ||
                                die "ERROR: openal not found"; } &&

libavcodec/allcodecs.c.rej

--- libavcodec/allcodecs.c
+++ libavcodec/allcodecs.c
@@ -772,6 +772,7 @@ extern const AVCodec ff_libx264_encoder;
 #endif
 extern const AVCodec ff_libx264rgb_encoder;
 extern AVCodec ff_libx265_encoder;
+extern AVCodec ff_libsvt_hevc_encoder;
 extern const AVCodec ff_libxavs_encoder;
 extern const AVCodec ff_libxavs2_encoder;
 extern const AVCodec ff_libxvid_encoder;
1480c1 commented 1 year ago

@guojiansheng0925 could you see if you can generate a patch for n6.0?

Seems the changes are

First three seems to be just simple moving around, the last one is a conflicting rename that can't easily be backported.

guojiansheng0925 commented 1 year ago

Hi @dpasqualin, Could you use git am to apply the patch? If you have to use patch command, try the parameter -p1: $ patch -p1 < ../SVT-HEVC/ffmpeg_plugin/master-0001-lavc-svt_hevc-add-libsvt-hevc-encoder-wrapper.patch

dpasqualin commented 1 year ago

@guojiansheng0925 could you see if you can generate a patch for n6.0?

If you don't mind I'll try to create PR, thanks for checking the changes :)

Hi @dpasqualin, Could you use git am to apply the patch? If you have to use patch command, try the parameter -p1: $ patch -p1 < ../SVT-HEVC/ffmpeg_plugin/master-0001-lavc-svt_hevc-add-libsvt-hevc-encoder-wrapper.patch

Sorry that was a bad copy/paste from my side, I did use -p1, description updated. Command git am also fails with message below.

$ git am ../master-0001-lavc-svt_hevc-add-libsvt-hevc-encoder-wrapper.patch
Applying: lavc/svt_hevc: add libsvt hevc encoder wrapper
error: patch failed: configure:1763
error: configure: patch does not apply
error: patch failed: libavcodec/allcodecs.c:772
error: libavcodec/allcodecs.c: patch does not apply
Patch failed at 0001 lavc/svt_hevc: add libsvt hevc encoder wrapper
hint: Use 'git am --show-current-patch=diff' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
dpasqualin commented 1 year ago

@1480c1 and @guojiansheng0925, please check whether this is acceptable :) PR https://github.com/OpenVisualCloud/SVT-HEVC/pull/643

guojiansheng0925 commented 1 year ago

Hi @dpasqualin I have tried the patch for master branch can be used for n6.0. I've no idea if there are some gaps, the commit of ffmpeg n6.0 is: commit ea3d24bbe3c58b171e55fe2151fc7ffaca3ab3d2 (grafted, tag: n6.0) is it right?

reproduce.sh.log

Is anything wrong in this script? Can it work in your environment?

dpasqualin commented 1 year ago

Hi @guojiansheng0925 , my PR only covers branch n6.0, not master. So when on ffmpeg repo do something like git checkout tags/n6.0 -b n6.0-branch before applying the patch.

Apparently on FFmpeg master there were some additional breaking changes already. Tomorrow morning I'll update the MR adding a new master-0001-lavc-svt_hevc-add-libsvt-hevc-encoder-wrapper.patch

guojiansheng0925 commented 1 year ago

Hi @dpasqualin Not about your PR. My question is the current patch works well in my environment and I don't know which step went wrong...

gjs@guojians-dev:~/code/svt$ git clone https://git.ffmpeg.org/ffmpeg.git
Cloning into 'ffmpeg'...
remote: Enumerating objects: 6507, done.
remote: Counting objects: 100% (6507/6507), done.
remote: Compressing objects: 100% (4890/4890), done.
remote: Total 694571 (delta 4639), reused 2029 (delta 1611)
Receiving objects: 100% (694571/694571), 167.85 MiB | 6.87 MiB/s, done.
Resolving deltas: 100% (561830/561830), done.
Updating files: 100% (8138/8138), done.
gjs@guojians-dev:~/code/svt$
gjs@guojians-dev:~/code/svt$
gjs@guojians-dev:~/code/svt$ cd ffmpeg
gjs@guojians-dev:~/code/svt/ffmpeg$
gjs@guojians-dev:~/code/svt/ffmpeg$ git checkout tags/n6.0 -b n6.0-branch
Switched to a new branch 'n6.0-branch'
gjs@guojians-dev:~/code/svt/ffmpeg$
gjs@guojians-dev:~/code/svt/ffmpeg$ git am ../SVT-HEVC/ffmpeg_plugin/master-0001-lavc-svt_hevc-add-libsvt-hevc-encoder-wrapper.patch
Applying: lavc/svt_hevc: add libsvt hevc encoder wrapper
gjs@guojians-dev:~/code/svt/ffmpeg$
gjs@guojians-dev:~/code/svt/ffmpeg$

the commit of ffmpeg is

commit ea3d24bbe3c58b171e55fe2151fc7ffaca3ab3d2 (tag: n6.0)
Author: Michael Niedermayer <michael@niedermayer.cc>
Date:   Fri Nov 2 01:36:21 2018 +0100

    RELEASE_NOTES: Based on the version from 5.1

    Name suggested by Niklas Haas

    Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

and the SVT-HEVC is

commit 6cca5b932623d3a1953b165ae6b093ca1325ac44 (HEAD -> master, origin/master, origin/HEAD)
Author: Jan Beich <jbeich@FreeBSD.org>
Date:   Thu Apr 27 15:44:37 2023 +0000

    ffmpeg_plugin: unbreak documentation patch after cc9b8bde85b2

    error: corrupt patch at line 169
    error: patch failed: doc/general.texi:243

    Signed-off-by: Jan Beich <jbeich@FreeBSD.org>

Any gaps between us?

dpasqualin commented 1 year ago

Oh, true. For some reason I only tried to apply SVT-HEVC/ffmpeg_plugin/master-0001-lavc-svt_hevc-add-libsvt-hevc-encoder-wrapper.patch to FFmpeg master branch, not n6.0.

Still, If I update master-0001-lavc-svt_hevc-add-libsvt-hevc-encoder-wrapper.patch to work with FFmpeg master plus SVT-HEVC/ffmpeg_plugin/README.md would you consider merging my PR? It might still be beneficial considering updates on FFmpeg API.

guojiansheng0925 commented 1 year ago

umm... the main branch also works...

gjs@guojians-dev:~/code/svt$ git clone https://git.ffmpeg.org/ffmpeg.git
Cloning into 'ffmpeg'...
remote: Enumerating objects: 6507, done.
remote: Counting objects: 100% (6507/6507), done.
remote: Compressing objects: 100% (4890/4890), done.
remote: Total 694571 (delta 4640), reused 2029 (delta 1611)
Receiving objects: 100% (694571/694571), 167.85 MiB | 3.33 MiB/s, done.
Resolving deltas: 100% (561831/561831), done.
Updating files: 100% (8138/8138), done.
gjs@guojians-dev:~/code/svt$
gjs@guojians-dev:~/code/svt$
gjs@guojians-dev:~/code/svt$ cd ffmpeg
gjs@guojians-dev:~/code/svt/ffmpeg$
gjs@guojians-dev:~/code/svt/ffmpeg$ git am ../SVT-HEVC/ffmpeg_plugin/master-0001-lavc-svt_hevc-add-libsvt-hevc-encoder-wrapper.patch
Applying: lavc/svt_hevc: add libsvt hevc encoder wrapper
gjs@guojians-dev:~/code/svt/ffmpeg$

The latest commit is

commit d51b0580e423f57d9957a0b4d29800a82389f4d3 (origin/master, origin/HEAD)
Author: Tong Wu <tong1.wu-at-intel.com@ffmpeg.org>
Date:   Mon Jun 19 14:15:09 2023 +0800

    lavu/hwcontext_qsv: fix memory leak for d3d9 impl

    Signed-off-by: Tong Wu <tong1.wu@intel.com>

right?

dpasqualin commented 1 year ago

What... the...

Yes, I can confirm that it worked for me now. No clue what I did on first try that made me spend my Sunday on it. Sorry about that too.