Recording MP4 files (with H.264 video and AAC audio) with HDFVR and WOWZA

Published by bursuc on | 7 Comments

Documentation, Flash Media Server, HDFVR, Red5, Research, Wowza

Facebook1Twitter0Google+1Email

If you are using Wowza Streaming Engine (Wowza 4.0) or newer just follow the steps from the documentationThis article is relevant only for versions of Wowza up to 3.6

Introduction

With the launch of Flash Player 11 (4th Ocotober 2011) Adobe introduced the H.264 video codec in Flash Player for video encoding. For those of you who don’t know yet what H.264 is, it is a standard for video compression, and it is currently one of the most commonly used formats for the recording, compression, and distribution of high definition video. The final drafting work on the first version of the standard was completed in May 2003.

The  Problems:

There are 3 major media servers on the market: FMIS, Red5 and Wowza. All three are supported by HDFVR, our video recording product.

From these three only FMIS and Wowza can produce MP4 files. Red5 can’t save the audio and video data in MP4 files.

None of them can produce MP4 files with AAC audio because the only audio encoding codecs available in Flash Player  are NellyMoser’s ASAO and Speex. Neither of these two audio codecs are recommended with MP4 containers.

In addition FMIS produces MP4 files using an industry-standard recording technology known as “fragments” or “moof atoms.” Some MPEG-4 compatible tools and players do not support moof atoms and therefore cannot recognize files recorded by Adobe Media Server unless they are post-processed with a tool called F4V Post Processor . This tool can be downloaded from here.

The solution:

After digging deeper into the problem we’ve came across the Transcoder AddOn for Wowza. The Transcoder AddOn takes a live stream, decodes the video and audio and then re-encodes the data to suit your needs (delivery to iOS devices, etc.).  It seems it works just as good for recording streams.

To produce MP4 files with H.264 video and AAC audio we need the Transcoder AddOn to

  1. take in the audio and video data coming from HDFVR,
  2. decode the audio and re-encode it with AAC
  3. put the initial video data and the new AAC audio data in an .MP4 file

With a few configurations tweaks for HDFVR we’ve managed to do that. Let’s see how we’ve done it.

Requirements

Here’s everything we need (download and install step by step):

  • STEP 1HDFVR build number 508 (beta version)  or later (installation details here)
  • STEP 2: Wowza 3 (trial, installation guide) or later
  • STEP 3: For Wowza 3.0.3 you need this Wowza patch (more details below)
  • STEP 4: Transcoder AddOn for Wowza 3,  this comes along with the trial version of Wowza 3 and is included with Wowza 3.5 (download, installation guide)
  • STEP 5: 64 bit OS (Linux or Windows) and 64 bit Java runtime (download)

When running Wowza on Windows you will also need:

  • .NET Framework 3.5.1 Feature (download)
  • Desktop Experience  if you run Windows Server (details)

After installing everything, including the Transcoder AddOn you have to start Wowza in standalone mode. To do so you have to run startup.bat (on Windows) or startup.sh (on Linux). These startup files are inside the Wowza/bin folder.

Once Wowza is started, at the beginning of the log in the command line window, you should see a line telling you that the Transcoder AddOn is available. The message should look something like this: INFO server comment – Transcoder Streams Available.



In case your Transcoder AddOn appears as unavailable you should  check the log messages in the console window that show the  Java version. The correct line should look like this: INFO server comment – Java Architecture: 64. If this is not correct you should try installing the Java runtime again and set your Java path, details here.

Important note about Wowza versions:

===
Wowza 3.0.3

After testing with the latest Wowza – at the time of writing this article it was 3.0.3 - and the Transcoder AddOn we’ve found that the recorded mp4 files could not be played  with any external player. After researching a little bit we’ve came across a patch (Patch 3 for Wowza 3.0.3) that fixed this problem. The patch can be found here : http://www.wowza.com/downloads/WowzaMediaServer-3-0-3/WowzaMediaServer3.0.3-patch3.zip .
You will need to replace the files inside of your Wowza  3.0.3 installation folder with the ones inside the patch (only the files contained inside the patch).

===
Wowza 3.0.4 and later 3.0.x versions

Work as expected and do not need to be patched.

===

Wowza 3.1.0

We could not get it to transcode properlly and produced unusable .MP4 files.

===

Wowza 3.1.1, 3.1.2 and later (including 3.5 and 3.6)

Work as expected however the final MP4 file will not be created when the user presses STOP in HDFVR (build 508). It will only be created when:

  • the client records another video (re-records)
    OR
  • the client disconnects

Until one of the 2 events happen Wowza will not create the final .mp4 file and the existing .mp4 file will be unplayable. You will know Wowza has not closed the .mp4 dile and is waiting for one of the 2 events to happen when you see a .tmp file in the content folder:

.temp video file in Wowza 3.0.4file

.temp video file in Wowza 3.0.4file

After getting everything above installed and running follow these steps to configure HDFVR and Wowza/Transcoder addon for recording MP4 files with AAC audio and H.264 video.

Step 1 : Setting up HDFVR

1.1 Set the proper Audio Video Quality Profile in HDFRV

First we need to tell HDFVR we’re using Wowza + the Transcoder AddOn.

Inside the video quality profile of your choice set:

  • <vcodec> tag to h264_w_t and
  • <snd> tag to speex10

By default HDFVR uses the following video quality profile files depending on the HTML page that embeds HDFVR:

  • VideoRecorder.html -> audio_video_quality_profiles/320x240x30x90.xml
  • VideoRecorder-api.html -> audio_video_quality_profiles/320x240x30x90.xml
  • VideoRecorder-sd-16by9.html -> audio_video_quality_profiles/wide/640x360x30x90.xml
  • VideoRecorder-hd.html -> audio_video_quality_profiles/wide/1280x720x30x90.xml

Here’s the <vcodec> and <snd> tags properly set to h264_w_t in the 320x240x30x90.xml video quality profile file.

This will produce a stream with video encoded with H.264 and audio encoded with Speex or NellyMoser (the Transcoder can decode both so the sound codec choice does not matter) but upon reaching the media server Wowza will know that it has to transcode the audio to AAC.

speex10 will produce an audio stream containing 16khz audio at 42.2kbits/s.

According to the transcoder guide, Wowza does not know to decode NellyMoser’s ASAU audio codec so don’t use it, use Speex.

1.2 Configure  Application.xml

The next step is configure the Application.xml file for HDFVR. The Application.xml file for HDFVR is found inside Wowza/conf/hdfvr directory. Here’s what you need to change from the default Application.xml with which HDFVR is delivered:

  • set the <StreamType> tag  to  live-record.
  • uncomment the <LiveStreamPacketizers> and make sure it’s set to cupertinostreamingpacketizer, smoothstreamingpacketizer, sanjosestreamingpacketizer
  • uncomment the <Transcoder> and <HTTPStreamers> tags and make sure:
    • the <LiveStreamTranscoder> tag is set to transcoder (this will enable the Transcoder addon)
    • the <Templates> tag is set to hdfvr.xml
    • the <HTTPStreamers> tag is set to cupertinostreaming,smoothstreaming,sanjosestreaming

If  these options are not present in your Application.xml please add them. Make sure that they are  not commented.

In the end your Application.xml should look like this:

<Root>
	<Application>
		<!-- Uncomment to set application level timeout values
		<ApplicationTimeout>60000</ApplicationTimeout>
		<PingTimeout>12000</PingTimeout>
		<ValidationFrequency>8000</ValidationFrequency>
		<MaximumPendingWriteBytes>0</MaximumPendingWriteBytes>
		<MaximumSetBufferTime>60000</MaximumSetBufferTime>
		<MaximumStorageDirDepth>25</MaximumStorageDirDepth>
		-->
		<Connections>
			<AutoAccept>true</AutoAccept>
			<AllowDomains></AllowDomains>
		</Connections>
		<!--
			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

		-->

		<Streams>
			<StreamType>live-record</StreamType>
			<StorageDir>${com.wowza.wms.context.VHostConfigHome}/content</StorageDir>
			<KeyDir>${com.wowza.wms.context.VHostConfigHome}/keys</KeyDir>
			 <LiveStreamPacketizers>cupertinostreamingpacketizer, smoothstreamingpacketizer, sanjosestreamingpacketizer</LiveStreamPacketizers>
			<Properties>
			</Properties>
		</Streams>

		<Transcoder>
			<!-- To turn on transcoder set to: transcoder -->
			<LiveStreamTranscoder>transcoder</LiveStreamTranscoder>
			<!-- [templatename].xml or ${SourceStreamName}.xml -->
			<Templates>hdfvr.xml</Templates>
			<ProfileDir>${com.wowza.wms.context.VHostConfigHome}/transcoder/profiles</ProfileDir>
			<TemplateDir>${com.wowza.wms.context.VHostConfigHome}/transcoder/templates</TemplateDir>
			<Properties>
			</Properties>
		</Transcoder>

		<HTTPStreamers>cupertinostreaming,smoothstreaming,sanjosestreaming</HTTPStreamers>

		<SharedObjects>
			<StorageDir></StorageDir>
		</SharedObjects>
		<Client>
			<IdleFrequency>-1</IdleFrequency>
			<Access>
				<StreamReadAccess>*</StreamReadAccess>
				<StreamWriteAccess>*</StreamWriteAccess>
				<StreamAudioSampleAccess></StreamAudioSampleAccess>
				<StreamVideoSampleAccess></StreamVideoSampleAccess>
				<SharedObjectReadAccess>*</SharedObjectReadAccess>
				<SharedObjectWriteAccess>*</SharedObjectWriteAccess>
			</Access>
		</Client>
		<RTP>
			<!-- RTP/Authentication/[type]Methods defined in Authentication.xml. Default setup includes; none, basic, digest -->
			<Authentication>
				<PublishMethod>digest</PublishMethod>
				<PlayMethod>digest</PlayMethod>
			</Authentication>
			<!-- RTP/AVSyncMethod. Valid values are: senderreport, systemclock, rtptimecode -->
			<AVSyncMethod>senderreport</AVSyncMethod>
			<MaxRTCPWaitTime>12000</MaxRTCPWaitTime>
			<IdleFrequency>75</IdleFrequency>
			<RTSPSessionTimeout>90000</RTSPSessionTimeout>
			<RTSPMaximumPendingWriteBytes>0</RTSPMaximumPendingWriteBytes>
			<RTSPBindIpAddress></RTSPBindIpAddress>
			<RTSPConnectionIpAddress>0.0.0.0</RTSPConnectionIpAddress>
			<RTSPOriginIpAddress>127.0.0.1</RTSPOriginIpAddress>
			<IncomingDatagramPortRanges>*</IncomingDatagramPortRanges>
			<!-- Properties defined here will override any properties defined in conf/RTP.xml for any depacketizers loaded by this application -->
			<Properties>
			</Properties>
		</RTP>

		<Modules>
			<Module>
				<Name>base</Name>
				<Description>Base</Description>
				<Class>com.wowza.wms.module.ModuleCore</Class>
			</Module>
			<Module>
				<Name>properties</Name>
				<Description>Properties</Description>
				<Class>com.wowza.wms.module.ModuleProperties</Class>
			</Module>
			<Module>
				<Name>logging</Name>
				<Description>Client Logging</Description>
				<Class>com.wowza.wms.module.ModuleClientLogging</Class>
			</Module>

			<Module>
				<Name>flvplayback</Name>
				<Description>FLVPlayback</Description>
				<Class>com.wowza.wms.module.ModuleFLVPlayback</Class>
			</Module> 

			<Module>
				<Name>customServerHDFVR</Name>
				<Description>Server HDFVR</Description>
				<Class>com.naicuandnaicu.server.MyModule</Class>
			</Module>
		</Modules>
		<!-- Properties defined here will be added to the IApplication.getProperties() and IApplicationInstance.getProperties() collections -->
		<Properties>
		</Properties>
	</Application>
</Root>

You can download the above Application.xml code/file from here: http://codeviewer.org/view/code:26eb.

1.3 Setting up a Wowza application for playback:

Now we are ready to record mp4 files on Wowza but how about playing them inside of HDFVR.

Because the <StreamType> tag is set to live-record inside Application.xml after you finish recording you will not be able to play back the file. The stream can only be played only while it’s being recorded because Wowza treats it as a live stream.

Not to worry though because we have a solution. Wowza is storing the recorded files inside a folder (Wowza/content) that is shared by all the applications so all we need to do now is set up another app with a different <StreamType> tag that will recognize the files as recorded streams and play them back properly.

On your Wowza media server you will have to copy the hdfr_play files (they’re in the HDFVR build 508 (beta version) archive) as a normal application and the rest is done automatically by HDFVR.

The Application.xml for the hdfr_play app (Wowza/conf/hdfvr_play) should have the <StreamType> tag set to record.

For those of you who do not use HDFVR and want a better understanding of how it works the principle is pretty straight forward: HDFVR connects to one application (hdfvr) with its set of settings and uses the Transcoder AddOn to record mp4 files. To play the files HDFVR connects to another application (hdfvr_play) with a different set of settings.

Step 2: Setting up the Transcoder

Inside Application.xml for the hdfvr app (Wowza/conf/hdfvr) mentioned the following things are specified:

  • the <Transcoder> tag contains the information  about where the configuration file for the addon can be found,
  • the <TemplateDir> tag contains the path to the templates folder,
  • the <Templates> tag contains the name of the template file to use and it has the following value hdfvr.xml .

Here’s the contents of hdfvr.xml, copy and paste it in a hdfvr.xml file inside your Wowza/transcoder/templates folder.

<Root>
	<Transcode>
		<Encodes>
			<!-- Example Encode block for source, not required unless Member of StreamNameGroup. -->
			<Encode>
				<Enable>true</Enable>
				<Name>aac</Name>
				<StreamName>mp4:${SourceStreamName}</StreamName>
				<Video>
					<!-- H.264, PassThru, Disable -->
					<Codec>PassThru</Codec>
					<Bitrate>${SourceVideoBitrate}</Bitrate>
					<Parameters>
					</Parameters>
				</Video>
				<Audio>
					<!-- AAC, PassThru, Disable -->
					<Codec>AAC</Codec>
					<Bitrate>48000</Bitrate>
				</Audio>
				<Properties>
				</Properties>
			</Encode>
		</Encodes>
		<Decode>
		</Decode>
		<StreamNameGroups>
		</StreamNameGroups>
		<Properties>
		</Properties>
	</Transcode>
</Root>

Here’s the above doe explained:

  • The <StreamName> tag will tell the Transcoder to produce an mp4 file.
  • The <Video> tag will leave the video untouched  as the <Codec> tag is set to  PassThru and the <Bitrate> tag is set to the maintain the source’s one.
  • The <Audio> tag will encode audio as AAC set through the <Codec> tag and a bitrate of 48000 set through the <Bitrate> tag.

Results

After all this set up is time to run HDFVR in the browser. Press the record button and have fun. After you finished recording press play. If the recorded file does not play go back and see the section about the hdfvr_play app. To see the recorded mp4 files go to Wowza/content folder.

Conclusion

I m sure most of you know  why MP4  files are useful but for those of you who can’t quite get why this is a major feature here it goes: Flash Player is not supported by iOS and Android Internet Browsers thus .flv files can not be played on these devices. With this feature you will now be able to play you recordings straight away on any type of  OS.

There are many possibilities offered by the Transcoder AddOn not just recording mp4 files but saving different copies of your file with different quality settings , making playlists and so forth (the documentation is available here) , all you have to do is to configure the Transcoder configuration file hdfvr.xml to suit your needs.

7 thoughts on “Recording MP4 files (with H.264 video and AAC audio) with HDFVR and WOWZA

  1. Pingback: Solved: Recording MP4 with AAC audio, H.264 video | Learn from Lisa

  2. Karel Boek

    A nice solution! Just one thing to consider is that the TransCoder AddOn is not free and licensed PER INCOMING STREAM. So embedding your recorder in a web site and offering it to the public would require you buy a license for every simultaneous user; eg. if 100 users want to use the recorder at the same time, it requires 100 TransCoder licenses. That might be quite costly if the solution becomes a success.

    Reply
  3. Pingback: URL

      1. Carter

        I’m using the latest version of Wowza and I’ve made sure that Transcoder Streams Available – Unlimited is showing in the console.

        Reply
  4. Mike

    I’m also having the same problem, latest wowza, exact copies of hdfvr.xml and the Application.xml and logging successful transcoder abilities.

    Still recording only in flv.

    Could you share your original conf/Application.xml file?

    Reply
Add Comment Register



Leave a Reply

Your email address will not be published. Required fields are marked *


× five = 30

To view this page ensure that Adobe Flash Player version 12.0.0.44 or greater is installed.

Get Adobe Flash Player

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>