天天看点

red5+ffmpeg

1. download and install jdk-1.7

2. download and install jre-1.7

3. download and install apache-ant-1.9

4. set home environment variable

insert these into /etc/profile

JAVA_HOME=/usr/local/jdk1.7.0_11

JRE_HOME=/usr/local/jre1.7.0_11

ANT_HOME=/usr/local/ant

export JAVA_HOME

export JRE_HOME

export ANT_HOME

5. download and install red5-1.0.0

   mv red5-1.0.0 /usr/local/red5

6. run red5

/usr/local/red5/red5.sh

7. install red5 demo

http://192.168.137.66:5080/

click install

choose oflaDemo and click install

8. change webapps/oflaDemo/index.html file

<script type='text/javascript'>^M

  jwplayer('mediaspace').setup({^M

    'flashplayer': 'player.swf',^M

    'file': 'hobbit_vp6.flv',^M

    'streamer': 'rtmp://192.168.137.66/oflaDemo',^M

    'controlbar': 'bottom',^M

    'width': '848',^M

    'height': '360'^M

  });^M

</script>^M

<script type='text/javascript'>^M

  jwplayer('mediaspace2').setup({^M

    'flashplayer': 'player.swf',^M

    'file': 'hobbit_vp6.flv',^M

    'streamer': 'rtmpt://192.168.137.66:5080/oflaDemo',^M

    'controlbar': 'bottom',^M

    'width': '848',^M

    'height': '360'^M

  });^M

</script>^M

9. web player

http://192.168.137.66:5080/oflaDemo/index.html

A. ffmpeg + red5

A.1 streaming ffmpeg rtmp output to red5

ffmpeg -re -f mpegts -i film.ts -c:a libfaac -ac 1 -c:v libx264 -s 352x288 -aspect 4:3 -b:v 300k -f flv 'rtmp://localhost/live/sss1 live=1'

A.2 setup live player

cd webapps/live

cp ../oflaDemo/index.html .

cp ../oflaDemo/jwplayer.js .

cp ../oflaDemo/player.swf .

A.3 edit live/index.html

<script type='text/javascript'>^M

  jwplayer('mediaspace').setup({^M

    'flashplayer': 'player.swf',^M

    'file': 'sss1.flv',^M

    'streamer': 'rtmp://192.168.137.66/live',^M

    'controlbar': 'bottom',^M

    'width': '848',^M

    'height': '360'^M

  });^M

</script>^M

<script type='text/javascript'>^M

  jwplayer('mediaspace2').setup({^M

    'flashplayer': 'player.swf',^M

    'file': 'sss1.flv',^M

    'streamer': 'rtmpt://192.168.137.66:5080/live',^M

    'controlbar': 'bottom',^M

    'width': '848',^M

    'height': '360'^M

  });^M

</script>^M

A.4 web player

http://192.168.137.66:5080/live/index.html

A.5 ffmpeg decode rtmp stream from red5

ffmpeg -re -i 'rtmp://192.168.137.66/live/sss1 live=1' -an -c:v rawvideo -s 352x288 -f rawvideo tt.yuv

Notes:

Above, the live=1 is a must, or ffmpeg will fail on connect red5 rtmp stream server.

 the live stream should be packeted with audio and video, or if only with video data, 

above command will hung long time, or delay long time.

for example:

stream only video to red5

ffmpeg -re -f mpegts -i film.ts -an -c:v libx264 -s 352x288 -aspect 4:3 -b:v 300k -f flv 'rtmp://localhost/live/sss1 live=1'

decode stream from red5

ffmpeg -re -i 'rtmp://192.168.137.66/live/sss1 live=1' -an -c:v rawvideo -s 352x288 -f rawvideo tt.yuv

ffmpeg will hung long time or delay long time.

but.

ffmpeg -re -f mpegts -i film.ts -c:a libfaac -ac 1 -c:v libx264 -s 352x288 -aspect 4:3 -b:v 300k -f flv 'rtmp://localhost/live/sss1 live=1'

ffmpeg -re -i 'rtmp://192.168.137.66/live/sss1 live=1' -an -c:v rawvideo -s 352x288 -f rawvideo tt.yuv

this will be ok.