AlexxIT / go2rtc

Ultimate camera streaming application with support RTSP, RTMP, HTTP-FLV, WebRTC, MSE, HLS, MP4, MJPEG, HomeKit, FFmpeg, etc.
https://github.com/AlexxIT/Blog
MIT License
4.64k stars 378 forks source link

Cannot get ffmpeg to work - An established connection was aborted by the software in your host machine (Solved) #1372

Open catboyschrody opened 1 week ago

catboyschrody commented 1 week ago

I am using ffmpeg version 2024-09-22, go2rtc version=1.9.4 I have the following, which works:

   streams:
     cam3:
       type: rtsp
       url: rtsp://10.0.0.45:80/ch2_0.264
       control: false
       record: false
       options:
         reconnect: true
         reconnect_interval: 60 # seconds
         max_retries: 5

Now, I want to handle this with ffmpeg. According to the documentation, with the format being ffmpeg:{input}#{param1}#{param2}#{param3} the following simple stream should work: test: ffmpeg:rtsp://localhost:8554/cam3 But I am getting the error: error="read tcp 127.0.0.1:8554->127.0.0.1:50731: wsarecv: An established connection was aborted by the software in your host machine."

Now the following works:

  test:
     type: ffmpeg
     url: rtsp://localhost:8554/cam3

But I cant apply operations like #rotate=90 or `options: rotate: 90' to work

The following doesnt work either: test: ffmpeg:rtsp://10.0.0.45:80/ch2_0.264

My end goal is to create a new rtsp stream by taking 4 camera streams, cam1, cam2, cam3 and cam4 and applying the following: -filter_complex "[0:v][1:v]hstack[top];[2:v][3:v]hstack[bottom];[top][bottom]vstack" I want to use the camera stream created by go2rtc as opposed to from the camera source because I need the functionality of reconnect_interval.

I have ensured both go2rtc.exe and ffmpeg.exe are in windows antivirus and firewall exclusion list

But I'm failing at basically step two, getting ffmpeg to work

catboyschrody commented 1 week ago

Okay so through lots of testing I figured it out. This stream formatting for ffmpeg works:

  test_scale: #native is 2560x1440
    - ffmpeg:cam1#video=h264#width=1280#height=720 

You need to have video set to something otherwise you cant transcode a stream copy.

So then I started playing around with custom formats. Although I couldnt manage to create my new format, I could override existing ones. Previously RTSP looked like this: "h264": "-c:v libx264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency -pix_fmt:v yuv420p" This is what I turned it into, note that go2rtc doesn't actually handle multi-line strings right, so this would all be one line, i just added indentation so its legible:

ffmpeg:
  rtsp: >
    -fflags nobuffer 
    -flags low_delay 
    -timeout 5000000 
    -thread_queue_size 512 
    -user_agent go2rtc/ffmpeg 
    -rtsp_flags prefer_tcp 
    -i rtsp://localhost:8554/cam1 
    -i rtsp://localhost:8554/cam2 
    -i rtsp://localhost:8554/cam3 
    -i rtsp://localhost:8554/cam4 
    -filter_complex '[0:v][1:v]hstack[top];[2:v][3:v]hstack[bottom];[top][bottom]vstack'"

And this gives me exactly what I wanted: Screenshot 2024-09-26 111928

Although tbh its kind of finicky and slow to load