adding custom watermark on video stream?

Homer

Member
hi ,
Is it possible to add custom watermark on the video stream? Just like the one on the demo site player where it will show on every interval.

regards,
Homer
 

Max

Administrator
Staff member
Hello

You can try to set
custom_watermark_filename=mylogo.png
in flashphoner.properties
and place mylogo.png file in WCS_HOME/conf directory.
The mylogo.png file should be 640x480

The watermark will not be displayed without transcoding.
Therefore
1. You have to force video transcoding, setting particular playback resolution.
Example:
session.createStream({name:"stream1", constraints:{video:{width:640,height:480}}}).play();
2. The transcoder may take about 1 core CPU per publishing stream.
So if you have 16 publishing streams, 16 cores will be utilized for transcoding.
 

Homer

Member
Hi again,
Sounds like the watermark will appear on all transcoded streams. Possible to control and display only on specific streamId ? :D
 

Max

Administrator
Staff member
Yes it is possible.
You can intercept a transcoded stream by stream name and add watermark to your transcoded stream.
This can be done on server-side.
1. Create Java class.
Code:
package com.example.video;

import com.flashphoner.sdk.media.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyDecodedFrameInterceptor implements IDecodedFrameInterceptor {

    //create one global logger
    private static final Logger log = LoggerFactory.getLogger("MyDecodedFrameInterceptor");

    public void frameDecoded(String streamName, YUVFrame frame) {
    log.info("Got frame " + frame);
    //draw 100x100 rectangle in the center
    int rectSide = 100;
    byte[] greenPixel = new byte[]{0x00, 0x00, 0x00};
    if (frame.getWidth() > rectSide && frame.getHeight() > rectSide) {
        int x = frame.getWidth()/2 - rectSide/2;
        int y = frame.getHeight()/2 - rectSide/2;
        int xLimit = x + rectSide;
        int yLimit = y + rectSide;
        log.info("Draw rect x:" + x + "-" + xLimit + " y:" + y + "-" + yLimit);
        for (; x < xLimit; x++) {
        for (int y2 = y; y2 < yLimit; y2++) {
            frame.writePixel(x, y2, greenPixel);
        }
        }
    }
    }
}
and compile this class to .jar file using Flashphoner libs:
Code:
javac -classpath .:tbs-flashphoner.jar:slf4j-api-1.6.4.jar -d . MyDecodedFrameInterceptor.java
jar cf frame-interceptor.jar com
2. Add to flashphoner.properties
decoded_frame_interceptor =com.example.video.MyDecodedFrameInterceptor

As you can see, we can draw green square on video frame using code above. It is bit complex, but it is the one way to insert custom watermark for particular stream, for now.
 

Attachments

Top