Encoding video with Media Kit

I am trying to produce video from raw RGB frames, but result video does not open with MediaPlayer: [mov,mp4,m4a,3gp,3g2,mj2 @ 0x195493108c0] moov atom not found error is displayed. What I am doing wrong? Also does Media Kit supports modern codec encoders like H264 of VP8/9?

Source: https://github.com/X547/HaikuUtils/tree/master/VideoEncoder
Haiku: hrev54101 x86_64

MediaKit doesn’t care which video format you use, that’s the job of the ffmpeg add-on which should support mostly everything you expect from ffmpeg. However I think the encoding side is quite broken currently.

The ffmpeg addon is currently broken for anything except h264 mp4 with aac, as can be verified by MediaConvertor. For my video editor, I have 2 code paths, MediaKit and direct Ffmpeg, and default to ffmpeg code path since it works (with uglier C code). Its only one function about 50-60 lines of code to interface with. When I finish up with my editor and open source it, I’ll have a crack at porting the code to MediaKit to fix that code path as well.

1 Like

I can’t see h264 enoder codec for mp4 format:

container: MPEG (Motion Picture Experts Group) format 4, mp4
encoder: MPEG-4 video, mpeg4
encoder: Theora video, theora
encoder: MJPEG (Motion JPEG), mjpeg

Can you provide link to mp4/h264 ffmpeg encoder code that work with actual ffmpeg version?

My goal is to make fast screen capture application and upload result videos to YouTube or similar services.

1 Like

The weekend is the earliest, but will post test code to illustrate.

Have you tried BeScreenCapture? This already supports video capturing using the Media Kit.

It produce extremely low framerate for me and do not supports modern formats (mp4, webm). I already managed to build ffmpeg with x264 and make multithreaded screen capture that produce reasonable framerate. Currently I don’t know how to synchronize time in video.

The FFmpeg package already has x264, I think?

Anyway, jackburton is still around and will accept feature requests and certainly code changes, so why not submit them there? BeScreenCapture uses the Media Kit, so adding WebM should just be exposing it in the UI…

No: ffmpeg: add libx264 · Issue #4919 · haikuports/haikuports · GitHub.

h264 encoder is still not enumerated by Media Kit when libx264 is enabled in ffmpeg. So Media Kit can’t be used for now.

It is probably a 2-line change to add a H.264 profile to the Media Kit FFmpeg plugin encoders whitelist. Why not add that, rather than taking all the time to write something else?

I haven’t looked in Media Kit ffmpeg plugin yet. Zenja says that “The ffmpeg addon is currently broken for anything except h264 mp4 with aac, as can be verified by MediaConvertor”.

I managed to get 1920x1080 25 FPS screen capture with libx264 and 4 threads enabled. Interface became slow during screen capture because of reading frontbuffer. Additional app_server screen buffer is needed to speed up screen capture.

4 Likes

Screen capture result:

10 Likes

Almost real time, considering blender + Mesa are chewing all cores as well as ffmpeg encoder, with no help from GPU silicon. I’m impressed …

5 Likes

Beautiful and so fast I am impresed! :star_struck:

Could your code help to get BeScreenCapure work as fast?

There should be a Haiku programmers prize :trophy:for your work on Haiku.

I am using ffmpeg with libx264 enabled, but there are license issues with libx264: ffmpeg: add libx264 · Issue #4919 · haikuports/haikuports · GitHub. It seems incompatible with MIT license and software using it is infected by GPL. Other video encoders are no such fast as libx264 that is important for software encoding.

Maybe Haiku can get a temporarily license until R1?!
Or a special contract?

See: In addition to being free to use under the GNU GPL, x264 is also available under a commercial license. Contact x264licensing@videolan.org for more details.

It’s also worth noting that H.264 is still patented, and MPEG LA has been known to go after open-source projects in the past that supported encoding it. There was a news article somewhere about this…

Could you please share your ScreenCapture app?

1 Like