Wowza Community

Split recording every 10 min

Hi Guys,

I do live streaming for 10 Tv Channels using one wowza server. I want to record each channel in different folder and file time should be around 10 minute I do recording by FMLE , I prefer to use WMS how I can achieve that?


Take a look at these two posts:


I can handle one at a time. this is one.


Not sure how precise you can get with this method. You should change StreamType “live-record” to “live”. The LiveStreamRecord api is recording in your case. That might even help. There is built-in filemover


I suspect that the recordings you have made so far are from Wowza recording the live stream with StreamType “live-record”

Make sure you change the StreamType to “live”. Then try to use the hourly recording module.

When recording starts with this module, you should see a comment in the logs “ModuleStreamRecord.startRecording: [params]”

Look for errors in the access and error log. Try running Wowza in stand-alone mode (/bin/startup.bat) so you see logs in real-time


I have not worked with that example. You will have to test.


Thanks Richard,

I will give a try and get you back,


I have a post here, please take a look

Ok, here is the post:

I’m using wowza media server2 prepetual 2.2.4 build27452

Flash Media Encoder 3.2 with (MP4:+streamname)

streamrecord hourly

I built the follwoing code using wowza IDE. it works good

package streamrecord.hourly.monthlyrollover;

import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import com.wowza.wms.application.*;
import com.wowza.wms.module.*;
import com.wowza.wms.plugin.integration.liverecord.*;

public class ModuleStreamRecord extends ModuleBase implements IMediaStreamNotify {
	private IApplicationInstance appInstance;
	private String timezone;
	private StreamTimer streamTimer;
	private int date;
	private int startHour = 0;
	private int endHour = 23;
	private int hourOfDay = -1;
	private boolean record = false;
	private PublishNotifier publishNotifier;
	private List<String> streams;
	public static final int FORMAT_UNKNOWN = 0;
	public static final int FORMAT_FLV = 1;
	public static final int FORMAT_MP4 = 2;
	private Map<String, ILiveStreamRecord> recorders = null;

	private class StreamTimer extends Thread {
		private boolean doQuit = false;

		public synchronized void quit() {
			doQuit = true;

		public void run() {
			while (true) {
				try {
					TimeZone tz = TimeZone.getTimeZone(timezone);
					Calendar cal = Calendar.getInstance(tz);

					date = cal.get(Calendar.DATE);
					int prevHour = hourOfDay;
					hourOfDay = cal.get(Calendar.HOUR_OF_DAY);
					int start = startHour;
					int end = endHour;
					if (start > end && hourOfDay > start) {
						end += 24;

					if (end < start && hourOfDay < end) {
						start -=24;

					if (hourOfDay >= start && hourOfDay < end) {
						record = true;
					} else {
						record = false;

					streams = appInstance.getMediaCasterStreams().getMediaCasterNames();

					if (prevHour != hourOfDay && record) {
						for (String streamName : streams) {
							IMediaStream stream = appInstance.getStreams().getStream(streamName);
							appInstance.getVHost().getHandlerThreadPool().execute(new DoStartRecording(stream, streamName));
					} else if(!record) {
						for (String streamName : streams) {
							ILiveStreamRecord recorder = recorders.remove(streamName);
							if(recorder != null)
					synchronized (this) {
						if (doQuit) {
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block

	public void onAppStart(IApplicationInstance appInstance) {
		this.appInstance = appInstance;
		WMSProperties props = appInstance.getProperties();
		startHour = props.getPropertyInt("startHour", 0);
		endHour = props.getPropertyInt("endHour", 24);
		timezone = props.getPropertyStr("timezone", "America/Chicago");

		recorders = Collections.synchronizedMap(new HashMap<String, ILiveStreamRecord>());
		publishNotifier = new PublishNotifier();
		streamTimer = new StreamTimer();
		streamTimer.setName("RecordController-" + appInstance.getApplication().getName());

	public void onAppStop(IApplicationInstance appInstance) {

		// cleanup any recorders that are still running
		synchronized (recorders) {
			Iterator<String> iter = recorders.keySet().iterator();
				String streamName =;
				ILiveStreamRecord recorder = recorders.get(streamName);
				getLogger().info("  stopRecording: "+streamName);
		recorders = null;
		publishNotifier = null;

	private synchronized void startRecording(IMediaStream stream) {
		String streamAlias = stream.getName().substring(0, stream.getName().indexOf(".stream"));
		if (!streamAlias.isEmpty()) {
			String outputPath = appInstance.getStreamStorageDir()+"/"+String.format("%02d", date); //day;
			boolean append = false;
			File path = new File(outputPath);
			if (path.exists()) {
				File outputFile = new File(path.getPath()+File.separator+streamAlias+"_"+String.format("%02d", hourOfDay)+".mp4");
				Date today = new Date();
				if (!(outputFile.lastModified() < today.getTime() - 86400000)) {
					append = true;
			} else {
			recordStream(stream, FORMAT_MP4, append, outputPath+File.separator+streamAlias+"_"+String.format("%02d", hourOfDay)+".mp4", false, true, true);
	private void recordStream(IMediaStream stream, int format, boolean append, String outputPath, boolean versionFile, boolean startOnKeyFrame, boolean recordData)

		String streamName = stream.getName();
		// if a format was not specified then check the stream prefix and choose accordingly
		if (format == FORMAT_UNKNOWN)
			format = FORMAT_FLV;
			String extStr = stream.getExt();
			if (extStr.equals("mp4"))
				format = FORMAT_MP4;
		String params = "stream:"+streamName;
		params += " format:"+(format==FORMAT_MP4?"mp4":"flv");
		params += " append:"+append;
		if (outputPath != null)
			params += " outputPath:"+outputPath;
			File writeFile = stream.getStreamFileForWrite();
			params += " outputPath:"+writeFile.getAbsolutePath();
		params += " versionFile:"+versionFile;
		params += " startOnKeyFrame:"+startOnKeyFrame;
		params += " recordData:"+recordData;
		getLogger().info("ModuleStreamRecord.startRecording: "+params);
		// create a stream recorder and save it in a map of recorders
		ILiveStreamRecord recorder = null;
		// create the correct recorder based on format
		if (format == FORMAT_MP4)
			recorder = new LiveStreamRecorderMP4();
			recorder = new LiveStreamRecorderFLV();
		// add it to the recorders list
		ILiveStreamRecord prevRecorder = recorders.get(streamName);
		if (prevRecorder != null)
		recorders.put(streamName, recorder);
		// if you want to record data packets as well as video/audio
		// Set to true if you want to version the previous file rather than overwrite it
		// If recording only audio set this to false so the recording starts immediately
		// start recording
		recorder.startRecording(stream, outputPath, append);

		public void onMediaStreamCreate(IMediaStream stream) {

		public void onMediaStreamDestroy(IMediaStream stream) {
			if(!stream.isPlay()) {
				ILiveStreamRecord recorder = recorders.remove(stream.getName());
				if (recorder != null)
	private class PublishNotifier implements IMediaStreamActionNotify {

		public void onPause(IMediaStream stream, boolean isPause,
				double location) {
			// TODO Auto-generated method stub

		public void onPlay(IMediaStream stream, String streamName,
				double playStart, double playLen, int playReset) {
			// TODO Auto-generated method stub

		public void onPublish(IMediaStream stream, String streamName,
				boolean isRecord, boolean isAppend) {
				appInstance.getVHost().getHandlerThreadPool().execute(new DoStartRecording(stream, streamName));

		public void onSeek(IMediaStream stream, double location) {
			// TODO Auto-generated method stub

		public void onStop(IMediaStream stream) {
			// TODO Auto-generated method stub

		public void onUnPublish(IMediaStream stream, String streamName,
				boolean isRecord, boolean isAppend) {
			ILiveStreamRecord recorder = recorders.remove(streamName);

			if (recorder != null)
				// stop recording
	private class DoStartRecording implements Runnable {
		private IMediaStream stream;
		private String streamName;
		private DoStartRecording(IMediaStream stream, String streamName) { = stream;
			this.streamName = streamName;

		public void run() {
			List<String> mediaCasters = appInstance.getMediaCasterStreams().getMediaCasterNames();
			if (mediaCasters.contains(streamName)) {
				int lockCount = appInstance.getMediaCasterStreams().getMediaCaster(streamName).getLockCount();
				if (lockCount > 0)

with the follwoing Application Conf

		<!-- Uncomment to set application level timeout values
			StorageDir path variables
			${com.wowza.wms.AppHome} - Application home directory
			${com.wowza.wms.ConfigHome} - Configuration home directory
			${com.wowza.wms.context.VHost} - Virtual host name
			${com.wowza.wms.context.VHostConfigHome} - Virtual host config directory
			${com.wowza.wms.context.Application} - Application name
			${com.wowza.wms.context.ApplicationInstance} - Application instance name
			<!-- LiveStreamPacketizers (separate with commas): cupertinostreamingpacketizer, smoothstreamingpacketizer, sanjosestreamingpacketizer, cupertinostreamingrepeater, smoothstreamingrepeater, sanjosestreamingrepeater -->
			<!-- Properties defined here will override any properties defined in conf/Streams.xml for any streams types loaded by this application -->
		<!-- HTTPStreamers (separate with commas): cupertinostreaming, smoothstreaming, sanjosestreaming -->
			<!-- RTP/Authentication/[type]Methods defined in Authentication.xml. Default setup includes; none, basic, digest -->
			<!-- RTP/AVSyncMethod. Valid values are: senderreport, systemclock, rtptimecode -->
			<!-- Properties defined here will override any properties defined in conf/RTP.xml for any depacketizers loaded by this application -->
			<!-- Properties defined here will override any properties defined in conf/MediaCasters.xml for any MediaCasters loaded by this applications -->
			<!-- Properties defined here will override any properties defined in conf/MediaReaders.xml for any MediaReaders loaded by this applications -->
			<!-- Properties defined here will override any properties defined in conf/MediaWriter.xml for any MediaWriter loaded by this applications -->
			<!-- Properties defined here will override any properties defined in conf/LiveStreamPacketizers.xml for any LiveStreamPacketizers loaded by this applications -->
			<!-- Properties defined here will override any properties defined in conf/HTTPStreamers.xml for any HTTPStreamer loaded by this applications -->
				<Description>Client Logging</Description>

		<!-- Properties defined here will be added to the IApplication.getProperties() and IApplicationInstance.getProperties() collections -->


i want to record exactly 1 hour then split to new folder but it never happened it records less or more and never exceeded 55 min

I also want to use Media mover module to move the every day stream to new folder

please advice


I already used the file mover it works as charm

all i need to do recording the stream every one hour exactly 60 min then split and start with new one

Wowza recording sometimes 20 min sometimes 1:45 min i don’t know how to control the time. When i use stream type:Live i should start stream every time by my self while i want the stream to be recorded automatically, when Wowza starts.

Hi Richard,

I’ll start over in new machine, install WMS, IDE, compile the module start it ant feed you

Back, but i just need confirmation for 2 things:

  1. Automatically start recording

  2. The recording hourly rollover mo thy module needs no extra modifications.

And I will come back after I finish this


Ok Richard!