Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFmpeg command: stream generated raw video over RTSP

I'm looking into using FFmpeg for streaming an output generated by an application to another system in the same network. However, I find the list of commands a little daunting and hard to understand. So I hope I can ask your help in the matter.

My current usecase: I have a Unity application which has a separate output stream of video and using a plugin I'm able to save that output to a videofile. The command used is to save this to file is:

ffmpeg -y -f rawvideo -vcodec rawvideo -pixel_format rgba -colorspace bt709 -video_size 1280x720 -framerate 30 -loglevel warning -i - -pix_fmt yuv444p -preset ultrafast -crf 0 test.mp4

The output format and such are already correct, but I'd like to stream this output directly over a network now, preferably using RTSP. Using the command below, where I replaced the test.mp4 at the end with udp://127.0.0.1:23000 to test streaming over UDP, but this returns an IOException in Unity.

Any help in guiding me in the right direction is greatly appreciated. Thanks in advance!

like image 870
Jan Discart Avatar asked Sep 10 '25 13:09

Jan Discart


2 Answers

You have to define your output streaming source at end of the command. You need to define your ffmpeg command all elements to match with the streaming format.For example if you are streaming over UDP you can use command similar to this.

ffmpeg -i (your input) -r 10 -vcodec mpeg4 -f mpegts udp://127.0.0.1:1234

You can test UDP stream using VLC or ffplay player. However if you want to stream over RTSP, easiest solution would be to use a media server such as Wowza or Red5. Red5 is an open source media server and it is bit confusing for beginners. Wowza is a paid media server but provides better documentation and support service. If you are using RTMP protocol you can use command similar to this.

ffmpeg -i (your input) -r 10 -vcodec libx264 -pix_fmt yuv420p -f flv "rtmp://(IpAddress):(portnumber)/live/myStream flashver=FMLE/3.0\20(compatible;\20FMSc/1.0) live=myApplication pubUser=myRTMP connection pubPasswd=password"

Also you can use ffserver (Ffmpeg media server) for RTMP. But it is only available for Linux operating systems.

like image 98
Wijaya Avatar answered Sep 13 '25 13:09

Wijaya


Here an example ffmpeg line I used before, format is mpeg-ts (video h264+audio aac), might help:

/path_to_ffmpeg/bin/ffmpeg -ignore_unknown -probesize 100000000 -analyzeduration 100000000 -loglevel verbose -thread_queue_size 2048 -err_detect aggressive -fflags +nobuffer+discardcorrupt -re -i - -aspect 16:9 -s 1920x1080 -c:v:0 libx264 -x264-params force-cfr=1 -preset superfast -vb 6000k -minrate 6000k -maxrate 6000k -bufsize 6000k -muxrate 7000k -nal-hrd cbr -flags +ilme+ildct -top 1 -g 25 -r 25 -pix_fmt yuv420p -vbsf h264_mp4toannexb -c:a:0 libfdk_aac -strict -2 -b:a:0 128k -mpegts_service_type advanced_codec_digital_hdtv -metadata service_provider='PROVIDER' -metadata service_name='hd_low' -mpegts_flags system_b -flush_packets 0 -f mpegts 'udp://DEST_IP:DEST_PORT?pkt_size=1316&reuse=1&localaddr=INTERFACE_IP&bitrate=7000000&fifo_size=18618&overrun_nonfatal=1'

Replace these:
DEST_IP is you guessed it, destination ip i.e. 192.168.1.5
DEST_PORT is destination port, i.e.: 1234
INTERFACE_IP is if device has multiple ethernet interface you should enter interface ip to use for output, or just enter device's ip. i.e.:192.168.1.3. This is optional.

You sen use destination ip as one of PC's on the network and use VLC to play stream on that PC (open network stream and enter udp://@dest_ip:port).

Hope that helps.

like image 43
the kamilz Avatar answered Sep 13 '25 13:09

the kamilz