[MPlayer-users] Re: Realaudio dump broken?

alpha0x89 at yahoo.de alpha0x89 at yahoo.de
Sat Mar 27 17:04:17 CET 2004


On Saturday 27 March 2004 16:08, alpha0x89 at yahoo.de wrote:
> I've tested it with
>
>   rtsp://rmlivev8.bbc.net.uk/farm/*/ev7/live24/radio2/live/r2_dsat_g2.ra
>
> The dumped file doesn't play for two reasons:
> 1. RealPlayer requires the stream duration value in the Media Properties
> Header when playing a RealMedia File. But this value is set to 0 for a live
> stream.
> 2. RealPlayer only plays silence when the mime type in the Media Properties
> Header is set to "audio/x-pn-multirate-realaudio-live". It has to be
> replaced by "audio/x-pn-realaudio".
>
> The appended shell script can be used to convert dumped files into files
> that can be played with RealPlayer:
>
>   ./realfix.sh outfile < infile
>
> It can also be used to fix the stream while it is dumped (using bash):
>
>   mkfifo stream.pipe
>   ./realfix.sh outfile < stream.pipe &
>   mplayer -dumpstream -dumpfile stream.pipe rtsp://<URL> &
>   MPLAYER_PID=$!
>   sleep <SECONDS>
>   kill $MPLAYER_PID
>
> The last command ends the recording.

It seems the attachment didn't arrive. That is the second try.



-------------- next part --------------
#!/bin/sh

# mime type in Media Properties Header will be replaced by:
MIME_TYPE=audio/x-pn-realaudio

# Usage:
#   ./realfix.sh outfile < infile
# or
#   ./realfix.sh outfile < pipe.fifo &
#   mplayer -dumpstream -dumpfile pipe.fifo rtsp://URL

# Tested with:
#   GNU bash, version 2.05b.0(1)-release (i586-suse-linux)
#   GNU Coreutils 4.5.8
#   xxd V1.10 27oct98 by Juergen Weigert
# Description:
#   Set stream duration value in the Media Properties Header of a
#   RealMedia File (stream) with a single RealAudion (version 4 or 5)
#   stream dumped with mplayer and replace mime type by $MIME_TYPE.
# References:
#   RealSystem G2 Software Development Kit Developer's Guide.
#     Appendix G: RealMedia File Format (RMFF).
#        http://home.pcisys.net/~melanson/codecs/rmff.htm 
#   getID3(). module for analyzing Real Audio/Video files.
#     http://www.getid3.org/module.audio-video.real.phps

# Copyright (C) 2004-03-27  MPlayer-users
# GNU General Public License

FourCC_RMF=2e524d46  # .RMF
FourCC_PROP=50524f50 # PROP
FourCC_CONT=434f4e54 # CONT
FourCC_MDPR=4d445052 # MDPR
FourCC_DATA=44415441 # DATA
FourCC_INDX=494e4458 # INDX
FourCC_RA=2e7261fd   # .raý
read_ () { dd bs=$1 count=1 2>/dev/null | xxd -p -c $1 -l $1; }
write () { echo $1 | xxd -r -p >>"$OUTFILE"; }
copy () { dd bs=$1 count=1 >>"$OUTFILE" 2>/dev/null; }
skip () { dd bs=$1 count=1 > /dev/null 2>/dev/null; }

if [ -z "$1" ]; then echo usage: $0 outfile >&2; exit 1
elif [ -e "$1" ]; then echo $1 exists!; exit 1
else OUTFILE="$1"; fi
head_size=0
while true; do fourcc=`read_ 4`; case $fourcc in
  $FourCC_RMF | $FourCC_CONT ) write $fourcc
    size=`read_ 4`; ((head_size+=0x$size));
    write $size; copy $((0x$size-8));;
  $FourCC_PROP ) write $fourcc; prop_offset=$head_size
    size=`read_ 4`; ((head_size+=0x$size));
    write $size; copy $((0x$size-8));;
  $FourCC_MDPR ) write $fourcc; mdpr_offset=$head_size
    mdpr_size=`read_ 4`; buf=`read_ 32`
    size=`read_ 1`; buf=$buf$size`read_ $((0x$size))`
    size=`read_ 1`; skip $((0x$size))
    mdpr_size=`printf %.8x $((0x$mdpr_size-0x$size+${#MIME_TYPE}))`
    ((head_size+=0x$mdpr_size));
    write $mdpr_size$buf`printf %x ${#MIME_TYPE}`
    write `echo -n $MIME_TYPE|xxd -p -c $((2*${#MIME_TYPE})) -`
    type_size=`read_ 4`; fourcc=`read_ 4`; version=`read_ 2`
    if [ $fourcc != $FourCC_RA ]; then
      echo "No RealAudio!"; exit 1; fi
    if [ $((0x$version)) -ne 4 -a $((0x$version)) -ne 5 ]; then
      echo "Cannot handle RealAudio version $((0x$version))!"
      exit 1; fi
    write $type_size$fourcc$version; copy 18
    frame_size=`read_ 4`; write $frame_size; copy 4
    bytes_per_min=`read_ 4`; write $bytes_per_min; copy $((0x$type_size-36));;
  $FourCC_DATA ) write $fourcc; data_offset=$head_size
    ((head_size+=18)); copy 14
    frames=`dd bs=$((0x$frame_size+12)) 2>&1 >>"$OUTFILE"|head -n1|cut -f1 -d+`
    ;;
  * ) break;; esac; done
printf %.8x $data_offset | xxd -r -p |\
dd of="$OUTFILE" seek=$((prop_offset+42)) bs=1 count=4 conv=notrunc 2>/dev/null
mdpr_duration=$((1000*60*0x$frame_size*frames/0x$bytes_per_min))
printf %.8x $mdpr_duration | xxd -r -p |\
dd of="$OUTFILE" seek=$((mdpr_offset+36)) bs=1 count=4 conv=notrunc 2>/dev/null
# prevent RealPlayer from buffering forever a few seconds before the end:
index_offset=$((head_size+frames*(0x$frame_size+12)))
echo $FourCC_INDX | xxd -r -p |\
dd of="$OUTFILE" seek=$index_offset bs=1 count=4 2>/dev/null


More information about the MPlayer-users mailing list