Skip to content

Implement video parsing/playback#1333

Draft
adfriz wants to merge 1 commit into
leezer3:masterfrom
adfriz:video-parser
Draft

Implement video parsing/playback#1333
adfriz wants to merge 1 commit into
leezer3:masterfrom
adfriz:video-parser

Conversation

@adfriz

@adfriz adfriz commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Discussion at #1332
VERY EXPERIMENTAL, ONLY TESTED ON WINDOWS.

  • Added mpv_render_context_update flag check to bypass heavy OpenGL renders when no new frame is available.
  • Added auto-pause and resume behavior when textures are not rendered/accessed.
  • Configured automatic unloading after 20 seconds of inactivity to free GPU memory.
  • Added path query parsing (e.g. video.mp4?loop=no) to configure loop settings from b3d/csv files.
  • Added strict URL and network protocol checks to block internet endpoints.
  • Tuned MPV options (demuxer bounds, fast decoding, skiploopfilter, and thread limits) to prevent CPU/FPS lag.

simple way to use is jut load it like using nomal texture

example : myobject.b3d

[MeshBuilder]
Vertex 0.0000, 0.6000, -1.0000, 1.0000, 0.0000, 0.0000
Vertex 0.0000, 0.6000, 1.0000, 1.0000, 0.0000, 0.0000
Vertex 0.0000, -0.6000, 1.0000, 1.0000, 0.0000, 0.0000
Vertex 0.0000, -0.6000, -1.0000, 1.0000, 0.0000, 0.0000
Face 0, 1, 2, 3
Load myvideo.mp4
Coordinates 0, -0.0000, 0.0000
Coordinates 1, 1.0000, 0.0000
Coordinates 2, 1.0000, 1.0000
Coordinates 3, 0.0000, 1.0000

By default its looping infinitely, add this paramater in the same filepath as your video file.

Play once: video.mp4?loop=no (or ?loop=false / ?loop=0)
Loop forever (default): video.mp4 (or video.mp4?loop=inf)
Loop few times (e.g. 3 times): video.mp4?loop=3

so its like:

[MeshBuilder]
Vertex 0.0000, 0.6000, -1.0000, 1.0000, 0.0000, 0.0000
Vertex 0.0000, 0.6000, 1.0000, 1.0000, 0.0000, 0.0000
Vertex 0.0000, -0.6000, 1.0000, 1.0000, 0.0000, 0.0000
Vertex 0.0000, -0.6000, -1.0000, 1.0000, 0.0000, 0.0000
Face 0, 1, 2, 3
Load myvideo.mp4?loop=no
Coordinates 0, -0.0000, 0.0000
Coordinates 1, 1.0000, 0.0000
Coordinates 2, 1.0000, 1.0000
Coordinates 3, 0.0000, 1.0000

Note:

  1. I only write the code for talking with the dll, for the dll it self you need to compile it from the source https://github.com/mpv-player/mpv or use prebuilt binaries, i use the prebuilt by third party https://sourceforge.net/projects/mpv-player-windows/files/libmpv/ i choose the x64 for 64bit variant.
  2. You need to put the libmpv-2.dll next to Tolk.dll
  3. test it, on object viewer is easier.
  4. currently i set is as no audio, if you want to have audio, in file videotexture.cs line 93 you set that line as comment to enable audio decoder.
  5. i limit max video fps playback to 30fps
  6. the video may looks stretched, you must tweak your object UV coordinates and it shapes.

@leezer3 if you have time, may take a look?

- Added mpv_render_context_update flag check to bypass heavy OpenGL renders when no new frame is available.
- Added auto-pause and resume behavior when textures are not rendered/accessed.
- Configured automatic unloading after 20 seconds of inactivity to free GPU memory.
- Added path query parsing (e.g. video.mp4?loop=no) to configure loop settings from b3d/csv files.
- Added strict URL and network protocol checks to block internet endpoints.
- Tuned MPV options (demuxer bounds, fast decoding, skiploopfilter, and thread limits) to prevent CPU/FPS lag.
@ginga81

ginga81 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor
Screenshot_20260613_201817 Screenshot_20260613_201854 I built and tried to load an 11GB MP4 file, but it didn't play. It's GB, not 11MB. Since there's no time limit, I tried a larger file. I've never used b3d before, so I just tried it as is. I also tried a 400MB file, but that didn't work either. The codec in the MP4 file I loaded might not have been supported. Does it need to be converted to a supported codec?

@adfriz

adfriz commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

please dont use too big video file, try test it with small 720p 10 seconds file.

you need the libmpv .so file, unfortunately im not familiar with linux environment. you need to obtain the libmpv file either compile it from the source or from your package's server.

@leezer3

leezer3 commented Jun 15, 2026

Copy link
Copy Markdown
Owner

For Debian / Ubuntu, I think you'll need to first install the libmpv2 package.

Then, edit the OpenBveApi.dll.config file to add the following into the <Configuration> block:

<dllmap os="linux" dll="libmpv-2.dll" target="libmpv.so.2"/>

Not tested at the minute, might try doing that later.

Apple wise, I think you'd have to compile it as a dylib, along with all it's dependancies and add that to the actual app bundle.

I'm not entirely convinced though. This seems like a lot of work (and mess) for a relatively small return, Animated GIF files haven't really been used, and they give much the same result.

@ginga81

ginga81 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

I also asked the question because I thought I could play an 11GB file since I heard there was no time limit.

However, as you mentioned, there's a time limit, and the resolution is 720P, and it's less than 30 seconds long, so I thought there are already realize by animated GIFs...
However, if the audio is also played, I think that's an advantage.

@adfriz

adfriz commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

I'm not entirely convinced though. This seems like a lot of work (and mess) for a relatively small return, Animated GIF files haven't really been used, and they give much the same result.

well yeah... it is very time consuming... just assume this PR as working proof of concept.

i tried to narrow it down, so only the video and audio decoder must work if we set video as texture, others feature should be blocked. But in the end, we must compile and tinker with the lib itself and its dependency if we need it for real public release... i don't want us to ship entire 100MB lib...

@adfriz

adfriz commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

I also asked the question because I thought I could play an 11GB file since I heard there was no time limit.

However, as you mentioned, there's a time limit, and the resolution is 720P, and it's less than 30 seconds long, so I thought there are already realize by animated GIFs... However, if the audio is also played, I think that's an advantage.

i mean... there is technically no limits for size and video length... but if you wanna test, 720p 30fps 10 seconds is good enough.

The audio is supported when i tested it in my side (windows).

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.

3 participants