Skip to content

Add gif encoder plugin

Markus Ebner requested to merge ebnerm/gst-plugins-rs:gifenc into master

Hello! As my first steps in the department of gstreamer plugins, I wrote a image/gif encoder plugin. This is only a very barebone implementation for now, created by copying the rav1e plugin, stripping it, and implementing what seems to be needed.

As encoder, I used the gif crate. Unfortunately, the encoder in this crate requires a std::io::Write implementation, to which it can write. To be able to retrieve the data the encoder wrote for a single frame, I implemented a CacheBuffer. The encoder can write to it, while the gstreamer plugin can extract the written data directly afterwards, to pass it to the finish_frame method. In the code, this can be (roughly) found as:

gstreamer
  -> element.handle_frame(frame)
  -> gifencoder.write_frame(frame)
  -> plugin.output_frames()
  -> element.finish_frame(cache.consume())

Like this, I was able to encode one frame at a time, followed by sending them to the pipeline. However (noted with a "FIXME" in the code), I was not able to get this to work properly. If I send frame-by-frame to the pipeline, the plugin crashes when I send an EOS to the pipeline:

gstreamer
  -> element.finish() // tells encoder to write trailing gif-format stuff
  -> plugin.output_frames()
  -> let mut frame = element.get_oldest_frame().expect(); // CRASH

It is still a bit rough overall, and (especially the CacheBuffer hack) probably not up to the coding standards. Would this plugin even be of interest? I would love a bit of feedback, and maybe also a hint regarding the mentioned crash problem. Thus marked as WIP.

Edited by Markus Ebner

Merge request reports