Wowza Community

IMediaWriterActionNotify: file write listener

https://www.wowza.com/docs/how-to-use-imediawriteractionnotify-to-programmatically-move-and-rename-recordings-of-live-streams

hi charlie,

It’s a big help for me to move files automatically after a file has been recorded to disk.But I am failed to achieve this goal.

I downloaded the wowza IDE,and created a project and class files.

this is my java code:(to rename the file according to system date)

package com.wowza.wms.plugin.extend.module;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import com.wowza.wms.application.*;
import com.wowza.wms.module.*;
import com.wowza.wms.stream.*;
public class ModuleMediaWriterFileMover extends ModuleBase
{
	class WriteListener implements IMediaWriterActionNotify
	{
		public void onFLVAddMetadata(IMediaStream stream, Map<String, Object> extraMetadata)
		{
			getLogger().info("ModuleWriteListener.onFLVAddMetadata["+stream.getContextStr()+"]");
		}
		public void onWriteComplete(IMediaStream stream, File file)
		{
			//getLogger().info("run here");
			
			String fileDir = file.getAbsolutePath();
			
			String filename = file.getName();
			
			File f_old = file;
			File f_new = null;
			String str = null;
			Date d = new Date();
			SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
			str = date.format(d);
			str = str.replace("-","");
			
			f_old = new File(fileDir,filename);
			f_new = new File(fileDir,"CBSJ_"+str+"_"+filename);
				
			f_old.renameTo(f_new);
			
			getLogger().info("ModuleWriteListener.onWriteComplete["+stream.getContextStr()+"]: "+file);
		}
		
	}
	
	public void onAppStart(IApplicationInstance appInstance)
	{
		//getLogger().info("run here");
		appInstance.addMediaWriterListener(new WriteListener());
		//getLogger().info("run here");
	}
}

Then copy the jar file to the wowza lib folder ,And I added the module to the application.xml file:

<Module>
<Name>ModuleMediaWriterFileMover</Name>
<Description>ModuleMediaWriterFileMover</Description>
<Class>ccom.wowza.wms.plugin.extend.module.ModuleMediaWriterFileMover</Class>
</Module>

But it seems do not work at all.could you have a look? is there any thing wrong in my config procedure?

Is the built-in Module also in the Application.xml?

If you uncomment the logger statement, do you see it in the logs?:

//getLogger().info("run here");

If yes, have you stepped through the following lines, or added logger statements to debug?

You can add try/catch block and put a logger statement in the catch.

Richard

Great! Thanks for the update.

Richard

You can’t have to Modules with the same name. The built-in one is:

<Module>
	<Name>ModuleMediaWriterFileMover</Name>
	<Description>ModuleMediaWriterFileMover</Description>
	<Class>com.wowza.wms.module.ModuleMediaWriterFileMover</Class>
</Module>

This is a built-in Module, you just need to add this to the Application.xml Modules list. Make sure it is last, at the bottom of the list.

If you have built the source code in that Article, and want to use your custom version, take out the built-in version.

Richard

I think you only need one entry for the application.xml of

ModuleMediaWriterFileMover

ModuleMediaWriterFileMover

com.wowza.wms.plugin.extend.module.ModuleMediaWriterFileMover

As suggested in the first post ?

Shamrock

the only thing I can think of is that you have two .jar files conflicting with the same class names.

looking through the code you do need only one entry in Application.xml, so seems to suggest something gone wrong with compiling it in the IDE or not added to the lib directory of the Wowza install.

Shamrock

Hi,thank you Richard for your reply.with your help I solve the problem,thank you very much again.

Hi lechi,

could you share your final codes with us.

thanks

Is the built-in Module also in the Application.xml?

If you uncomment the logger statement, do you see it in the logs?:

//getLogger().info("run here");

If yes, have you stepped through the following lines, or added logger statements to debug?

You can add try/catch block and put a logger statement in the catch.

Richard

Hi,thank you Richard for your reply.with your help I solve the problem,thank you very much again.

Hello, I tried to make this work, created the project and a class file. Pasted lechie’s code and added the following to Application.xml

<Module>
        <Name>ModuleMediaWriterFileMover</Name>
        <Description>ModuleMediaWriterFileMover</Description>
        <Class>com.wowza.wms.module.ModuleMediaWriterFileMover</Class>
</Module>
<Module>
        <Name>ModuleMediaWriterFileMover</Name>
        <Description>ModuleMediaWriterFileMover</Description>
        <Class>com.wowza.wms.plugin.extend.module.ModuleMediaWriterFileMover</Class>
</Module>

and

<Property>
        <Name>fileMoverDestinationPath</Name>
        <Value>${com.wowza.wms.context.VHostConfigHome}/content/acopy</Value>
</Property>
<Property>
        <Name>fileMoverDeleteOriginal</Name>
        <Value>false</Value>
        <Type>Boolean</Type>
</Property>
<Property>
        <Name>fileMoverVersionFile</Name>
        <Value>true</Value>
        <Type>Boolean</Type>
</Property>

The file is moved to destination, but without any date change in the name. Only versioning.

Can you help me? This is my first try to work with java and wowza IDE. I’m sure I messed something.

Nothing happens only with one entry. The file stays in the current dir without any changes.

Thanks! I will keep trying. The custom code doesn’t work for me and I am not so good to debug it as lechie did.