arut / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
13.45k stars 3.51k forks source link

Pseudo-live streaming - newbie question #654

Open rcruzmar opened 9 years ago

rcruzmar commented 9 years ago

I have read all of the questions on this forum but could not find the answer I am looking for. Hopefully someone can point me in the right direction.

I have been using Wowza for the past 6 months for its ability to allowing pseudo-live streaming of videos to my clients. I am new to nginx-rtmp-module and after a couple of days of reading and trying I was finally able to get VoD to work using RTMP.

What I would like to do is to have nginx-rtmp-module stream videos as if it were a TV channel (pseudo-live). I am not very clear regarding that subject and how it relates to this module however, I am hoping someone could point me in the right direction.

So the question comes down to this... am I able to create a stream from this module similar to a TV channel or do I need to use another software like ffmpeg, GStreamer/LiquidSoap?

Appreciate any answers...

sergey-dryabzhinsky commented 9 years ago

No you can't. You need other software to push stream into nginx-rtmp.

rcruzmar commented 9 years ago

Thanks for the reply. Since it can't be done this way, what Linux-based software would you recommend to push the stream to nginx-rtmp?

nxtreaming commented 9 years ago

So the question comes down to this... am I able to create a stream from this module similar to a TV channel or do I need to use another software like ffmpeg, GStreamer/LiquidSoap?

I use ffmpeg + playlist to achieve pseudo-live streaming (7x24h live streaming).

rcruzmar commented 9 years ago

@nxtreaming - I'd be interested in learning what approach you use to combine ffmpeg and playlists. Could I email you directly? Thanks.

nxtreaming commented 9 years ago

I use the following implementation:

/usr/local/bin/ffmpeg -loglevel warning -xerror -re -f concat -i /path/to/your_playlist.txt -c copy -f flv rtmp://127.0.0.1/vod/live24h_stream_name

//the content of your_playlist.txt : file /main_disk/dota2_programs/d1029.mp4 file /mnt/backbone/dota2_programs/d2071.mp4 file /mnt/backbone/dota2_programs/d2072.mp4 file /mnt/backbone/dota2_programs/d2073.mp4 file /mnt/backbone/dota2_programs/d2074.mp4 file /mnt/backbone/dota2_programs/d2075.mp4 file /mnt/backbone/dota2_programs/d2076.mp4 file /mnt/backbone/dota2_programs/d2077.mp4 file /mnt/backbone/dota2_programs/d2078.mp4 file /mnt/backbone/dota2_programs/d2079.mp4 file /mnt/backbone/dota2_programs/d2080.mp4 file /mnt/backbone/dota2_programs/d2081.mp4 file /mnt/backbone/dota2_programs/d2082.mp4 file /mnt/backbone/dota2_programs/d2083.mp4 file /mnt/backbone/dota2_programs/d2084.mp4 file /mnt/backbone/dota2_programs/d2085.mp4 file /mnt/backbone/dota2_programs/d2086.mp4 file /mnt/backbone/dota2_programs/d2087.mp4 file /mnt/backbone/dota2_programs/d2088.mp4 file /main_disk/dota2_programs/d1020.mp4 file /main_disk/dota2_programs/d1021.mp4 file /main_disk/dota2_programs/d1022.mp4 file /main_disk/dota2_programs/d1024.mp4 file /main_disk/dota2_programs/d1025.mp4 file /main_disk/dota2_programs/d1026.mp4 file /main_disk/dota2_programs/d1027.mp4 file /main_disk/dota2_programs/d1028.mp4 file /main_disk/dota2_programs/d1030.mp4 file /mnt/backbone/dota2_programs/d2089.mp4 file /mnt/backbone/dota2_programs/d2090.mp4 file /mnt/backbone/dota2_programs/d2091.mp4 file /mnt/backbone/dota2_programs/d2092.mp4 ....

Note: all files in playlist MUST have the same file format and the same encoder configration(eg: same format,codecs,bitrate, fps...)

rcruzmar commented 9 years ago

Thanks for your example. Thanks for the tip about having all videos have the same format, bitrate, etc. I had read about that before and I had to re-encode several videos I thought were already encoded correctly.

I have a command similar to what you posted but best I can do is build all of the .TS and M3U8 files and stream it once. My command:

ffmpeg -f concat -i vid_list.txt \
    -vcodec libx264 -c:a copy \
    -profile:v high -preset fast -b:v 1000k -threads 0 \
    -framerate 30 -video_size 1280x720 -flags +loop \
    -crf 15 -g 46 -bufsize 3000k -maxrate 6000k \
    -force_key_frames 10 -f segment -segment_list /tmp/hls_test/playlist.m3u8 \
    -segment_list_flags +live -segment_time 10 \
    -movflags faststart -f flv rtmp://localhost:1935/hls_test/playlist

How do you account for "looping" your channel to operate 24x7? If you don't mind the question, to which platform are you streaming? I am streaming to a Roku private channel I developed but can't get the video stream to restart when completed. I may have to do minor code change.

nxtreaming commented 9 years ago

I just re-publish the stream to live platforms( several Chinese Live Platforms) if the playlist file has reached EOF. Streaming platforms will automatically relay the stream.

I do not directly publish to 3rd streaming platform, I firstly publish a pseudo live stream to the local machine (rtmp://127.0.0.1/vod/abc) , and then I relay the pseudo live stream to 3rd streaming platform.

PS: you MUST take care the timestamp (DTS/PTS) if you re-loop

Please reference my codes: https://gist.github.com/nxtreaming/2c6eb9c03fd82b23b80f