Note: This question has been asked before in https://www.wowza.com/forums/showthread.php?25585-Matching-the-original-stream-while-recording-a-transcoded-stream but was never answered (in the forums)
class StreamListener implements IMediaStreamActionNotify2 {
// ...
@Override
public void onPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) {
String[] transcoders = stream.getLiveStreamTranscoderList().split(",");
if (stream.isTranscodeResult() == true) {
for (String transcoderName : transcoders) {
getLogger().info("Ingrex SmilFactory: stream " + streamName + " has transcoder: " + transcoderName);
ILiveStreamTranscoder transcoder = stream.getLiveStreamTranscoder(transcoderName);
if (transcoder == null)
break;
getLogger().info("Ingrex SmilFactory: stream " + streamName + " has source stream: " + transcoder.getStreamName());
}
}
}
}
How can it be that variable transcoderName within the for() loop returns “transcoder” (a valid string that represents the transcoder name), while stream.getLiveStreamTranscoder(transcoderName) returns null?
Wowza Streaming Engine 4.0.3 build 10989
Hi,
I suspect as you are calling it on the transcoded stream, rather than the non transcoded stream. Looking at the API it suggests that this is only available for non transcoded streams.
Andrew.
Tried the following code instead; but “transcoder” is still NULL!
@Override
public void onPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) {
String[] transcoders = stream.getLiveStreamTranscoderList().split(",");
if (stream.isTranscodeResult())
return;
for (String transcoderName : transcoders) {
getLogger().info("Stream " + streamName + " has transcoder: " + transcoderName);
ILiveStreamTranscoder transcoder = stream.getLiveStreamTranscoder(transcoderName);
if (transcoder == null) {
getLogger().info("Ingrex SmilFactory: sorry, transcoder for stream " + streamName + " is NULL");
continue;
}
getLogger().info("Ingrex SmilFactory: stream " + streamName + " has source stream: " + transcoder.getStreamName());
}
}
I don’t see how your code is different from mine, except that you’ve added a line that splits the streamname on underscore and tries to find the source stream for the transcoded stream. Besides of that, you’re still trying to get the ILiveStreamTranscoder object from the source stream, which I already tried in my previous post. However, what your write above the code sample looks controversial to the code sample itself: if getLiveStreamTranscoder takes a streamname, not a transcodername, it would mean that stream.getLiveStreamTranscoder(“teststream”) would return the ILiveStreamTranscoder instance instead of stream.getLiveStreamTranscoder(“transcoder”)
My intention is: if I have a transcoded stream, I want to be able to find the source stream from that WITHOUT having to do a split on the streamname. Splitting on underscore is a weak solution; e.g. your sample code will fail if someone uses a streamname “test_stream”.
Hi,
A couple of things
getLiveStreamTranscoder actually requires a stream name, not a transcoder name, documentation could be better and i’ll flag that up.
The code
String[] transcoders = stream.getLiveStreamTranscoderList().split(",");
returns all available transcoder named objects, of which 99.9% of the time you will get back transcoder.
So if you do something like
public void onPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend)
{
String[] transcoders = stream.getLiveStreamTranscoderList().split(",");
// assume streamName is <source>_<rendition>
if (stream.isTranscodeResult() )
{
String sourceStream = streamName.split("_")[0];
IMediaStream sourceStreamobj = stream.getStreams().getStream(sourceStream);
for (String transcoderName : transcoders)
{
getLogger().info("Stream " + streamName + " has transcoder: " + transcoderName);
ILiveStreamTranscoder transcoder = sourceStreamobj.getLiveStreamTranscoder(transcoderName);
if (transcoder == null)
{
getLogger().info("Ingrex SmilFactory: sorry, transcoder for stream " + streamName + " is NULL");
continue;
}
getLogger().info("Ingrex SmilFactory: stream " + streamName + " has source stream: " + sourceStreamobj.getName()+" transcoder object '"+transcoder);
}
}
}
That should return the getLiveStreamTranscoder although not entirely sure its what you are after.
Andrew.
Hi,
Yes you are completely correct. I mis-read both documentation and my testing, unfortunately the problem when trying to do multiple things at the same time.
The object you can only ever get back is the transcoder object, which is not the transcoder object for each stream, but the overall transcoder object inherited.
From a stream you can not determine where the source of the transcoding is.
To determine transcoded streams the simplest way is to use ILiveStreamTranscoderNotify when the transcoding session starts up. You get the source stream and using ILiveStreamTranscoderActionNotify you can then also determine the destination stream name.
I must apologise for the confusion and how you are trying to determine source stream there, wont work from a simple stream object.
Andrew.