pedroSG94 / RootEncoder

RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Apache License 2.0
2.58k stars 780 forks source link

How to preview filters ,watermarks before stream #155

Closed pratheepchowdhary closed 6 years ago

pratheepchowdhary commented 6 years ago

Hello sir how to preview the filter effects and watermarks before the stream by apply effects and watermarks before stream it will not showing it while streaming only it works so please guide me sir

pedroSG94 commented 6 years ago

I can do it. I detect a crash with gif, images and text but it has an easy fix that will be update in the next days (no time now). To fix replace in openglview:

//need load a stream object
            if (loadStreamObject) {
              if (textStreamObject != null) {
                managerRender.setText(textStreamObject);
              } else if (imageStreamObject != null) {
                managerRender.setImage(imageStreamObject);
              } else if (gifStreamObject != null) {
                managerRender.setGif(gifStreamObject);
              } else {
                managerRender.clear();
              }
            }

To:

//need load a stream object
            if (loadStreamObject) {
              if (textStreamObject != null) {
                managerRender.setText(textStreamObject);
              } else if (imageStreamObject != null) {
                managerRender.setImage(imageStreamObject);
              } else if (gifStreamObject != null) {
                managerRender.setGif(gifStreamObject);
              } else {
                managerRender.clear();
              }
              if (surfaceManagerEncoder == null) loadStreamObject = false;
            }

Of course in activity example you need delete this conditional: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/app/src/main/java/com/pedro/rtpstreamer/openglexample/OpenGlRtmpActivity.java#L105

pratheepchowdhary commented 6 years ago

K Thank you.....

pratheepchowdhary commented 6 years ago

And how to preview local video stream after applying filters and water marks

pedroSG94 commented 6 years ago

No preview available streaming a file for now. It need be developed.

pratheepchowdhary commented 6 years ago

K How to make AndroidViewFilter fit to the video view width and height Accordingly Now it will show according screen resolution of mobile How to make it according to video resloution

pedroSG94 commented 6 years ago

Go xml, create a layout with match parent size and set it to androidviewfilter. Now you have a layout that fit stream. You can hide this layout behind other view to avoid duplicate view in the activity.

pratheepchowdhary commented 6 years ago

Still remains the same issue It will takes the same screen size Is there is any way to fix it programmatically In canvas by giving width and height of video

pedroSG94 commented 6 years ago

Ok, this error is only with stream file mode. I'm looking a fix for it.

pratheepchowdhary commented 6 years ago

please fix it bro

pedroSG94 commented 6 years ago

I try it but for now I can't find a solution. The problem is that you need resize canvas to adjust to stream resolution. I did severals test with a device 1920x1080 screen resolution and I cant find a mathematical relationship. If you are in portrait resize values is 1080x1530 (setted in this line: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/rtplibrary/src/main/java/com/pedro/rtplibrary/OffScreenGlThread.java#L203)

pratheepchowdhary commented 6 years ago

K Another issue is that while adding jpg images as watermark in file stream the it will shows completly white screen with watermark image I tried to convert jpg to png same result But I use already extisted png images works good but with jpg come white screen is there is any solution

pedroSG94 commented 6 years ago

Can you send me an image capture and jpg image that produce error?

pratheepchowdhary commented 6 years ago

screenshot_2018-04-16-18-21-31-400_com facebook katana The images shows video

676a12d7bd3f2ed99b3d13e6584ac1c8 This above show the icon watermark

pedroSG94 commented 6 years ago

Can you send me an image while you are streaming please?

pratheepchowdhary commented 6 years ago

Watch this video

pratheepchowdhary commented 6 years ago

https://m.facebook.com/story.php?story_fbid=1227506437382002&id=100003679734430

pedroSG94 commented 6 years ago

Ok, I understand now. I have to fix the overlay in all stream but the rest is jpg problem but jpg has not alpha so you can't provide a transparency like I do with png and if you convert an image jpg to png the result is an image without transparency because the original image has not it. In this case: 0 -> 100% transparency 1 -> 0% transparency (opaque)

JPG image alpha always 1 because this format has not transparency then you convert to png that has transparency but original transparency is 1 so the result is png with 1 transparency.

How can you fix it (this is a concrete fix for your case)? using a concrete color like transparency (like in chroma stage with green color) in your case white color is good choice.

To do it go to watermark shader: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/encoder/src/main/res/raw/watermark_fragment.glsl#L14 Replace that line to:

if (watermarkPixel.a <= 0.5 || watermarkPixel.rbg == vec3(1.0, 1.0, 1.0)) {

This will filter pure white color but I test and no totally filter in your case so I recommend you filter grey scale totally like:

if (watermarkPixel.a <= 0.5 || (watermarkPixel.r == watermarkPixel.b && watermarkPixel.b == watermarkPixel.g)) {
pedroSG94 commented 6 years ago

Overlay in all stream size is fixed now: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/commit/936e58afe92534f4fece30630890f8dfbb718140

pratheepchowdhary commented 6 years ago

K it's working Thank u