I am testing Wowza on a trial license (expires in 15 days).
I have enabled the transcoder on live application (called “live2”) and publish from flash client stream named “myStream” to this application.
So in wowza manager I can see succesfully produced three streams: myStream rtmp://127.0.0.1:16943 , myStream_160p local (Transcoder) , myStream_360p local (Transcoder)
Now I try to get thumbnails from “myStream”.
I use sample code from https://www.wowza.com/docs/how-to-get-thumbnail-images-from-wowza-transcoder-with-an-http-provider.
I compiled and added this module to my application:
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
import com.wowza.wms.amf.*;
import com.wowza.wms.client.*;
import com.wowza.wms.request.*;
import com.wowza.wms.module.*;
import com.wowza.wms.application.*;
import com.wowza.wms.stream.*;
import com.wowza.wms.transcoder.model.*;
import com.wowza.wms.transcoder.util.*;
public class ModuleTestTranscoderFrameGrab extends ModuleBase
{
private IApplicationInstance appInstance = null;
class GrabResult implements ITranscoderFrameGrabResult
{
public void onGrabFrame(TranscoderNativeVideoFrame videoFrame)
{
BufferedImage image = TranscoderStreamUtils.nativeImageToBufferedImage(videoFrame);
if (image != null)
{
getLogger().info("ModuleTestTranscoderFrameGrab#GrabResult.onGrabFrame: "+image.getWidth()+"x"+image.getHeight());
String storageDir = appInstance.getStreamStoragePath();
File pngFile = new File(storageDir+"/thumbnail.png");
File jpgFile = new File(storageDir+"/thumbnail.jpg");
try
{
if (pngFile.exists())
pngFile.delete();
ImageIO.write(image, "png", pngFile);
getLogger().info("ModuleTestTranscoderFrameGrab#GrabResult.onGrabFrame: Save image: "+pngFile);
}
catch(Exception e)
{
getLogger().error("ModuleTestTranscoderFrameGrab.grabFrame: File write error: "+pngFile);
}
try
{
if (jpgFile.exists())
jpgFile.delete();
ImageIO.write(image, "jpg", jpgFile);
getLogger().info("ModuleTestTranscoderFrameGrab#GrabResult.onGrabFrame: Save image: "+jpgFile);
}
catch(Exception e)
{
getLogger().error("ModuleTestTranscoderFrameGrab.grabFrame: File write error: "+jpgFile);
}
}
}
}
public void onAppStart(IApplicationInstance appInstance)
{
getLogger().info("ModuleTestTranscoderFrameGrab.onAppStart["+appInstance.getContextStr()+"]");
this.appInstance = appInstance;
}
public void grabFrame(IClient client, RequestFunction function, AMFDataList params)
{
getLogger().info("ModuleTestTranscoderFrameGrab.grabFrame");
while(true)
{
String streamName = params.getString(PARAM1);
if (streamName == null)
{
getLogger().warn("ModuleTestTranscoderFrameGrab.grabFrame: No streamName");
break;
}
IApplicationInstance appInstance = client.getAppInstance();
if (appInstance == null)
{
getLogger().warn("ModuleTestTranscoderFrameGrab.grabFrame: No appInstance");
break;
}
IMediaStream stream = appInstance.getStreams().getStream(streamName);
if (stream == null)
{
getLogger().warn("ModuleTestTranscoderFrameGrab.grabFrame: No stream");
break;
}
LiveStreamTranscoder liveStreamTranscoder = (LiveStreamTranscoder)stream.getLiveStreamTranscoder("transcoder");
if (liveStreamTranscoder == null)
{
getLogger().warn("ModuleTestTranscoderFrameGrab.grabFrame: No liveStreamTranscoder");
break;
}
TranscoderStream transcodingStream = liveStreamTranscoder.getTranscodingStream();
if (transcodingStream == null)
{
getLogger().warn("ModuleTestTranscoderFrameGrab.grabFrame: No transcodingStream");
break;
}
TranscoderStreamSourceVideo sourceVideo = transcodingStream.getSource().getVideo();
if (sourceVideo == null)
{
getLogger().warn("ModuleTestTranscoderFrameGrab.grabFrame: No sourceVideo");
break;
}
getLogger().info("ModuleTestTranscoderFrameGrab.grabFrame: Call grabFrame");
sourceVideo.grabFrame(new GrabResult(), 426, 240);
break;
}
}
}
On client side I call custom method grabeFrame this way (after succesfully connection to wowza and publishing stream “myStream” to live2 application):
...
nc.call("grabFrame", null, "myStream");
...
On server side I can see in logs “ModuleTestTranscoderFrameGrab.grabFrame: Call grabFrame” but it seems that sourceVideo.grabFrame(new GrabResult(), 426, 240); is never called and thumbnails aren’t created.
What I do wrong?