Raspberry Pi how to convert RTSP stream h265 to h264 - ffmpeg

I am trying to convert H265 rtsp stream to H264.
ffmpeg -rtsp_transport tcp -i 'rtsp://admin:admin123#192.168.1.42:554/stream2' -f lavfi -i aevalsrc=0 -vcodec copy -acodec aac -map 0:0 -map 1:0 -c:v libx264 -pix_fmt yuv420p -shortest -strict experimental -f flv rtmp://localhost:1935/live/stream
When I use this command it gives this error.
[tcp # 0x23f13b0] Connection to tcp://localhost:1935 failed: Connection refused
[rtmp # 0x23f1270] Cannot open connection tcp://localhost:1935
rtmp://localhost:1935/live/stream: Connection refused

If FFmpeg should act as a server you must add the parameter -listen 1.
ffmpeg -i 'rtsp://admin:admin123#192.168.1.42:554/stream2' {...} -f flv -listen 1 rtmp://localhost:1935/live/stream

Related

ffmpeg stream an audio file to Telegram rtmp server

I tried to stream an mp3 file to a Telegram RTMP live using the following command:
ffmpeg -re -i 1.mp3 -c copy -f mp3 rtmps://dc4-1.rtmp.t.me/s/145158:AtyF3rrME2nHEkqGA
But I couldn't hear any sound in the stream.
You should specify the codecs explicitly.
The following is the simplest working command:
ffmpeg -i your_input -c:v libx264 -c:a aac -f flv rtmps://dcx-y.rtmp.t.me/s/YOUR_KEY
Here is a more advanced example from #tgbeta:
ffmpeg -stream_loop -1 -re -i your_input -c:v libx264 -preset veryfast -b:v 3500k -maxrate 3500k -bufsize 7000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 -ar 44100 -f flv rtmps://dcx-y.rtmp.t.me/s/YOUR_KEY
Change -f mp3 by -f flv.
Example:
ffmpeg -re -i 1.mp3 -c:a copy -f flv rtmps://dc4-1.rtmp.t.me/s/145158:AtyF3rrME2nHEkqGA

FFMPEG: How to record video from one source and audio from other source?

I'm using this command to record camera ip:
ffmpeg -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i rtsp://192.168.1.105/media/video1 -c:a aac -c:v copy -flags +global_header -strftime 1 -f segment -map 0:0 -segment_time 30 -reset_timestamps 1 file_%Y-%m-%d_%H-%M-%S.mp4
But i would like to add an audio from a different camera ip which use this stream rtsp://192.168.1.106/media/video1
Is this possible?
Sure.
Use
ffmpeg
-use_wallclock_as_timestamps 1 -rtsp_transport tcp -i rtsp://192.168.1.105/media/video1
-use_wallclock_as_timestamps 1 -rtsp_transport tcp -i rtsp://192.168.1.106/media/video1
-c:a aac -c:v copy ...
If both the inputs have audio, you should map to make sure the correct inputs are chosen, by adding -map 0:v -map 1:a.

How to re-stream h265 RTSP stream using FFMPEG

I have written a small piece of code to re-stream camera RTSP stream on Nginx stream server using FFMPEG.
Everything working fine, my re-stream RTSP on to Nginx stream server using following FFMPEG command:
ffmpeg -rtsp_transport tcp -i 'rtsp://212.78.10.88:554/stream' -f lavfi -i aevalsrc=0 -vcodec copy -acodec aac -map 0:0 -map 1:0 -shortest -strict experimental -f flv rtmp://localhost:1935/live/stream
My basic problem is H265 and H265+. FFMPEG failed to re-stream H265 format streams. I tried differently command params but no luck.
Any body know how to re-stream H265 and + in FFMPEG?
Finally, I solved the issue to re-stream h265 stream.
I just used following arguments in command to solve this issue.
-c:v libx264 -pix_fmt yuv420p
and final command is:
ffmpeg -rtsp_transport tcp -i 'rtsp://212.78.10.88:554/stream' -f lavfi -i aevalsrc=0 -vcodec copy -acodec aac -map 0:0 -map 1:0 -c:v libx264 -pix_fmt yuv420p -shortest -strict experimental -f flv rtmp://localhost:1935/live/stream

ffmpeg rtmp and local file output

I have a trouble with ffmpeg
I receive a rtsp stream from a grabbing device (camera) and I stream-out it to rtmp (Youtube Live)
I want to have a copy of the stream in my computer so I write at the same time in a local file
I use this command :
ffmpeg -y -i 'RTSP_SOURCE' -c:v copy -c:a libvo_aacenc -map 0:v -bsf:v dump_extra -fflags +genpts -flags +global_header -movflags +faststart
-map_metadata 0 -metadata title= -f tee -filter_complex aevalsrc=0 '[f=mp4]/tmp/backup.mp4|[f=mpegts]/tmp/backup.ts|[f=flv]rtmp://a.rtmp.youtube.com/live2/STREAM_ID'
The problem is when I have some disconnections, ffmpeg exits and stop to recording
Is there any flag or option for telling to ffmpeg to continue recording in local files even there is not internet ?
Thank you very much for your help =)
You can try:
ffmpeg -f tee "[onfail=ignore] ...
More description is available here.

What steps are needed to stream RTSP from FFmpeg?

What steps are needed to stream RTSP from FFmpeg?
Streaming UDP is not a problem, but as I want to stream to mobile devices which can natively read RTSP streams, I couldn't find any setup which tells what exactly is needed. Do I need an RTSP streaming server like LIVE555 or can I use FFmpeg only?
My Command:
ffmpeg -i space.mp4 -vcodec libx264 -tune zerolatency -crf 18 -f rtsp -muxdelay 0.1 rtsp://192.168.1.200:1234
I get an Input/Output error.
Do I need a SDP description to use RTSP?
And if yes where do I have to put it?
You can use FFserver to stream a video using RTSP.
Just change console syntax to something like this:
ffmpeg -i space.mp4 -vcodec libx264 -tune zerolatency -crf 18 http://localhost:1234/feed1.ffm
Create a ffserver.config file (sample) where you declare HTTPPort, RTSPPort and SDP stream. Your config file could look like this (some important stuff might be missing):
HTTPPort 1234
RTSPPort 1235
<Feed feed1.ffm>
File /tmp/feed1.ffm
FileMaxSize 2M
ACL allow 127.0.0.1
</Feed>
<Stream test1.sdp>
Feed feed1.ffm
Format rtp
Noaudio
VideoCodec libx264
AVOptionVideo flags +global_header
AVOptionVideo me_range 16
AVOptionVideo qdiff 4
AVOptionVideo qmin 10
AVOptionVideo qmax 51
ACL allow 192.168.0.0 192.168.255.255
</Stream>
With such setup you can watch the stream with i.e. VLC by typing:
rtsp://192.168.0.xxx:1235/test1.sdp
Here is the FFserver documentation.
FWIW, I was able to setup a local RTSP server for testing purposes using simple-rtsp-server and ffmpeg following these steps:
Create a configuration file for the RTSP server called rtsp-simple-server.yml with this single line:
protocols: [tcp]
Start the RTSP server as a Docker container:
$ docker run --rm -it -v $PWD/rtsp-simple-server.yml:/rtsp-simple-server.yml -p 8554:8554 aler9/rtsp-simple-server
Use ffmpeg to stream a video file (looping forever) to the server:
$ ffmpeg -re -stream_loop -1 -i test.mp4 -f rtsp -rtsp_transport tcp rtsp://localhost:8554/live.stream
Once you have that running you can use ffplay to view the stream:
$ ffplay -rtsp_transport tcp rtsp://localhost:8554/live.stream
Note that simple-rtsp-server can also handle UDP streams (i.s.o. TCP) but that's tricky running the server as a Docker container.
Another streaming command I've had good results with is piping the ffmpeg output to vlc to create a stream. If you don't have these installed, you can add them:
sudo apt install vlc ffmpeg
In the example I use an mpeg transport stream (ts) over http, instead of rtsp. I've tried both, but the http ts stream seems to work glitch-free on my playback devices.
I'm using a video capture HDMI>USB device that sets itself up on the video4linux2 driver as input. Piping through vlc must be CPU-friendly, because my old dual-core Pentium CPU is able to do the real-time encoding with no dropped frames. I've also had audio-sync issues with some of the other methods, where this method always has perfect audio-sync.
You will have to adjust the command for your device or file. If you're using a file as input, you won't need all that v4l2 and alsa stuff. Here's the ffmpeg|vlc command:
ffmpeg -thread_queue_size 1024 -f video4linux2 -input_format mjpeg -i /dev/video0 -r 30 -f alsa -ac 1 -thread_queue_size 1024 -i hw:1,0 -acodec aac -vcodec libx264 -preset ultrafast -crf 18 -s hd720 -vf format=yuv420p -profile:v main -threads 0 -f mpegts -|vlc -I dummy - --sout='#std{access=http,mux=ts,dst=:8554}'
For example, lets say your server PC IP is 192.168.0.10, then the stream can be played by this command:
ffplay http://192.168.0.10:8554
#or
vlc http://192.168.0.10:8554
UPDATE:
Here is a command to use VLC for rtsp, instead of using the rtsp-simple-server:
ffmpeg -thread_queue_size 1024 -f video4linux2 -input_format mjpeg -video_size 1280x720 -r 30 -i /dev/video0 -f alsa -thread_queue_size 1024 -i plughw:CARD=MS2109,DEV=0 -acodec mp2 -vcodec libx264 -preset ultrafast -crf 20 -s hd720 -vf format=yuv420p -profile:v main -f mpegts -|vlc -I dummy - --sout='#rtp{sdp=rtsp://:8554/} --sout-all --sout-keep'
If your PC ip is 192.168.0.10, then the rtsp stream is played by this command:
vlc rtsp://192.168.0.10:8554/
An alternative that I used instead of FFServer was Red5 Pro. On Ubuntu, I used this line:
ffmpeg -f pulse -i default -f video4linux2 -thread_queue_size 64 -framerate 25 -video_size 640x480 -i /dev/video0 -pix_fmt yuv420p -bsf:v h264_mp4toannexb -profile:v baseline -level:v 3.2 -c:v libx264 -x264-params keyint=120:scenecut=0 -c:a aac -b:a 128k -ar 44100 -f rtsp -muxdelay 0.1 rtsp://localhost:8554/live/paul

Resources