Stream mp4 video via ffmpeg and rtmp using red5

15,888

Try this command. This is the command i usually use to stream a video file as a live stream

ffmpeg -re -i localFile.mp4 -c copy -f flv rtmp://server/live/streamName

The -re option tells FFmpeg to read the input file in realtime and not in the standard as-fast-as-possible manner. With -c copy (alias -acodec copy -vcodec copy ) I’m telling FFmpeg to copy the essences of the input file without transcoding, then to package them in an FLV container (-f flv) and send the final bitstream to an rtmp destination (rtmp://server/live/streamName).

The JWplayer source is as follows

<html>
<head><title>TEST PLAYER</title>
</head>
<body>
<script type="text/javascript" src="jwplayer.js"></script>
<div id="myElement">Loading the player...</div>
<script type="text/javascript">
jwplayer("myElement").setup({
file: "rtmp://[ip-address]/live/streamname",
    });
</script>
</body>
</html>

Make sure the jwplayer.js and player.swf are in the correct locations.

Share:
15,888

Related videos on Youtube

Kevin - Dhinesh babu
Author by

Kevin - Dhinesh babu

Angular Developer at Datawens tech.

Updated on September 18, 2022

Comments

  • Kevin - Dhinesh babu
    Kevin - Dhinesh babu over 1 year

    I need to stream mp4 video file via FFMPEG and stream the output to RED5 using RTMP protocol. I am using the following command to do this. It's encoding perfectly, but it does not play when I embed with jwplayer.

    ffmpeg -i http://xxxxxx.com/adv.mp4 -acodec copy -vcodec copy -f flv rtmp://xxxxxxx/live/stream1
    

    it's given the following result:

    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'http://xxxxxxxxxxxx.com/adv.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: mp42isomavc1
        creation_time   : 2013-10-14 11:57:33
        encoder         : HandBrake 0.9.9 2013052900
      Duration: 00:04:50.99, start: 0.000000, bitrate: 912 kb/s
        Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 1920x360 [PAR 847:1920 DAR 847:360], 795 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
        Metadata:
          creation_time   : 2013-10-14 11:57:33
        Stream #0.1(und): Audio: aac, 11025 Hz, stereo, s16, 116 kb/s
        Metadata:
          creation_time   : 2013-10-14 11:57:33
    Output #0, flv, to 'rtmp://xxxxxxxxx/live/stream1':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: mp42isomavc1
        creation_time   : 2013-10-14 11:57:33
        encoder         : Lavf53.21.1
        Stream #0.0(und): Video: libx264, yuv420p, 1920x360 [PAR 847:1920 DAR 847:360], q=2-31, 795 kb/s, 1k tbn, 25 tbc
        Metadata:
          creation_time   : 2013-10-14 11:57:33
        Stream #0.1(und): Audio: libvo_aacenc, 11025 Hz, stereo, 116 kb/s
        Metadata:
          creation_time   : 2013-10-14 11:57:33
    Stream mapping:
      Stream #0.0 -> #0.0
      Stream #0.1 -> #0.1
    Press ctrl-c to stop encoding
    frame= 7266 fps=563 q=-1.0 Lsize=   32544kB time=290.64 bitrate= 917.3kbits/s    
    video:28220kB audio:4130kB global headers:0kB muxing overhead 0.601155%
    

    After this i embed the RTMP url to my jwplayer

    <script type='text/javascript'>
                jwplayer('mediaspace').setup({
                'flashplayer': 'http://xxxxxxxxxx/tools/js/jwplayer.flash.swf',
                'stretching': 'exactfit',
                'type': 'rtmp',     
                'file':'stream1',
                'autostart': 'true',            
                'controlbar': 'bottom',
                'streamer':'rtmp://xxxxxxxx/live/', 
    
                'width': '889',
                'height': '410',
    
                });
                </script>
    

    After done this my player show the following error

    Error loading stream
    Could not connect to the server
    

    how can i solve this and stream like live stream....???

  • Kevin - Dhinesh babu
    Kevin - Dhinesh babu over 10 years
    how can i embed with jwplayer ???
  • Unnikrishnan
    Unnikrishnan over 10 years
    which version of jwplayer u using?
  • Kevin - Dhinesh babu
    Kevin - Dhinesh babu over 10 years
    jwplayer 6.0 above
  • Unnikrishnan
    Unnikrishnan over 10 years
    No error here. Check command once more. Try changing the order of options
  • Kevin - Dhinesh babu
    Kevin - Dhinesh babu over 10 years
    how can i add multi input file
  • Unnikrishnan
    Unnikrishnan over 10 years
    This is the command i used ffmpeg -re -i /usr/local/content/sample.mp4 -c copy -f flv rtmp://192.168.1.34:1935/live/test
  • Kevin - Dhinesh babu
    Kevin - Dhinesh babu over 10 years
    my friend i said mulit input like following syntax ffmpeg -re i- inputfile1.mp4,inputfile2.mp4,inputfile3.mp4 -c copy -f flv rtmp://xxxxx/live/test like this how can i command
  • Unnikrishnan
    Unnikrishnan over 10 years
    I think you cant add multiple files like this using this command.First try the command i said. Its applicable for a single file.
  • Unnikrishnan
    Unnikrishnan over 10 years
    Glad it worked :)
  • Kevin - Dhinesh babu
    Kevin - Dhinesh babu over 10 years
    can we use vlc to ffmpeg and rtmp for getting multiple file ?
  • Unnikrishnan
    Unnikrishnan over 10 years
    I have nt worked with vlc much. I guess you can open multiple instances of FFMpeg. I mean just execute the commands in different tabs for different files. But the system load will go up. Anyways try it.
  • Unnikrishnan
    Unnikrishnan over 10 years