Kha
Kha copied to clipboard
HTML5: Kha Video Example Won't Build (Reliably)
Trying to build this video example: https://github.com/luboslenco/video_example_kha
$ node Kha/make html5 --ffmpeg /usr/local/bin/ffmpeg
Using Kha from /Users/Joncom/Desktop/video_example_kha/Kha
Creating Kha project.
Exporting asset 1 of 1 (movie.mp4).
However, it just hangs indefinitely...
Edit 1:
As part of my effort document this Github issue, I ran ffmpeg -version, because I was going to copy paste the output into here. However, it seems running that command, followed by the build command resulted it builds working now??
$ ffmpeg -version
ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1_1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gpl --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librtmp --enable-libspeex --enable-videotoolbox
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
$ node Kha/make html5 --ffmpeg /usr/local/bin/ffmpeg
Using Kha from /Users/Joncom/Desktop/video_example_kha/Kha
Creating Kha project.
Exporting asset 1 of 1 (movie.mp4).
Compiling shader 1 of 8 (painter-colored.frag.glsl).
Compiling shader 2 of 8 (painter-colored.vert.glsl).
Compiling shader 3 of 8 (painter-image.frag.glsl).
Compiling shader 4 of 8 (painter-image.vert.glsl).
Compiling shader 5 of 8 (painter-text.frag.glsl).
Compiling shader 6 of 8 (painter-text.vert.glsl).
Compiling shader 7 of 8 (painter-video.frag.glsl).
Compiling shader 8 of 8 (painter-video.vert.glsl).
/Users/Joncom/Desktop/video_example_kha/Sources/Empty.hx:21: characters 3-24 : Warning : Use System.notifyOnFrames instead
/Users/Joncom/Desktop/video_example_kha/Sources/Main.hx:7: characters 3-14 : Warning : Use System.start instead
Done.
Really not sure why it started working. Don't think I did anything else other than check the ffmpeg version, and I had tried (and always failed) to build like 5 times already. Anyway, glad it's working.
Edit 2:
$ rm -rf build
$ node Kha/make html5 --ffmpeg /usr/local/bin/ffmpeg
Using Kha from /Users/Joncom/Desktop/video_example_kha/Kha
Creating Kha project.
Exporting asset 1 of 1 (movie.mp4).
Never mind, looks like it's failing/hanging again. :(
Edit 4:
After it hangs for, say, 5 minutes, and I CTRL-C to cancel it, and then immediately re-try, it seems it will instantly succeed now. However, if I inspect the movie.webm file (by playing it in VLC), it appears to be missing the second half that is present in movie.mp4. So even when it succeeds at building, something went wrong.

Even when the build process appears to succeed, running in Chrome produces a JavaScript error.
Video (and audio) cannot be played in Chrome before user gesture events.
True, but that would not throw an exception, would it?
Not sure. Test play() on mouse click
@RblSb, yep, playing after a mouse click worked OK.
However, this issue still remains: trying to build sometimes works and sometimes just hangs. It seems that CTRL-C "cancelling" and then retrying multiple times will always work eventually, but this is still obviously broken...
Even though it takes it sweet time to build the webm, it seems to build on linux at least.
xxx:~/kode/video_example_kha$ time node Kha/make html5 --ffmpeg /snap/bin/ffmpeg
Using Kha from /home/dklein/kode/video_example_kha/Kha
Creating Kha project.
Exporting asset 1 of 1 (movie.mp4).
Compiling shader 1 of 8 (painter-colored.frag.glsl).
...
Done.
real 1m21,370s
user 2m44,165s
sys 0m1,008s
It might be possible that things hang when ffmpeg printfs too much or does other weirdness on the command line. The ffmpeg parameters are around https://github.com/Kode/khamake/blob/master/src/main.ts#L655 Try that manually and see what it does.
The Chrome blocking until interaction thing is problematic though, didn't know that's also applied to videos now and no ideas yet how to handle that nicely.
Does the blocking apply to videos, or specifically the audio in the videos? Because I've noticed on my iPhone (Safari) that videos (YouTube) still autoplay, but always start off muted, and say "tap to unmute".
The whole blocking thing is different per browser.