What different video formats RTMP streaming support? - nginx

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)

Related

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

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.

FFMpeg - Print Date and Time during recording like surveillance

I need to record video from RaspberryPi, using this Bash script:
#!/bin/sh
/usr/bin/ffmpeg -f video4linux2 -input_format h264 -video_size 320x240 -framerate 15 -i /dev/video0 -vcodec copy -an "/var/ayron/videotrap/videos/pctrace_$(date +"%Y_%m_%d_%H_%M_%S").h264"
In this way, I can report the date and time of start recording. But I need to show on video the Date and Time during registration. Which kind of filter must I use?
Thanks for your supply.
Use drawtext filter:
/usr/bin/ffmpeg -f video4linux2 -input_format h264 -video_size 320x240 -framerate 15 -i /dev/video0 -an -vf "drawtext=text='%{localtime\:%Y_%m_%d_%H_%M_%S}'" "/var/ayron/videotrap/videos/pctrace_$(date +"%Y_%m_%d_%H_%M_%S").h264"
You can't filter and stream copy the video at the same time so -vcodec copy has been omitted.
If you want to use colons (:) in the time then you'll have to do some ugly escaping as shown in How to drawtext colon with localtime in ffmpeg -filter_complex?

ffmpeg and nginx - restream with audio reencoding

I use nginx and ffmpeg to restream video from my provider. Previously I use ffmpeg with arguments where I reencoding video and reencoding audio, because my server is to slow I resigned from reencoding.
So now, I use that command :
ffmpeg -re -i http://link.somelink.com:6565/21d12d1/17233 -map 0 -c copy -bsf:a aac_adtstoasc -f flv -flvflags no_duration_filesize rtmp://test_ip/canal/stream
This works only when my provider streaming with aac audio codec, but sometimes my provider change audio codec to ac3. And then this doesn't work. I try something like this :
ffmpeg -thread_queue_size 32768 -re -i http://link.somelink.com:6565/21d12d1/17233 -c:v copy -c:a aac -f flv -flvflags no_duration_filesize rtmp://test_ip/canal/stream
And it all looks like it's all right in console with ffmpeg, but my restreaming video doesn't work. Ngnix throws 304 exception sometime.
Any suggestions?
Please help,
It's very important for me...
Ac3 is not in supported codecs list. You should encode your stream accordingly.
RTMP supports only a limited number of codecs. The most popular RTMP video codecs are H264, Sorenson-H263 (aka flv) and audio codecs AAC, MP3, Nellymoser, Speex. If your video is encoded with these codecs (the most common pair is H264/AAC) then you do not need any conversion. Otherwise you need to convert video to one of supported codecs.
https://github.com/arut/nginx-rtmp-module/wiki/Getting-started-with-nginx-rtmp

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?

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