libgdx / gdx-video

A libGDX cross platform video rendering extension
Apache License 2.0
147 stars 50 forks source link

New iOS backend, build system and desktop updates. #77

Closed dasisdormax closed 1 year ago

dasisdormax commented 1 year ago

Hello everyone,

This draft PR includes larger changes to add video support into our game.

Original changes:

Added later:

I focused on the features and platforms that are needed in our game, so GWT and Windows aren't as thoroughly tested. (edited)

I understand that this is quite a lot to review as one, but I could not separate the code from the build system changes.

Still, please feel free to test the current state and leave feedback, questions or suggestions.

dasisdormax commented 1 year ago

A small update on the progress:

In the last days I focused on getting Linux builds to work, and on building and testing the included test projects. I also updated the github actions to work with the Gradle changes, but I couldn't test the changes to snapshot and release publishing.

Known Issues / Things that I'll still work on:

As I won't have much time the next weeks, I'll skip the preload system for now and focus on fixing bugs and making the current version more stable. Once this is done I'll mark this PR as ready for review. I still think the build and documentation updates and the iOS backend benefit the library users and potential new contributors. I don't want to delay this until the preload system is fully done.

dasisdormax commented 1 year ago

Here are some more comments about the changes to the build system:

Gradle and dependency versions

Gradle and the dependencies are brought up to the same versions as current libGDX:

This required replacing the 'maven' plugin with 'maven-publish'.

Github Actions

The actions were updated to work with the updated gradle versions. For this, the java and gradle setup were borrowed from libGDX's actions.

Also, the natives builds were split up into Linux, Mac and Windows. These jobs upload to a common 'desktop-natives' artifact, which is consumed by the final 'gradle-build' job. The 'desktop-natives' artifact is also comfortable to download and use for local building and testing.

Desktop natives building

(gdx-video-desktop/build.gradle)

The compile steps for the desktop natives remain the same: First, a custom build of FFmpeg is compiled. Then, this build is combined with own logic via gdx-jnigen to produce a shared library with everything included.

The configuration of the compile tasks works slightly different now. A registerBuild function is configured that

The flags were updated to work with the updated FFmpeg version and additional support for AV1/Opus

dasisdormax commented 1 year ago

Here are some more comments about the updated desktop implementation:

The FFmpeg submodule was updated to version 5.1.3. This required significant changes to the VideoDecoder class, but also allowed to make some things simpler. The FFmpeg initialization and custom I/O methods are not required anymore.

An overview what the code does:

dasisdormax commented 1 year ago

On the iOS implementation:

I feel it is quite straight forward overall. The provided file is opened as AVAsset, which is queried for the track metadata and passed to an AVPlayerItem. As audio output is handled automatically, we only add a videoOutput to the AVPlayerItem request the video frames as RGB data. The AVPlayerItem is added to an AVPlayer for playback control.

When calling update, we check the video output for new frames and create a libGDX Texture from it.

SimonIT commented 1 year ago

Thanks for the massive work!

Frosty-J commented 9 months ago

On desktop, AV1 seems not to work. Any thoughts? Only tried on Windows and encoding with av1_nvenc. VP8 and VP9 are fine.

[av1 @ 0000017ce51f5800] Your platform doesn't suppport hardware accelerated AV1 decoding.
[av1 @ 0000017ce51f5800] Failed to get pixel format.
[av1 @ 0000017ce51f5800] Missing Sequence Header.
[av1 @ 0000017ce51f5800] Missing Sequence Header.
[...]
[matroska,webm @ 0000017ce51f1100] Could not find codec parameters for stream 0 (Video: av1 (Main), none(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9]): unspecified pixel format
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
[VideoPlayer::loadFile] video stream found [index=0]
[VideoPlayer::loadFile] audio stream found [index=1]
[VideoPlayer::loadFile] Loading audio resampler ...
[VideoPlayer::loadFile] Loading video scaler ...
Assertion desc failed at src/libswscale/swscale_internal.h:725

After reading the error, I tried encoding with -pix_fmt yuv420p, which unsurprisingly made no difference.