# Set start and duration to rtmp is indistinct

**URL:** <https://community.wowza.com/t/set-start-and-duration-to-rtmp-is-indistinct/39869>\
**Category:** Wowza Developer Dojo\
**Tags:** wowza-streaming-server-java-api\
**Created:** [January 24, 2013, 4:08pm UTC](https://community.wowza.com/t/set-start-and-duration-to-rtmp-is-indistinct/39869 "2013-01-24T16:08:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Corentin\_LEBLANC](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@Corentin\_LEBLANC](https://community.wowza.com/u/Corentin_LEBLANC)\
**Post date:** [January 24, 2013, 4:08pm UTC](https://community.wowza.com/t/set-start-and-duration-to-rtmp-is-indistinct/39869/1 "2013-01-24T16:08:32Z")

</div>

Hello,

I’m using Wowza 3.5 and JWPlayer 6 and I’m trying to specify start and duration for on demand video (rtmp).

For that :

- I’m using an override for play method on a class who extends ModuleBase :

[PHP]

public void play(IClient client, RequestFunction function, AMFDataList params) throws MalformedURLException {

URL url = new URL(client.getPageUrl());

Map\<String,String\> urlParameters = getQueryMap(url.getQuery());

//Calcul de l’extrait au besoin.

double start = Double.parseDouble(urlParameters.get(“tcin”));

double duration = Double.parseDouble(urlParameters.get(“tcout”)) - start;

String streamName = params.getString(PARAM1);

IMediaStream stream =getStream(client, function);

//On réaffecte la durée du stream.

AMFDataList customDataList = new AMFDataList();

customDataList.add(“play”);

customDataList.add(0.0);

customDataList.add(“null”);

customDataList.add(streamName);

customDataList.add(new AMFDataItem(start)); // start value in milliseconds

customDataList.add(new AMFDataItem(duration)); //duration (-1 means play to the end). Value in milliseconds.

customDataList.add(new AMFDataItem(true)); //reset

invokePrevious(this, client, function, customDataList);

//Stockage de la durée de l’extrait dans les propriétés du stream pour l’extraire ensuite dans la classe MyMediaReaderMP4InjectMetadata

stream.getProperties().put(“overrideDuration”, duration/1000);

}

[/PHP]

- I’m using an override for getMetadata method on a class who extends MediaReaderH264 (and set its className in MediasReader.xml) :

[PHP]

public List getMetadata(){

List ret = super.getMetadata();

WMSLogger getLogger = WMSLoggerFactory.getLogger(null);

// Here the calculated duration stored by above is extracted.

// Note that the default duration is used if there is no duration property in the stream, so simple video streaming will work as usual

double overrideDuration = this.stream.getProperties().getPropertyDouble(“overrideDuration”, (double) this.duration / 1000); // Value in seconds.

getLogger.info("CIMUMediaReaderMP4InjectMetadata\_overrideDuration: " + overrideDuration);

while(true){

if (ret == null)

break;

if (ret.size() \<= 0)

break;

ByteBuffer packet = ret.get(0);

AMFDataList myMetadata = new AMFDataList(packet);

AMFDataMixedArray dataObj = (AMFDataMixedArray)myMetadata.get(1);

dataObj.put(“duration”, new AMFDataItem(overrideDuration)); // duration in seconds.

byte[] data = myMetadata.serialize();

ByteBuffer newPacket = ByteBuffer.wrap(data);

ret.set(0, newPacket);

break;

}

return ret;

}

[/PHP]

It’s approximately working, but i’m encountering a strange behavior :

I’m trying to extract 5 seconds from video @ 10seconds from beginning

=\> I’m setting start value to 10000

=\> I’m setting duration value to 5000

=\> I’m setting overrideDuration value to 5000

From webInterface, when I play video, **its duration is longer than 5 seconds (approximately 7 seconds)** but value on JWPlayer is 5

=\> JWPlayer slider is out of 0 - 5duration @ end of video

Screen :

![](http://img23.imageshack.us/img23/8740/wowza.png)

Video are really longer than 5 seconds but duration was set to 5000 in play method.

Any ideas for that ?

Thanks for reading

Epoks
