How can I convert RTMP nginx livestream from Flv to mp4 file? - nginx

I have an RTMP server running using nginx that records the livestream into flv files but what I want to do is record the files into a mp4 format... Here’s my nginx.conf file:
I want when I rtmp livestream going I can convert it from flv to an mp4 file... How can I do this? Here is my nginx.conf file:
​
user  www-data;
worker_processes auto;
rtmp_auto_push on;
events {
    worker_connections  1024;
}
rtmp {
    server {
        listen 1935;
        chunk_size 4096;
        application s9-live {
            exec ffmpeg -i rtmp://localhost:1935/s9-rtmp/$name
            \-c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1280x720 -preset superfast -profile:v baseline rtmp://localhost:1935/s9-rtmp/$name;
            live on;
            meta copy;
            hls_cleanup off;
            record all;
            record_path /rec/videos;
            record_max_size 1k;
            record_unique on;
            record_suffix %y%m%d_%H%M%S.flv;
            exec_record_done ffmpeg -y -i $path -acodec libmp3lame -ar 44100 -ac 1 -vcodec libx264 $dirname/$basename.mp4;
        }
    }
}
http { 
    default_type application/octet-stream;
    server { 
        listen 8000; 
        location /tv { 
            root /tmp/hls; 
        }
\# This URL provides RTMP statistics
        location /stats {
            rtmp_stat all;
        }
        location /control {
            rtmp_control all;
        }
    }
    types {
        application/vnd.apple.mpegurl m3u8;
        video/mp2t ts;
        text/html html;
    } 
}
The application runs well without any issues at all the only if possible that I would like to know is how to get an mp4 or the recorded stream converted from the flv files.

You already have the command to convert flv to mp4 in your config:
exec_record_done ffmpeg -y -i $path -acodec libmp3lame -ar 44100 -ac 1 -vcodec libx264 $dirname/$basename.mp4;
While recording is on, you will only see an flv file. Once the recording is done, exec_record_done is triggered and the flv is converted to an mp4 file. You will then have an flv and a corresponding mp4 in your folder.

Related

What different video formats RTMP streaming support?

In almost all the online references related to FFMPEG and RTMP, I am getting -f as flv. Is there any other formats.
(I have tried avi, mpeg and h264, but no success.)
Currently, I am running following command -
ffmpeg -re -i video.mp4 -f s16le -ar 48000 -ac 2 -i audio.wav -c copy -f flv rtmp://192.168.0.1:1935/myapp/stream
The issues with -f flv in my case are -
It doesn't support 48k sample rate.
None of my input videos are in flv format (I have to convert it to flv externally).
P.S. - I am using VLC as RTMP player.
EDIT -
I am getting following error with 48k audio file -
[flv # 0x5650ba7afb80] FLV does not support sample rate 48000, choose from (44100, 22050, 11025)

Sometimes HLS chunks does not generate in /tmp/hls directory

I am working on an adaptive HLS solution using Nginx RTMP module as a streaming server and VideoJs as a client. I have completed the setup i.e. NGINX configurations and client sample in VideoJs.
NGINX Configurations:
nginx.txt
I am using this Ffmpeg command to generate stream:
ffmpeg -re -i /home/user/Downloads/test.mp4 -vcodec libx264 -vprofile baseline -g 30 -acodec aac -strict -2 -f flv rtmp://192.168.1.68/live
My problem is that sometimes the Nginx does not generate .ts and .m3u8 files in /tmp/hls directory when I issue the above ffmpeg command. I have also enabled the nginx-rtmp module logs but they are only giving me access information and I am not getting any logs in error logs.
Do let me know if more information is required. Any help will be appreciated.
Thanks,

Using ffmpeg to transcode/transmux HLS to RTMP for nginx simulcast not working

I want to take an HLS stream and transcode it to RTMP and simulcast it with the nginx RTMP module.
It's not working, however (I have it placed in the application section of the RTMP module).
exec ffmpeg -i -re http://<HLS>.m3u8 -acodec aac -vcodec libx264 -f flv rtmp://localhost/live/test;
When I try to view my RTMP stream in VLC, it is not loading. I have tried several variations of that ffmpeg directive, none have worked. Any advice? If you need to see more of my config file, I can provide that, but this server has been working previously perfectly when sending video over via a Teradek encoder. This new wrinkle is just not working.
EDIT: Just had a thought. It’d probably help to have the codec information of the incoming HLS stream. Here it is:
Video Codec: H264 - MPEG-4 AVC
Resolution: 640x360
Frame rate: 24
Decoded format: Planar 4:2:0 YUV
Audio Codec: MPEG AAC Audio (mp4a)
Channels: Stereo
Sample rate:48000Hz
If you run in terminal
ffmpeg -i -re http://<HLS>.m3u8 -acodec aac -vcodec libx264 -f flv rtmp://localhost/live/test;
are you able to play the stream in VLC?

Transcode H264 stream into mpeg2 with ffmpeg and nginx-rtmp module

I am using nginix web server and nginx-rtmp module for managing my video stream encoded in h264. Here is my nginx conf:
rtmp {
server {
listen 1935;
application big {
live on;
exec ffmpeg -re -i rtmp://localhost:1935/$app/$name -vcodec
libx264 -vprofile baseline -acodec libvo_aacenc -ac 1 -ar 441000
-f flv rtmp://localhost:1935/hls/${name};
}
}
application hls
{
live on;
hls_path /usr/local/nginx/html/video;
}
}
it works well in browser, however because my mobile client is Adobe Air it would only work on Android but not Apple, because Apple doesn't support H264 encoding through AIR applications, so I was trying to transcode the stream to something supported for example mpeg. And this is how I changed my ffmpeg:
exec ffmpeg -re -i rtmp://localhost:1935/$app/$name -vcodec
mpeg2video -acodec copy -b:v 10M -b:a 128k
-f mpegts rtmp://localhost:1935/hls/${name};
However it just won't show the video not in a browser nor on device, my assumption is that it probably failed to transcode.
Maybe I am missing something ? Any ideas are highly appreciated.
Thank you.
You probably got your answer already, but just in case:
You are not using the module properly,
1) On iOS you need to point your browser to http://localhost:80/hls/${name} to get the HLS stream.
2) You are missing in the config the http section to generate the HLS stream
See here for details: How can we transcode live rtmp stream to live hls stream using ffmpeg?

How do I change a website video to m3U8 format?

Can anyone walk me through the steps of taking a video from our website and changing it to a m3U8 so we can then insert it to our app dashboard to have video on our app?
Download FFMPEG
then download a http segmenter e.g. apple's one or the google one
Now run the command prompt using cmd.
Go to bin directory of the FFMPEG from the command prompt.
Type ffmpeg –h to find various option of the ffmpeg.
This sample code converts a mp4 to a ts file:
ffmpeg -i myvideo.mp4 -acodec libfaac -ar 48000 -ab 64k -s 320x320 -vcodec libx264 -vbsf h264_mp4toannexb -f mpegts myvideo.ts
then run the segmenter to break up the ts file into smaller segments
segmenter -i myvideo.ts -d 20 -o la -x test/myvideo.m3u8
add the following to your htaccess file if you are running on apache
.M3U8 application/x-mpegURL
.ts video/MP2T
that's about it
Use gstreamill, which can transcode video to m3u8 format.

Resources