Converting FLV files to MP4 via Transcode Post Processing

Red5 Pro records files as flv, but many people have asked about how to convert those files easily to mp4 so that more media players can be used to view them.


The TranscodePostProcessor uses FFMpeg to transcode a supplied FLV into an MP4. If used in combination with the S3UploaderPostProcessor after conversion is completed, the MP4 will be uploaded to S3 alongside the FLV which is stored there.


The Transcoder uses two native applications: FFMpeg and an h.264 encoder, either x264 or OpenH264.

Having FFMpeg with h.264 support as a dependency carries licensing information along with its use / deployment. There are two primary licenses we are concerned with herein, GNU General Public License and GNU Lesser General Public License. GPL being the most restrictive of the two and requiring the implementer to meet their specific requirements (see the license and/or consult your lawyer).

Installing FFMpeg via apt-get

Per How to install FFmpeg on Ubuntu 14.04

FFmpeg has been removed from Ubuntu 14.04 and was replaced by Libav. This decision has been reversed so that FFmpeg is available now in Ubuntu 15.04 again, but there is still no official package for 14.04. The following will direct you how to install FFmpeg from mc3man ppa.

First, add the mc3man ppa:

sudo add-apt-repository ppa:mc3man/trusty-media

And confirm the resulting message by pressing [enter].

Also note that with apt-get a sudo apt-get dist-upgrade is needed for initial setup & with some package upgrades. Press [ENTER] to continue or ctrl-c to cancel adding it. Update the package list:

sudo apt-get update
sudo apt-get dist-upgrade

Now FFmpeg is available to be installed with apt:

sudo apt-get install ffmpeg

Server Configuration

The writer post processor used by FLVWriter is configured in the server's common configuration file: (red5pro)/conf/red5-common.xml. The example below displays the configuration with the TranscodePostProcessor (note - this bean exists in the file, you just need to modify & add the writer post processor value):

<bean id="flv.impl" class="">
  <property name="cache">
    <ref bean="object.cache"/>
  <property name="writerPostProcessors">

This configuration indicates the transcoder writerPostProcessor which implements IPostProcessor will be executed after a file is finalized by the FLVWriter.

If you choose to use both the S3UploaderPostProcessor and the TranscodePostProcessor methods, then the bean should look like:

<bean id="flv.impl" class="">
  <property name="cache">
    <ref bean="object.cache"/>
  <property name="writerPostProcessors">

Additional FFMpeg compilation detail may be found here: Ubuntu FFMpeg Compilation Guide

Compiling FFMpeg with OpenH264

Alternatively to installing via apt-get, you can compile FFMpeg with OpenH264.

  • Get the FFMpeg source via git: git clone ffmpeg
  • Change directory to ffmpeg: cd ffmpeg
  • Make a build directory inside the ffmpeg directory: mk ffmpeg_build
  • Go back to the top-level: cd ..
  • Get the OpenH264 (Version 1.5) source code (download as zip)
  • Unzip into openh264 directory
  • Enter the openh264 directory: cd openh264
  • Modify the openh264/Makefile changing PREFIX to point at the full path to your ffmpeg/ffmpeg_build directory; Example: PREFIX=/workspace/infrared5/booma/pov-booma-server-side/ffmpeg/ffmpeg_build
  • Save the Makefile
  • Execute make install
  • Enter the ffmpeg directory, execute the build script below
# Red5 Pro FFMpeg build script for Transcoding


function build_ff
./configure \
    --disable-everything \
    --disable-doc --disable-ffplay --disable-ffprobe --disable-ffserver \
    --enable-libopenh264 \
    --disable-avdevice \
    --disable-programs \
    --enable-ffmpeg \
    --disable-indevs --disable-outdevs \
    --disable-swscale-alpha \
    --disable-symver --disable-iconv \
    --disable-bsfs --disable-videotoolbox \
    --disable-protocols \
    --enable-protocol=file \
    --enable-protocol=rtmp \
    --disable-decoders \
    --enable-decoder=aac \
    --enable-decoder=h264 \
    --enable-decoder=h263 \
    --enable-decoder=flv \
    --enable-decoder=nellymoser \
    --disable-encoders \
    --enable-encoder=aac \
    --enable-encoder=libopenh264 \
    --disable-filters \
    --enable-filter=aresample \
    --disable-parsers \
    --enable-parser=aac \
    --enable-parser=h264 \
    --disable-demuxers \
    --enable-demuxer=flv \
    --disable-muxers \
    --enable-muxer=flv \
    --enable-muxer=mp4 \
    --disable-shared \
    --enable-static \
    --enable-small \
    --extra-cflags="-Os -fpic $ADDI_CFLAGS -I$(pwd)/ffmpeg_build/include" \
    --extra-ldflags="$ADDI_LDFLAGS -L$(pwd)/ffmpeg_build/lib" \
    --pkg-config-flags="--static" \
    --disable-debug --prefix=$(pwd)/ffmpeg_build \
make && make install

Lastly, copy the ffmpeg executable from ffmpeg_build to a known location which will be used in your conf/ file as the value for the ffmpeg.path entry. Note: the file has GPL (x264) uncommented by default. If you are using OpenH264, then you need to uncomment the LGPL command template:

#ffmpeg.template=%s -y -report -async 1 -i %s -acodec aac -b:a 128k -ar 44100 -vcodec libopenh264 -pix_fmt yuv420p -profile:v baseline -level 3.0 %s