Results 1 to 8 of 8

Thread: How to get recording segment duration at onWriteComplete()

  1. #1

    Default How to get recording segment duration at onWriteComplete()

    Hi,

    I am using the HTTPLiveRecording module to generate recording segments, I would like to know the segment's duration when it wrote done. the onWriteComplete() would be the best timing for me.
    Is it possible to get the duration at onWriteComplete()? please prompt how to do it, thanks a lot.

    Yehudi

  2. #2

    Default

    You can access this information and more with IOPerformanceCounter.

    In the IDE import:
    import com.wowza.util.IOPerformanceCounter;
    Then in the onWriteComplete method add the following code (in bold):
    public void onWriteComplete(IMediaStream stream, File file)
      {
    	getLogger().info("ModuleWriteListener.onWriteComplete["+stream.getContextStr()+"]: "+file);
    		
            IOPerformanceCounter perf = stream.getMediaIOPerformance();	
             Double duration = stream.getElapsedTime().getTimeSeconds();
    			
      }
    Salvadore

  3. #3

    Default

    Hi,

    I tried, but the stream.getElapsedTime().getTimeSeconds() is NOT the current segment file duration. It maybe the stream's total duration and would be incremental on each segment completion:
    public void onWriteComplete(IMediaStream stream, File file)
      {
    ....
       destinationPath = fileMoverDestinationPath + "/"+file.getName();
       File dstFile = new File(destinationPath);
       IOPerformanceCounter perf = stream.getMediaIOPerformance();	
       Double duration = stream.getElapsedTime().getTimeSeconds();
       getLogger().info("[onWriteComplete] from: "+file+" to:"+dstFile + " duration: "+ duration);
    ....
      }
    log:
    INFO server comment - [onWriteComplete] from: /Library/WowzaMediaServer/content/mystream_2013-08-16-07.38.37.030-CST_0.mp4 to:/Library/WowzaMediaServer/content/11/mystream_2013-08-16-07.38.37.030-CST_0.mp4 duration: 80.288 #strange first value, each file content duration has only about 4~8 seconds
    INFO server comment - [onWriteComplete] from: /Library/WowzaMediaServer/content/mystream_2013-08-16-07.38.37.030-CST_1.mp4 to:/Library/WowzaMediaServer/content/11/mystream_2013-08-16-07.38.37.030-CST_1.mp4 duration: 84.329
    INFO server comment - [onWriteComplete] from: /Library/WowzaMediaServer/content/mystream_2013-08-16-07.38.37.030-CST_2.mp4 to:/Library/WowzaMediaServer/content/11/mystream_2013-08-16-07.38.37.030-CST_2.mp4 duration: 90.372
    INFO server comment - [onWriteComplete] from: /Library/WowzaMediaServer/content/mystream_2013-08-16-07.38.37.030-CST_3.mp4 to:/Library/WowzaMediaServer/content/11/mystream_2013-08-16-07.38.37.030-CST_3.mp4 duration: 94.528
    ...
    Is it possible to get the current segment file duration directly?
    I searched and found the ILiveStreamRecord.getCurrentDuration, it seems like what I need (not sure). But I have no idea about how to get the recorder at onWriteComplete()

    Yehudi
    Last edited by spiritsoul; 08-15-2013 at 05:36 PM.

  4. #4

    Default

    I really appreciate if you can help on it

    Thanks

  5. #5

    Default

    Hi,

    If the file is in the appInstance storage directory then you can just use StreamUtils.getStreamLength(appInstance, streamName); where streamName is the file name relative to the storage directory.

    It isn't easy with a file that is outside of the storage directory so if possible, record to somewhere that can be mapped to the storage directory.

    Roger.

  6. #6

    Default

    Hi Roger
    Thank your reply, I tried but the getStreamLength always returned 0.0 in experiment
    package com.mycompany.wms.module;
    
    import java.io.File;
    import java.util.Map;
    
    import com.wowza.wms.application.IApplicationInstance;
    import com.wowza.wms.module.*;
    import com.wowza.wms.stream.IMediaStream;
    import com.wowza.wms.stream.IMediaWriterActionNotify;
    import com.wowza.wms.util.StreamUtils;
    
    public class SegmentCompleteListener extends ModuleBase implements IMediaWriterActionNotify
    {
    	
    	public void onAppStart(IApplicationInstance appInstance)
    	{
    		appInstance.addMediaWriterListener(this);
    		getLogger().info("[onAppStart]: "+appInstance.getContextStr());		
    	}
    	
    	public void onWriteComplete(IMediaStream stream, File file)
    	{
    		IApplicationInstance appInstance = stream.getStreams().getAppInstance();
    		double overrideDuration = StreamUtils.getStreamLength(appInstance, file.getName());	
    		getLogger().info("[onWriteComplete]: file: "+file + " duration: "+ overrideDuration);
    	}
    	
    	public void onFLVAddMetadata(IMediaStream stream, Map<String, Object> extraMetadata)
    	{
    	}
    	
    }

    Application.xml
    <Streams>
    			<StreamType>live</StreamType>
    			<StorageDir>${com.wowza.wms.context.VHostConfigHome}/content</StorageDir>
    			...
    </Streams>
    ...
    <Modules>
    ...
                <Module>
                    <Name>SegmentCompleteListener</Name>
                    <Description>SegmentCompleteListener</Description>
                    <Class>com.mycompany.wms.module.SegmentCompleteListener</Class>
                </Module>          
    </Modules>
    Using HttpLiveStreamRecord to start the recording by duration, the log as follow
    INFO server comment - [onWriteComplete]: file: /Library/WowzaMediaServer/content/mystream_2013-08-20-09.43.23.275-CST_0.mp4 duration: 0.0
    INFO server comment - [onWriteComplete]: file: /Library/WowzaMediaServer/content/mystream_2013-08-20-09.43.23.275-CST_1.mp4 duration: 0.0
    INFO server comment - [onWriteComplete]: file: /Library/WowzaMediaServer/content/mystream_2013-08-20-09.43.23.275-CST_2.mp4 duration: 0.0
    INFO server comment - [onWriteComplete]: file: /Library/WowzaMediaServer/content/mystream_2013-08-20-09.43.23.275-CST_3.mp4 duration: 0.0
    INFO server comment - [onWriteComplete]: file: /Library/WowzaMediaServer/content/mystream_2013-08-20-09.43.23.275-CST_4.mp4 duration: 0.0
    The duration always be 0.0 (even i assign a existed file e.g. sample.mp4, the result still be 0.0)

    Yehudi
    Last edited by spiritsoul; 08-19-2013 at 07:11 PM.

  7. #7

    Default

    Hi,

    I did actually think about this later, You need to add the prefix to the stream name that you are passing into the getStreamLength method.

    double overrideDuration = StreamUtils.getStreamLength(appInstance, "mp4:" + file.getName());
    The creates a MediaReader to open the file and read the metadata. It needs the prefix so it knows what type of MediaReader to create.

    Roger.

  8. #8

    Default

    Hi, Roger:

    It works!!
    Thank you very much

    Yehudi

Similar Threads

  1. Start Recording Segment By Duration has a problem?
    By tujixx in forum Live Streaming and Encoder Discussion
    Replies: 2
    Last Post: 02-01-2014, 01:09 AM
  2. How to record only one segment of certain duration?
    By cipris in forum General Forum
    Replies: 3
    Last Post: 03-14-2013, 07:53 AM
  3. Live stream recording using recorder segment duration setter
    By sam.shm in forum Live Streaming and Encoder Discussion
    Replies: 0
    Last Post: 01-31-2013, 01: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
  •