Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rav1e to contribs #3199

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft

Conversation

ePirat
Copy link

@ePirat ePirat commented Oct 25, 2020

Description of Change:

As discusses on IRC, this adds the rav1e AV1 encoder to contribs, along with cargo-c, needed to build and install the C interface library for rav1e.

Some more work on this is needed regarding cross-compilation. But it would be best to discuss the general approach first
before those things are tackled.

Test on:

  • Windows 10+ (via MinGW)
  • macOS 10.13+
  • Ubuntu Linux

@ePirat ePirat marked this pull request as draft October 25, 2020 21:57
@bradleysepos
Copy link
Contributor

Thanks, will review as time allows.

@ePirat
Copy link
Author

ePirat commented Oct 25, 2020

Looks like Linux CI succeeded even though it failed in contribs:

  : error: failed to download `openssl-src v111.12.0+1.1.1h`
  : Caused by:
  :   can't make HTTP request in the offline mode
  : ../contrib/cargo-c/module.rules:2: recipe for target 'contrib/cargo-c/.stamp.cargo-c.build' failed
  : make: *** [contrib/cargo-c/.stamp.cargo-c.build] Error 101
  : make: *** Waiting for unfinished jobs....

It fails like that for all platforms right now, as it does not fetch the openssl-src properly with cargo. Will look into that.

@Nomis101
Copy link
Contributor

On macOS I'm getting:

...
   Compiling either v1.6.0
error: unknown codegen option: `embed-bitcode`

error: unknown codegen option: `embed-bitcode`

error: unknown codegen option: `embed-bitcode`

error: unknown codegen option: `embed-bitcode`

error: unknown codegen option: `embed-bitcode`

error: unknown codegen option: `embed-bitcode`

error: unknown codegen option: `embed-bitcode`

error: unknown codegen option: `embed-bitcode`

error: could not compile `autocfg`.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: unknown codegen option: `embed-bitcode`

error: unknown codegen option: `embed-bitcode`

error: unknown codegen option: `embed-bitcode`

error: unknown codegen option: `embed-bitcode`

error: unknown codegen option: `embed-bitcode`

Error: CliError { error: Some(build failed), exit_code: 101 }
make[1]: *** [contrib/librav1e/.stamp.librav1e.build] Error 1

** BUILD FAILED **


The following build commands failed:
	ExternalBuildToolExecution external
(1 failure)
make: *** [macosx.build] Error 65

No idea what that means, but I hope it helps.

@ePirat
Copy link
Author

ePirat commented Oct 27, 2020

@Nomis101 Never seen that so far, what did you do that caused that? I guess maybe I need to override the whole target to make sure it does not add some arbitrary extra flags that are incorrect for direct use with cargo…

@ePirat
Copy link
Author

ePirat commented Oct 27, 2020

@Nomis101 hmm could it be your rust toolchain is very old? Can you share the output of rustc --version?

@Nomis101
Copy link
Contributor

@ePirat: It's not very old, but yes, this seems to be the above issue. I have rustc 1.43.1 (8d69840ab 2020-05-04) installed, because I need to it build Mozilla Thunderbird and a newer versions fails to build esr78.
If I remove my local rustc, I see the following:

...
cargo fetch --manifest-path=./contrib/cargo-c/cargo-c-0.6.15/Cargo.toml
make[1]: cargo: No such file or directory
/usr/bin/patch -t -N -p1 -d ./contrib/x265/x265_3.2.1/ < /Volumes/Developer/rav1e/HandBrake/contrib/x265/A04-darwin-neon-support-for-arm64.patch
make[1]: *** [contrib/cargo-c/.stamp.cargo-c.configure] Error 1
make[1]: *** Waiting for unfinished jobs....
...
Command ExternalBuildToolExecution failed with a nonzero exit code

** BUILD FAILED **


The following build commands failed:
	ExternalBuildToolExecution external
(1 failure)
make: *** [macosx.build] Error 65

@ePirat
Copy link
Author

ePirat commented Oct 27, 2020

Thanks for the additional info. And yes, it's expected to fail without a rust toolchain.

@Nomis101
Copy link
Contributor

Thanks for the clarification. Yes, if I install rustc 1.47, rav1e builds just fine. But ffmpeg seems to not find rav1e. Is this expected as well?

/usr/bin/gm4 -Iproject /Volumes/Developer/rav1e/HandBrake/macosx/Info.plist.m4 > macosx/Info.plist
creating macosx/osl.filelist.txt
ERROR: rav1e >= 0.1.0 not found using pkg-config

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.
make[1]: *** [contrib/ffmpeg/.stamp.ffmpeg.configure] Error 1
Command ExternalBuildToolExecution failed with a nonzero exit code

** BUILD FAILED **


The following build commands failed:
	ExternalBuildToolExecution external
(1 failure)
make: *** [macosx.build] Error 65

@ePirat
Copy link
Author

ePirat commented Oct 28, 2020

Yeah thats the same CI fails for now, I will look into this when I have time, probably just a matter of setting the right PKG_CONFIG_PATH env var in ffmpeg contrib.

@maximd33
Copy link
Contributor

@ePirat rav1e should "install" its pkg_config into HB's ./build/contrib/lib/pkgconfig

@ePirat
Copy link
Author

ePirat commented Oct 31, 2020

@maximd33 That's already happening, which is why I expected ffmpeg to just find it, as I assumed the contrib pkgconfig directory would already be set as PKG_CONFIG_PATH.

@maximd33
Copy link
Contributor

@ePirat I see

....
error[E0599]: no method named wait_timeout_while found for type std::sync::Condvar in the current scope
--> /home/maxd/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-0.48.0/src/cargo/util/queue.rs:55:14
|
55 | .wait_timeout_while(self.state.lock().unwrap(), timeout, |s| s.items.is_empty())
| ^^^^^^^^^^^^^^^^^^ help: there is a method with a similar name: wait_timeout_until

error: aborting due to 25 previous errors

Some errors have detailed explanations: E0599, E0658.
For more information about an error, try rustc --explain E0599.
error: could not compile cargo.

To learn more, run the command again with --verbose.
make: *** [../contrib/cargo-c/module.rules:3: contrib/cargo-c/.stamp.cargo-c.build] Error 101

@ePirat
Copy link
Author

ePirat commented Nov 1, 2020

@maximd33 Are you sure you do not have the same issue as @Nomis101? (Too old rust toolchain?)

@ePirat
Copy link
Author

ePirat commented Nov 1, 2020

Figured out why for ffmpeg the PKG_CONFIG_PATH was not set properly. Although maybe there was a legitimate reason for it to override the whole default env, in which case PKG_CONFIG_PATH needs to be set manually there…

@ePirat
Copy link
Author

ePirat commented Nov 1, 2020

So now it clearly sets the right PKG_CONFIG_PATH, ffmpeg still fails with ERROR: rav1e >= 0.1.0 not found using pkg-config… Guess I need to do some CI debugging on my fork then to figure out whats going wrong there.

@maximd33
Copy link
Contributor

maximd33 commented Nov 1, 2020

@ePirat
what version is needed?

rustc --version
rustc 1.41.1

ffmpeg - have you checked details at ffbuild/config.log ?

@ePirat
Copy link
Author

ePirat commented Nov 1, 2020

@maximd33 As it fails on CI I can not easily. Will add some logging in CI in my fork, that prints this file, to figure out whats wrong.

You need at least rustc 1.47 so the cargo version will be at least the one that cargo-c depends on.

@Nomis101
Copy link
Contributor

I need to say, I have no idea what this means, but in ffbuild/config.log I see:

/usr/bin/gcc -L/Volumes/Developer/rav1e/HandBrake/build/contrib/lib -arch x86_64 -arch x86_64 -mfpmath=sse -msse2 -L/Volumes/Developer/rav1e/HandBrake/build/contrib/lib -Wl,-dynamic,-search_paths_first -I/Volumes/Developer/rav1e/HandBrake/build/contrib//include/rav1e -L/Volumes/Developer/rav1e/HandBrake/build/contrib//lib -o /var/folders/qh/gtfyt26d59nff_mf4033r7rc0000gn/T//ffconf.00rNg6DU/test /var/folders/qh/gtfyt26d59nff_mf4033r7rc0000gn/T//ffconf.00rNg6DU/test.o -lrav1e -lSystem -lresolv -lc -lm
error: can't create module summary index for buffer: Invalid summary version 9. Version should be in the range [1-8].
clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)
ERROR: rav1e >= 0.1.0 not found using pkg-config

@ePirat ePirat force-pushed the epirat-add-rav1e branch 6 times, most recently from 0e51cba to dad5af7 Compare November 21, 2020 23:46
@ePirat
Copy link
Author

ePirat commented Mar 10, 2021

Got it building in macOS CI now, although it fails at the final link step:

2021-03-10T21:53:39.0956300Z   :     /Applications/Xcode_12.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target x86_64-apple-macos10.11 -isysroot /Applications/Xcode_12.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -L/Users/runner/work/HandBrake/HandBrake/build/ub.osx1011.x86_64/xroot -L/Users/runner/work/HandBrake/HandBrake/build/ub.osx1011.x86_64/libhb -L/Users/runner/work/HandBrake/HandBrake/build/ub.osx1011.x86_64/contrib/lib -F/Users/runner/work/HandBrake/HandBrake/build/ub.osx1011.x86_64/xroot -filelist /Users/runner/work/HandBrake/HandBrake/build/ub.osx1011.x86_64/xroot/HandBrakeCLI.build/Objects-normal/x86_64/HandBrakeCLI.LinkFileList -Xlinker -object_path_lto -Xlinker /Users/runner/work/HandBrake/HandBrake/build/ub.osx1011.x86_64/xroot/HandBrakeCLI.build/Objects-normal/x86_64/HandBrakeCLI_lto.o -filelist /Users/runner/work/HandBrake/HandBrake/build/ub.osx1011.x86_64/macosx/osl.filelist.txt -lc++ -w -liconv -lbz2 -lz -framework CoreMedia -framework CoreVideo -framework VideoToolbox -framework CoreGraphics -framework CoreText -lavfilter -framework AudioToolbox -framework CoreServices -framework IOKit -lopus -lhandbrake -lass -lavcodec -lavformat -lavutil -lbluray -ldav1d -ldvdnav -ldvdread -lspeex -lturbojpeg -lfreetype -lfribidi -lmp3lame -llzma -lpostproc -logg -lswscale -ltheora -lvorbis -lswresample -lvorbisenc -framework Foundation -lvpx -lx264 -lxml2 -ljansson -lharfbuzz -lzimg -Xlinker -dependency_info -Xlinker /Users/runner/work/HandBrake/HandBrake/build/ub.osx1011.x86_64/xroot/HandBrakeCLI.build/Objects-normal/x86_64/HandBrakeCLI_dependency_info.dat -o /Users/runner/work/HandBrake/HandBrake/build/ub.osx1011.x86_64/xroot/HandBrakeCLI
2021-03-10T21:53:39.9165170Z   : Undefined symbols for architecture x86_64:
2021-03-10T21:53:39.9167100Z   :   "_rav1e_config_default", referenced from:
…

as rav1e is missing in the linker library list. What do I need to adjust to have it included in there?

@Nomis101
Copy link
Contributor

You need to add it to HandBrake.xcodeproj. You can use this as an example:
5f53243

@bradleysepos
Copy link
Contributor

Thanks for sticking with this.

@ePirat
Copy link
Author

ePirat commented Mar 11, 2021

@Nomis101 Thanks for the example, thats very helpful! Although I wonder how I could make this work for rav1e given that at least currently it would be useful to have it as optional dependency (as it requires the rust toolchain, which not everyone might have installed)?

Anyway I will probably proceed for now with just adding it so I can advance with the actual integration into Handbrake itself and solve this obstacle later.

@bradleysepos
Copy link
Contributor

Circling back to this after quite some time. I'd like to get this in if we can separate out the dependencies by adding relevant commands to scripts/mac-toolchain-build, and do whatever is necessary to support Linux and Windows. Will also need to update the docs (https://github.com/HandBrake/HandBrake-docs/blob/master/source/docs/en/latest/developer/build-mac.markdown and friends).

@quietvoid quietvoid mentioned this pull request Jan 14, 2023
@galad87
Copy link
Contributor

galad87 commented Jan 20, 2023

To conditionally link it in the Xcode project you can add something like these lines in x265 module.defs:

## optional static libs need to be marked

Just found out today we already had a system in place to resolve this 🙃

@gabriele2000
Copy link

gabriele2000 commented Mar 2, 2023

Since I'm curious: will this get merged before the end of this year?
Maybe we could build it using --RAV1E, thus disabling SVT-AV1

@ePirat
Copy link
Author

ePirat commented Mar 2, 2023

@galad87 If there is still interest in this MR I could give it a shot to rebase it and make the changes to get it working. It should be easier now that Handbrake already supports different AV1 encoders.

@galad87
Copy link
Contributor

galad87 commented Mar 3, 2023

I don't know about shipping it by default, even if we will probably need an AV1 encoder that isn't hopelessly slow on ARM cpu, but making it an optional encoder for now sounds good to me.

Ping @bradleysepos @sr55

@gabriele2000
Copy link

gabriele2000 commented Mar 29, 2023

@galad87 If there is still interest in this MR I could give it a shot to rebase it and make the changes to get it working. It should be easier now that Handbrake already supports different AV1 encoders.

I rebased it locally, the only commits that I had to skip were the one related to mac stuff and two commits of libdovi.
That's it, I'm building HandBrake now, let's see how it plays out.
Linux BTW.

UPDATE: It fails, for now

  :   Downloaded csv v1.1.3
  : touch contrib/librav1e/.stamp.librav1e.configure
  : /usr/bin/cargo clean --manifest-path=./contrib/librav1e/rav1e-0.3.4/Cargo.toml
  : /usr/bin/rm -f ./contrib/librav1e/.stamp.librav1e.build
  : ./contrib/bin/cargo-cbuild cbuild --manifest-path=./contrib/librav1e/rav1e-0.3.4/Cargo.toml --offline --release --library-type staticlib --prefix /home/gabriele/HandBrake/build/contrib/
  : Error: CliError { error: Some(no matching package named `aom-sys` found
  : location searched: registry `https://github.com/rust-lang/crates.io-index`
  : required by package `rav1e v0.3.4 (/home/gabriele/HandBrake/build/contrib/librav1e/rav1e-0.3.4)`
  : As a reminder, you're using offline mode (--offline) which can sometimes cause surprising resolution failures, if this error is too confusing you may wish to retry without the offline flag.), exit_code: 101 }
  : gmake: *** [../contrib/librav1e/module.rules:3: contrib/librav1e/.stamp.librav1e.build] Error 1
-------------------------------------------------------------------------------
time end: Wed Mar 29 19:19:02 2023
duration: 7 minutes, 32 seconds (452.97s)
result: FAILURE (code 2)
-------------------------------------------------------------------------------
Build is finished!
You may now cd into ./build and examine the output.

UPDATE 2

The reason it fails now, after removing --offline from cargo-c and librav1e module.defs files, is:
FFMPEG doesn't have the right header, as far as I understand.

In fact, the compilation goes buttery smooth until it cannot find references into librav1e.c.

  : /usr/bin/ld: /home/gabriele/HandBrake/build//contrib/lib/libavcodec.a(librav1e.o): in function `librav1e_receive_packet':
  : librav1e.c:(.text+0x7b): undefined reference to `rav1e_send_frame'
  : /usr/bin/ld: librav1e.c:(.text+0xb1): undefined reference to `rav1e_receive_packet'
  : /usr/bin/ld: librav1e.c:(.text+0xd4): undefined reference to `rav1e_frame_unref'
  : /usr/bin/ld: librav1e.c:(.text+0xec): undefined reference to `rav1e_status_to_str'
  : /usr/bin/ld: librav1e.c:(.text+0x13e): undefined reference to `rav1e_status_to_str'
  : /usr/bin/ld: librav1e.c:(.text+0x22e): undefined reference to `rav1e_frame_new'
  : /usr/bin/ld: librav1e.c:(.text+0x265): undefined reference to `rav1e_frame_fill_plane'
  : /usr/bin/ld: librav1e.c:(.text+0x2d6): undefined reference to `rav1e_twopass_in'
  : /usr/bin/ld: librav1e.c:(.text+0x313): undefined reference to `rav1e_twopass_out'
  : /usr/bin/ld: librav1e.c:(.text+0x38b): undefined reference to `rav1e_data_unref'
  : /usr/bin/ld: librav1e.c:(.text+0x512): undefined reference to `rav1e_frame_extract_plane'
  : /usr/bin/ld: librav1e.c:(.text+0x536): undefined reference to `rav1e_status_to_str'
  : /usr/bin/ld: librav1e.c:(.text+0x554): undefined reference to `rav1e_status_to_str'
  : /usr/bin/ld: librav1e.c:(.text+0x579): undefined reference to `rav1e_twopass_out'
  : /usr/bin/ld: librav1e.c:(.text+0x5ca): undefined reference to `rav1e_data_unref'
  : /usr/bin/ld: librav1e.c:(.text+0x5f0): undefined reference to `rav1e_frame_set_opaque'
  : /usr/bin/ld: librav1e.c:(.text+0x607): undefined reference to `rav1e_send_frame'
  : /usr/bin/ld: librav1e.c:(.text+0x637): undefined reference to `rav1e_packet_unref'
  : /usr/bin/ld: librav1e.c:(.text+0x666): undefined reference to `rav1e_packet_unref'
  : /usr/bin/ld: librav1e.c:(.text+0x678): undefined reference to `rav1e_packet_unref'
  : /usr/bin/ld: librav1e.c:(.text+0x68e): undefined reference to `rav1e_data_unref'
  : /usr/bin/ld: librav1e.c:(.text+0x6ff): undefined reference to `rav1e_data_unref'
  : /usr/bin/ld: /home/gabriele/HandBrake/build//contrib/lib/libavcodec.a(librav1e.o): in function `librav1e_encode_close':
  : librav1e.c:(.text.unlikely+0x13): undefined reference to `rav1e_context_unref'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x29): undefined reference to `rav1e_frame_unref'
  : /usr/bin/ld: /home/gabriele/HandBrake/build//contrib/lib/libavcodec.a(librav1e.o): in function `librav1e_encode_init':
  : librav1e.c:(.text.unlikely+0x82): undefined reference to `rav1e_config_default'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0xd7): undefined reference to `rav1e_config_set_time_base'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x1b7): undefined reference to `rav1e_config_parse'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x1e8): undefined reference to `rav1e_config_parse_int'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x21f): undefined reference to `rav1e_config_parse_int'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x248): undefined reference to `rav1e_config_set_sample_aspect_ratio'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x25d): undefined reference to `rav1e_config_parse_int'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x28d): undefined reference to `rav1e_config_parse_int'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x2b2): undefined reference to `rav1e_config_parse_int'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x2d7): undefined reference to `rav1e_config_parse_int'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x2fc): undefined reference to `rav1e_config_parse_int'
  : /usr/bin/ld: /home/gabriele/HandBrake/build//contrib/lib/libavcodec.a(librav1e.o):librav1e.c:(.text.unlikely+0x324): more undefined references to `rav1e_config_parse_int' follow
  : /usr/bin/ld: /home/gabriele/HandBrake/build//contrib/lib/libavcodec.a(librav1e.o): in function `librav1e_encode_init':
  : librav1e.c:(.text.unlikely+0x51b): undefined reference to `rav1e_config_set_pixel_format'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x544): undefined reference to `rav1e_config_set_color_description'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x550): undefined reference to `rav1e_context_new'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x5bb): undefined reference to `rav1e_container_sequence_header'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x5cb): undefined reference to `rav1e_data_unref'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x62c): undefined reference to `rav1e_data_unref'
  : /usr/bin/ld: librav1e.c:(.text.unlikely+0x634): undefined reference to `rav1e_config_unref'
  : collect2: error: ld returned 1 exit status
  : gmake[3]: *** [Makefile:631: ghb] Error 1
  : gmake[3]: Leaving directory '/home/gabriele/HandBrake/build/gtk/src'
  : gmake[2]: *** [Makefile:449: all-recursive] Error 1
  : gmake[2]: Leaving directory '/home/gabriele/HandBrake/build/gtk'
  : gmake[1]: *** [Makefile:381: all] Error 2
  : gmake[1]: Leaving directory '/home/gabriele/HandBrake/build/gtk'
  : gmake: *** [../gtk/module.rules:31: gtk.build] Error 2
  : gmake: *** Waiting for unfinished jobs....
  : /usr/bin/strip ./HandBrakeCLI
-------------------------------------------------------------------------------
time end: Wed Mar 29 20:12:05 2023
duration: 20 seconds (20.41s)
result: FAILURE (code 2)
-------------------------------------------------------------------------------
Build is finished!
You may now cd into ./build and examine the output.

@ePirat Do you have any idea how to fix it? Perhaps an ffmpeg patch or something?
Spoiler: I don't understand 90% of this, I'm basing my findings on pure logic.

@gabriele2000
Copy link

@ePirat @galad87 any update on this from your perspectives?

@gabriele2000
Copy link

Gentle ping, this time to @ePirat, @galad87 (fellow Italian) and to the boss himself, @sr55

@sr55
Copy link
Contributor

sr55 commented Jul 12, 2023

I'm not the boss. Just one of 3 project owners.

Personally, ra1ve is of zero interest to me. I'm of the opinion that we should stick to a single encoder, or a single encoder per platform if SVT is problematic. So I will yield to @galad87 on this one if we want to swap the macOS encoder over if this works better on M1/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants