Fixing Flash videos (FLV) for use with Adobe Flash Media Server (FMS)

Using Adobe Flash Media Server to stream Flash videos (FLVs) you might hit on the following error messages:
  • In FMS's core.00.log:
    2008-12-18      00:33:55        3687    (w)2611179      Warning from libflv.so: File contains bad meta data : /opt/adobe/fms/applications/vod/media/somedir/200812171225_327.flv (TCFLVData.cpp:490). -
  • In the output of flvcheck (a utility shipped with FMS in the tools subdirectory to check FLVs for FMS compatibility):
    08-12-18 22:50:59       Error:  -9      Invalid FLV message footer.     200812171225_327.flv
    or
    08-12-18 22:51:12       Error:  -11     Found backward timestamp.       200812171228_328.flv
You can fix these errors using ffmpeg.

FFmpeg has a "copy" mode of processing: it copies raw codec data as is. You can specify the copy codec for both video and audio streams, in which case the streams remain untouched (thus video quality stays the same), only the container metadata is regenerated (ie. fixed if it was "broken"). So running the following command on an FLV that FMS had problems with fixes it:
ffmpeg -i input.flv -vcodec copy -acodec copy output.flv

I've created a small shellscript to check and repair all "broken" FLVs in a directory (and its subtree):
#!/bin/sh

flvcheck=/opt/adobe/fms/tools/flvcheck
logfile=flvfix.log

if [ -f "${logfile}" ]; then
  rm "${logfile}"
fi

for file in $(find . -type f -iname '*.flv'); do
  dir=$(dirname "${file}")
  base=$(basename "${file}")
  "${flvcheck}" -q "${file}" > /dev/null 2>&1
  if [ $? -ne 0 ]; then
    mv "${file}" "${file}.orig"
    ffmpeg -i "${file}.orig" -vcodec copy -acodec copy "${file}" > /dev/null 2>&1
    if [ $? -eq 0 ]; then
      #note: you might want to change owner or permissions of the new file
      #      so your streamer/webapp can access it
      #chown fms "${file}"
      echo "${file} was fixed" >> "${logfile}"
      "${flvcheck}" -n "${file}" >> "${logfile}"
    else
      echo "${file} was not fixed (ffmpeg failed)" >> "${logfile}"
      mv "${file}.orig" "${file}"
    fi
  fi
done

Put it into a script (eg. flvfix.sh), assign execute permissions (chmod a+x flvfix.sh) and run in the directory where you store your FLVs. Eg.
cd /mnt/fms_storage
~/bin/flvfix.sh
The script will create a logfile with the names of all files that it had fixed (or not fixed if ffmpeg failed). It will also keep a backup of the original FLV (ie. it renames the original *.flv into *.flv.orig).

PS: I've fetched ffmpeg from SVN on 4th Dec 2008 and compiled from source (with support for all sorts of codecs), but since the "copy" mode does not involve decoding of the streams, I assume you could do the same fix with a stock (repository) version of ffmpeg in Debian or Ubuntu.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

backward time stamp in live flvs

I have this issue coming in my live fms streams , can anybody tell how it can be resolved .
there was something regarding this on this link also
http://askmeflash.com/index.php?p=qlist
Richard

Re: backward time stamp in live flvs

Unfortunately I don't know a thing about live streaming with FMS (at least not yet). A quick Google search revealed nothing of use. I'm sorry that I couldn't help.

Syndicate content