how to get the delay of ffmpeg? - networking

I'm using ffmpeg to do some work on a network like this:
RtmpServer1 -- FfmpegServer -- RtmpServer2
I put a 6mins.mp4 on RtmpServer1(10.10.1.1) and play it on RtmpServer2(10.10.2.2) by this instruction:
ffmpeg -i rtmp://10.10.1.1:1935/play/6mins.mp4 -vcodec copy -c:v libx264 -f flv rtmp://10.10.2.2:1935/live
I would like to know is there a way to test the length of the time ffmpeg use to decode, compress and encode?(the duration from ffmpeg server get the data to the ffmpeg server send it out)
I tried tcpdump to listen on the both two eth ports(one for get and one for send) of ffmpeg server. But I can't match RTMP packets by pairs("pairs" means the packets containing the same data, one "got" packet matches one "sent" packet). I'd also like to know if there's a way to match the RTMP packets by their content(data).

I tried to use tcpdump on both of the input and output eths and get when the rtmp streamings starts and ends. It is helpful in some way.

Related

RTMP proxy to crop original video and send it to another RTMP server

I need to crop the video from an RTMP stream and send it to another RTMP server which always change. My understanding is that I should use nginx-proxy and ffmpeg, can anybody help me on how to set it up?
I suppose that i need to send the stream to an endpoint like /stream/:stream-key/:next-server-ip process the stream with ffmpeg and then send it to the :next-server-ip, what language should I use in the backend for this?
There are 2 strategies for processing such task:
"Pull"
You have some published rtmp stream and use ffmpeg to pull it, convert and send result to another server:
ffmpeg -i rtmp://source-server/stream -filter:v "crop=out_w:out_h:x:y" -vcodec h264 -acodec copy -f flv rtmp://next-server/stream
"Push"
RTMP stream is pushed to your server which processes it and sends result to another server. For such task you can use nginx-rtmp module for nginx and setup ffmpeg command using exec_push directive:
application src {
live on;
exec_push ffmpeg -i rtmp://localhost/src/$name -filter:v "crop=out_w:out_h:x:y" -vcodec h264 -acodec copy -f flv rtmp://next-server/stream 2>>/var/log/ffmpeg-$name.log;
}
When someone start to stream to rtmp://your-server/src/stream_name this ffmpeg command will be executed and the processing will begin
For additional information about video cropping and related ffmpeg parameters see https://video.stackexchange.com/a/4571

FFmpeg -> JSMpeg Websocket Closes Repeatedly

I'm trying to create a fairly simple streaming server/site. Here's the current flow:
OBS streams to an RTMP URL
Nginx accepts the RTMP stream and uses exec-push to have FFmpeg pick up the stream and transcode it
FFmpeg transcodes the stream and outputs it to a JSMpeg application, which displays the stream on a webpage.
When I have my exec_push statement as follows, everything seems to work perfectly, except the browser says Possible garbage data. Skipping. on every frame it receives:
exec_push /usr/bin/ffmpeg -re -i rtmp://127.0.0.1:1935/$app/$name -f mpeg1video http://localhost:8080/supersecret;
This behavior is understandable, because JSMpeg must receive MPEG-TS data, not MPEG1 data. It sees the MPEG1 frames and thinks they're garbage.
So through some online research, I found this:
exec_push /usr/bin/ffmpeg -re -i rtmp://127.0.0.1:1935/$app/$name -c:v copy -c:a copy -f mpegts http://localhost:8080/supersecret;
Supposedly, this is supposed to transcode my RTMP stream into an MPEG-TS format, which should be compatible with JSMpeg.
However, with the second version of the command, my FFmpeg -> JSMpeg stream keeps connecting and disconnecting, connecting and disconnecting, and so on. This behavior is observed in terminal:
Stream Connected: ::1:40208
close
Stream Connected: ::1:40212
close
Stream Connected: ::1:40216
close
Stream Connected: ::1:40220
close
Stream Connected: ::1:40224
close
...
What would cause this? I am pretty certain the issue is in my exec_push command. OBS is perfectly content, which tells me that the stream is making it to the server, and if I do a push, I can do a test push to Ustream just fine, which tells me that Nginx is at least processing the stream with some reasonable degree of success.
Disclaimer: I have no idea what I'm talking about. Everything I know about FFmpeg and JSMpeg/Node is from snippets of code that I found online.
Answer credit goes to #Mulvya.
In the second exec_push command, the -c:v copy -c:a copy should not be there. By using that, there isn't any transcoding going on-- it's just a stream passthrough.
Removing the -c:v copy -c:a copy from the command and restarting Nginx yields a successful stream.

DirectShow stream using ffmpeg point to point streaming through TCP protocol

I had set up a point-to-point stream using ffmpeg via UDP protocol and the stream worked, but there was screen tearing etc. I already tried raising the buffer size, but it did not help. This is a work network, so the UDP protocol won't work.
here is the full command:
ffmpeg -f dshow -i video="UScreenCapture" -r 30 -vcodec mpeg4 -q 12 -f mpegts udp://192.168.1.220:1234?pkt_size=188?buffer_size=65535
I've tried to make this work with TCP with no success
Here's what i've got now:
ffmpeg -f dshow -i video="UScreenCapture" -f mpegts tcp://192.168.1.194:5555
this returns an error:
real-time buffer [UScreenCapture] [Video input] too full or near too
full <323% of size: 3041280 [rtbufsize parameter]>! frame dropped!
This last message repeated xxxx times (it went up to around 1400 and I just turned it off).
I've tried to implement the -rtbufsize paremeter and raising the buffsize up to 800000000, didn't help.
I would appreciate any suggestions on how to solve this.

Force ffmpeg to ignore error when connecting failed

I'm trying to deploy a live stream delivery system with nginx and nginx-rtmp-module.
For every node in my system, I wish it could 'forward' the live stream received to downstream node. I try to implement it by following config in my nginx.conf:
exec_push ffmpeg -i rtmp://localhost/src/test -vcodec copy -strict -2 -ar 44100 -ac 1 -f flv rtmp://<downstreaming A>/src/test -f flv rtmp://<downstreaming B>/src/test
it works when everything runs well, but if the downstream node is down, this command will exit and none of the downstream nodes could receive the live stream.
How could I force ffmpeg to ignore the connetion refused, or is there any better alternative to my implementation?
You cannot ignore connection refused since RTMP uses TCP which needs a connection.
If I understood correctly you're trying to transcode a RTMP source and send it to a number of servers.
You could duplicate your command to send to each downstream node
individually but you'll be doing the transcoding twice.
An alternative is to transcode and publish the transcoded stream using
ffserver on the same machine and then push to / pull on each downstream server

capture RTSP stream and forward to RTMP

I am trying to tunnel RTSP h264 encoded data to nginx RTMP server witth ffmpeg, but its not working
my cmd line:
ffmpeg -y -i rtsp://192.168.1.84:6880/test.264 -c:v copy -an -map 0:0 -f mp4 -rtmp_buffer 100 -rtmp_live live rtmp://localhost/live/streamNam
VLC is able to decode rtsp://192.168.1.84:6880/test.264 fine.. Are there any additional options I can forward to ffmpeg for simple tunneling operation? Right now it stalls for a good amount of time doing probing - how to get rid of that too?

Resources