Wowza Community

Set duration to RTMP MP3 Streaming

I’ve tried the following code for MP3 streaming on RTMP, I could successfully set the play start time and duration of the MP3 file.

For example, if start time is set to 10s and duration is set to 30s, the JW Player will start playing at 10s (JW Player will display 0s) and keep playing for 30s.

But the problem is that the JW Player will just always show the whole duration of the MP3 file which is 24m00s.

How can the correct duration be displayed on JW player? Does anyone have any experience on it?

Thanks a lot!!

public class MediaReaderMP3InjectMetadata extends MediaReaderMP3{ 
	public List<ByteBuffer> getMetadata()
	{
 		List<ByteBuffer> 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("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;
	}

The code is working fine for MP4 but not MP3.

This might help. Add these Property settings to the Application.xml /MediaReader Properties container:

<Property>
   <Name>calculateMoreAccurateFrameSize</Name>
   <Value>true</Value>
   <Type>Boolean</Type>
</Property>
<Property>
   <Name>calculateMoreAccurateFrameWindow</Name>
   <Value>200</Value>
   <Type>Integer</Type>
</Property>

Richard

This might help. Add these Property settings to the Application.xml /MediaReader Properties container:

<Property>
   <Name>calculateMoreAccurateFrameSize</Name>
   <Value>true</Value>
   <Type>Boolean</Type>
</Property>
<Property>
   <Name>calculateMoreAccurateFrameWindow</Name>
   <Value>200</Value>
   <Type>Integer</Type>
</Property>

Richard

It doesn’t work.

Do you have any code that would modify the metadata of MP3?