Skip to content

Real time filters

Pedro Sánchez edited this page Sep 21, 2021 · 7 revisions

This library support OpenGL real time filters. By default you can choose between 36 different filters:

https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/tree/master/encoder/src/main/java/com/pedro/encoder/input/gl/render/filters

If you want use this feature you need use the following constructors:

If you want add a filter to stream you only need use setFilter method. Example set gray scale filter:

rtmpCamera1.getGlInterface().setFilter(new GreyScaleFilterRender());

Multiple filters

2.0.9+

In this version, the filters was refactored to remove or add filters dinamically without limitations. This produce a better performance in most of cases respect of previous versions.

Actually, it is working like if you are using a java ArrayList class with the following options:

  /**
   * Replaces the filter at the specified position with the specified filter.
   * You can modify filter's parameters after set it to stream.
   *
   * @param filterPosition filter position
   * @param baseFilterRender filter to set
   */
  void setFilter(int filterPosition, BaseFilterRender baseFilterRender);

  /**
   * Appends the specified filter to the end.
   * You can modify filter's parameters after set it to stream.
   *
   * @param baseFilterRender filter to add
   */
  void addFilter(BaseFilterRender baseFilterRender);

  /**
   * Inserts the specified filter at the specified position.
   * You can modify filter's parameters after set it to stream.
   *
   * @param filterPosition filter position
   * @param baseFilterRender filter to set
   */
  void addFilter(int filterPosition, BaseFilterRender baseFilterRender);

  /**
   * Remove all filters
   */
  void clearFilters();

  /**
   * Remove the filter at the specified position.
   *
   * @param filterPosition position of filter to remove
   */
  void removeFilter(int filterPosition);

  /**
   * @return number of filters
   */
  int filtersCount();

  /**
   * Replace the filter in position 0 or add the filter if list is empty.
   * You can modify filter's parameters after set it to stream.
   *
   * @param baseFilterRender filter to set.
   */
  void setFilter(BaseFilterRender baseFilterRender);

2.0.8 or less

You can set multiple filters by position:

//Greyscale + basic deformation
rtmpCamera1.getGlInterface().setFilter(0, new GreyScaleFilterRender());
rtmpCamera1.getGlInterface().setFilter(1, new BasicDeformationFilterRender());

Set max number of filters (Required in 2.0.8 or less and Optional in 2.0.9+)

You can select max number of filters in OpenGlView attrs:

app:numFilters="2"

Or modify it by code before create stream object:

ManagerRender.numFilters = 2;
rtmpFromFile = new RtmpFromFile(context, connectChecker, videoDecoderInterface, audioDecoderInterface);

Create your own filter

You can do your own filter if you extend from BaseFilterRender class. I recommend you see GreyScaleFilterRender class that is the most easy filter in the library to know how to work it and create your own filter.

Clone this wiki locally