How To Get File Information – Codec/Bitrate

We have been looking at how to do this for a while and finally came up with a reasonable method.

This could be used in conjunction with the AMLST API and do note it does trigger some ‘cupertino’ messages although you may not be using cupertino to stream anything.

private IMediaReaderCupertino mediaReader = null;
private IApplicationInstance appIns = null;
private IMediaStream stream = null;
private String streamName = null;

// Do something here to populate the above. If you look at the AMLST API these can be
// determined quite easily.

// Assume we have a 'streamName' of sample.mp4

// A little naughty here, but it works.
try
{
	IMediaReader reader = MediaReaderFactory.getInstance(appIns, appIns.getVHost().getMediaReaders(), "mp4cupertino");
	if (reader != null)
	{
    	String basePath = appIns.getStreamStoragePath();
	reader.init(this.appIns, this.stream, "mp4cupertino", basePath, streamName);
	reader.open(basePath, streamName);
	mediaReader = (IMediaReaderCupertino)ret;
	}
}
catch (Exception e)
{
	WMSLoggerFactory.getLogger(null).info("Broke it "+e.toString());
}
			
IHTTPStreamerCupertinoIndex indexer = null;
indexer = new HTTPStreamerCupertinoIndexFile();
			
mediaReader.indexFile(indexer);

// You need to close the reader otherwise it leaves the file handle open 			
mediaReader.close();

// We can now do 

int audioBitrate = indexer.getAudioBitrate();
int videoBitrate = indexer.getVideoBitrateAverage();

// Video width and height is useful
// long videoWidth = indexer.getCodecInfoVideo().getFrameWidth(); 
// long videoHeight = indexer.getCodecInfoVideo().getFrameHeight();

// Video and Audio codec strings are useful
// String audioCodecStr = indexer.getCodecInfoAudio().toCodecsStr();
// String videoCodecStr = indexer.getCodecInfoVideo().toCodecsStr();



Elements to note

- This is NOT a complete example and does require work, but provided as a guide
- You can get all the required information when using the AMLST API to hook this up
- Although the logs show cupertino indexing it can be used with any protocol as this just reports when the codec information is being found


Comments are closed.