Results 1 to 4 of 4

Thread: Generating smil files programatically

  1. #1

    Default Generating smil files programatically

    Hi,
    I'm using multiple origins and egdes, all of them use the same shared disc for the streams storage path.
    For each new stream in the origin server, I want to generate a smil file in the shared streams storage directory.
    I want the smill to match the ngrp:myStream_all.
    That's the code I wrote:
    class LiveStreamTranscoderListener implements ILiveStreamTranscoderNotify {

    @Override
    public void onLiveStreamTranscoderCreate(ILiveStreamTranscoder liveStreamTranscoder, IMediaStream mediaStream) {
    }

    @Override
    public void onLiveStreamTranscoderDestroy(ILiveStreamTranscoder liveStreamTranscoder, IMediaStream mediaStream) {
    }

    @Override
    public void onLiveStreamTranscoderInit(ILiveStreamTranscoder liveStreamTranscoder, IMediaStream mediaStream) {
    IApplicationInstance appInstance = liveStreamTranscoder.getAppInstance();

    String streamName = mediaStream.getName();
    String appName = appInstance.getContextStr();

    getLogger().debug("LiveStreamEntry#LiveStreamTranscoderListener.onLiveStreamTranscoderInit [" + appName + "/" + mediaStream.getName() + "]");

    // Itried all the three options below:
    MediaList mediaList = MediaListUtils.parseMediaList(appInstance, streamName, "smil", null);
    // MediaList mediaList = MediaListUtils.parseMediaList(appInstance, streamName + "_all", "smil", null);
    // MediaList mediaList = MediaListUtils.parseMediaList(appInstance, "ngrp:" + streamName + "_all", "smil", null);

    if (mediaList == null) {
    getLogger().error("LiveStreamEntry#LiveStreamTranscoderListener.onLiveStreamTranscoderInit: MediaList not found: " + appName + "/" + streamName);
    return;
    }

    String smil = mediaList.toSMILString();
    String filePath = appInstance.getStreamStoragePath() + File.separator + streamName + "_all.smil";

    try {
    PrintWriter out = new PrintWriter(filePath);
    out.print(smil);
    out.close();
    } catch (FileNotFoundException e) {
    getLogger().error("LiveStreamEntry#LiveStreamTranscoderListener.onLiveStreamTranscoderInit: Failed writing to file [" + filePath + "]: " + e.getMessage());
    return;
    }

    getLogger().info("LiveStreamEntry#LiveStreamTranscoderListener.onLiveStreamTranscoderInit: Created smil file [" + filePath + "] for stream " + appName + "/" + streamName + ":\n" + smil + "\n\n");
    }
    }

    public void onAppStart(IApplicationInstance appInstance) {
    appInstance.addLiveStreamTranscoderListener(new LiveStreamTranscoderListener());
    }
    When I access the medialist tool:
    http://wowza-01.dev:8086/medialist?s.../p&format=smil
    I get a valid smil:
    <smil>
    <head/>
    <body>
    <switch>
    <video src="mp4:0_xmk3txay_32" system-bitrate="1019904" width="640" height="480">
    <param name="audioBitrate" value="98304" valuetype="data"/>
    <param name="videoBitrate" value="921600" valuetype="data"/>
    <param name="videoCodecId" value="avc1.66.31" valuetype="data"/>
    <param name="audioCodecId" value="mp4a.40.34" valuetype="data"/>
    </video>
    <video src="mp4:0_xmk3txay_33" system-bitrate="475136" width="480" height="360">
    <param name="audioBitrate" value="65536" valuetype="data"/>
    <param name="videoBitrate" value="409600" valuetype="data"/>
    <param name="videoCodecId" value="avc1.66.21" valuetype="data"/>
    <param name="audioCodecId" value="mp4a.40.2" valuetype="data"/>
    </video>
    <video src="mp4:0_xmk3txay_34" system-bitrate="679936" width="640" height="480">
    <param name="audioBitrate" value="65536" valuetype="data"/>
    <param name="videoBitrate" value="614400" valuetype="data"/>
    <param name="videoCodecId" value="avc1.66.22" valuetype="data"/>
    <param name="audioCodecId" value="mp4a.40.2" valuetype="data"/>
    </video>
    <video src="mp4:0_xmk3txay_35" system-bitrate="987136" width="640" height="480">
    <param name="audioBitrate" value="65536" valuetype="data"/>
    <param name="videoBitrate" value="921600" valuetype="data"/>
    <param name="videoCodecId" value="avc1.77.31" valuetype="data"/>
    <param name="audioCodecId" value="mp4a.40.2" valuetype="data"/>
    </video>
    </switch>
    </body>
    </smil>
    But when I generate the smil file from the code, I get empty smil:
    <smil>
    <head/>
    <body>
    </body>
    </smil>
    Is there a way to do it?

    Thanks,
    T.

  2. #2

    Default

    Hi,

    You are trying to access the StreamNameGroup before it is created.

    You need to implement the ILiveStreamTranscoderActionNotify interface which has the methods, onRegisterStreamNameGroup and onUnregisterStreamNameGroup. From these methods, you should be able to call MedialistUtils.parseMedialist.

    There is a convenience class that already implements all of the ILiveStreamTranscoderActionNotify methods so you can just extend that in your own class and implement the required methods.

    . . .
    
    public void onLiveStreamTranscoderCreate (ILiveStreamTranscoder liveStreamTranscoder, IMediaStream stream)
    {
           ((LiveStreamTranscoder)liveStreamTranscoder).addActionListener(new MyTranscoderActionNotifier());
    }
    
    . . . 
    
    class MyTranscoderActionNotifier extends LiveStreamTranscoderActionNotifyBase
    {
    	void onRegisterStreamNameGroup(LiveStreamTranscoder liveStreamTranscoder, TranscoderStreamNameGroup streamNameGroup)
    	{
    		// Create smil here.
    	}
    
    	void onUnRegisterStreamNameGroup(LiveStreamTranscoder liveStreamTranscoder, TranscoderStreamNameGroup streamNameGroup)
    	{
    		// remove smil here if needed.
    	}
    }

  3. #3

    Default

    Thank you Roger,
    But I still get an empty smil file, although the media list tool over http returns the expected smil.
    I tried few options, all of them returned empty smil:
    MediaList mediaList = MediaListUtils.parseMediaList(appInstance, streamName, "smil", null);
    MediaList mediaList = MediaListUtils.parseMediaList(appInstance, streamName + "_all", "smil", null);
    MediaList mediaList = MediaListUtils.parseMediaList(appInstance, "ngrp:" + streamName + "_all", "smil", null);

    Could you please tell me what is the right one or what I do wrong?

    Thanks,
    T.

  4. #4

    Default

    solved it:

    class LiveStreamTranscoderActionListener extends LiveStreamTranscoderActionNotifyBase {

    @Override
    public void onRegisterStreamNameGroup(LiveStreamTranscoder liveStreamTranscoder, TranscoderStreamNameGroup streamNameGroup){

    IApplicationInstance appInstance = liveStreamTranscoder.getAppInstance();

    String groupName = streamNameGroup.getStreamName();
    String appName = appInstance.getContextStr();

    getLogger().debug("LiveStreamEntry#LiveStreamTranscoderActionListener.onRegisterStreamNameGroup [" + appName + "/" + groupName + "]");

    MediaList mediaList = MediaListUtils.parseMediaList(appInstance, groupName, "ngrp", null);
    if (mediaList == null) {
    getLogger().error("LiveStreamEntry#LiveStreamTranscoderActionListener.onRegisterStreamNameGroup: MediaList not found: " + appName + "/" + groupName);
    return;
    }

    String smil = mediaList.toSMILString();
    String filePath = appInstance.getStreamStoragePath() + File.separator + groupName + ".smil";

    try {
    PrintWriter out = new PrintWriter(filePath);
    out.print(smil);
    out.close();
    } catch (FileNotFoundException e) {
    getLogger().error("LiveStreamEntry#LiveStreamTranscoderActionListener.onRegisterStreamNameGroup: Failed writing to file [" + filePath + "]: " + e.getMessage());
    return;
    }

    getLogger().info("LiveStreamEntry#LiveStreamTranscoderActionListener.onRegisterStreamNameGroup: Created smil file [" + filePath + "] for stream " + appName + "/" + groupName + ":\n" + smil + "\n\n");
    }

    @Override
    public void onUnregisterStreamNameGroup(LiveStreamTranscoder liveStreamTranscoder, TranscoderStreamNameGroup streamNameGroup){

    IApplicationInstance appInstance = liveStreamTranscoder.getAppInstance();

    String groupName = streamNameGroup.getStreamName();
    String appName = appInstance.getContextStr();

    getLogger().debug("LiveStreamEntry#LiveStreamTranscoderActionListener.onUnregisterStreamNameGroup [" + appName + "/" + groupName + "]");

    String filePath = appInstance.getStreamStoragePath() + File.separator + groupName + ".smil";

    File file = new File(filePath);
    if(file.exists())
    file.delete();

    getLogger().info("LiveStreamEntry#LiveStreamTranscoderActionListener.onUnregisterStreamNameGroup: Deleted smil file [" + filePath + "] for stream " + appName + "/" + groupName);
    }
    }

Similar Threads

  1. resolvePlayAlias and SMIL files
    By vjagannathan in forum General Forum
    Replies: 2
    Last Post: 07-24-2014, 07:21 PM
  2. HTTPLiveStreamRecord Generating Corrupt Files
    By ImAStreamer in forum General Forum
    Replies: 5
    Last Post: 03-20-2014, 09:25 PM
  3. Problem with smil files
    By Atmapuri in forum Wowza Streaming Server Java API
    Replies: 5
    Last Post: 02-27-2014, 02:27 PM
  4. Live smil files on S3
    By cc0004 in forum Live Streaming and Encoder Discussion
    Replies: 2
    Last Post: 11-08-2011, 08:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •