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 Gosu::Video #595

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

Conversation

cyberarm
Copy link
Collaborator

@cyberarm cyberarm commented May 9, 2021

Currently a stub.

An ffmpeg/libvlc backed implementation that'll emulate the Gosu::Image and Gosu::Song public interfaces.

Gosu::Window::tick() will likely need to call Gosu::Video::update() on all videos; A static vector in Gosu::Video can host and maintain the list.

The implementation is wrapped in an #ifdef to allow Gosu::Video to be an optional feature.

@cyberarm
Copy link
Collaborator Author

@jlnr What do you think of this approach?

TODO:

  • Prevent concurrent read/write of Image data
  • Check for errors when creating libvlc_ objects
  • See why libvlc doesn't seem to like :borderless and if it can be fixed
  • Add libvlc to /dependencies
  • Link against libvlc on Windows and Mac

Video support is behind the -DGOSU_ENABLE_VIDEO flag

Working example:

require_relative "ffi-gosu/lib/gosu"
require_relative "ffi-gosu/lib/gosu/video"


class Window < Gosu::Window
  def initialize
    super(800, 600, false, 16.6667, true, false)

    @video = Gosu::Video.new("/home/cyberarm/Downloads/big-buck-bunny_trailer.webm")

    pp @video.width, @video.height, @video.length, @video.position

    calculate_scale
  end

  def draw
    Gosu.draw_rect(0, 0, width, height, Gosu::Color::WHITE)
    @video.draw(0, 0, 0, @scale, @scale)
  end

  def update
    calculate_scale
  end

  def button_down(id)
    @video.play if id == Gosu::KB_SPACE
    @video.stop if id == Gosu::KB_LEFT_CONTROL
  end

  def calculate_scale
    @scale = [
      [
        width / @video.width.to_f,
        height / @video.height.to_f
      ].min,
      [
        width / @video.width.to_f,
        height / @video.height.to_f
      ].max
    ].min
  end
end

Window.new.show

Screenshot from 2021-05-10 15-43-00

Copy link
Member

@jlnr jlnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, thanks for this. I didn't review all of it, but I left a couple of code comments.

My biggest worry with video support is shippability. ImageMagick seemed like a similar swiss army knife as VLC, but then packaging a Ruby/Gosu game with ImageMagick for Windows turned out to be a huge timesink. (I vaguely remember wrestling with ImageMagick "all in one" builds...)
Is VLC a single DLL that we can ship?

There was also an issue with example code for libtheora, I'm not sure how it compares to libvlc in terms of self-containedness: #349

(As long as it is hidden behind a compiler flag, this is not really a blocker. If video support is only a couple of extra files, why not!)

include/Gosu/Video.hpp Outdated Show resolved Hide resolved
include/Gosu/Video.hpp Outdated Show resolved Hide resolved
@cyberarm
Copy link
Collaborator Author

My biggest worry with video support is shippability. ImageMagick seemed like a similar swiss army knife as VLC, but then packaging a Ruby/Gosu game with ImageMagick for Windows turned out to be a huge timesink. (I vaguely remember wrestling with ImageMagick "all in one" builds...)
Is VLC a single DLL that we can ship?

For libvlc we'd need to include libvlc.dll, 'libvlccore.dll, and any required vlc plugins and codecs to playback video; We should probably only include playback support for ogg, webm, and av1, i.e. royality-free codecs, since they can be a landmine for commercial projects.
libvlc needs the VLC_PLUGIN_PATH environment variable set to locate plugins. It should be easy enough for users to add additional plugins/codecs that they may need.

There was also an issue with example code for libtheora, I'm not sure how it compares to libvlc in terms of self-containedness: #349

The gists @Dahrkael linked to for libtheoraplayer are returning 404s and the waybackmachine doesn't have them.

@jlnr
Copy link
Member

jlnr commented May 22, 2021

Okay, that sounds good 👍 I was worried that we might need to ship a whole zoo of Unix-ish libraries.

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

Successfully merging this pull request may close these issues.

None yet

2 participants