Discussion:
[FFmpeg-user] FFplay network stream with low latency
Elliott Balsley
2018-08-03 05:07:42 UTC
Permalink
I’m trying to use ffplay with a network stream from netcat. It’s raw h.264, 1280x720, 30fps.
When I play it with ffplay, there is about 10 seconds latency over the LAN. Is there any way to reduce this? I’ve tried -probesize 32 and —fflags nobuffer. I notice it plays at 25fps, so maybe that’s part of the problem. I can’t figure out how to force the rate to 30.

$ nc 192.168.3.3 8080 | ffplay -i pipe:0 -x 1280 -y 720 -probesize 32
ffplay version 3.4.git Copyright (c) 2003-2018 the FFmpeg developers
built with Apple LLVM version 9.1.0 (clang-902.0.39.2)
configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --enable-avresample --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-librsvg --enable-libtheora --enable-libopenjpeg --enable-libmodplug --enable-libvpx --enable-libsoxr --enable-libspeex --enable-libass --enable-libbluray --enable-lzma --enable-gnutls --enable-fontconfig --enable-libfreetype --enable-libfribidi --disable-libjack --disable-libopencore-amrnb --disable-libopencore-amrwb --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --disable-indev=jack --enable-opencl --disable-outdev=xv --enable-audiotoolbox --enable-videotoolbox --enable-sdl2 --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/clang --arch=x86_64 --enable-x86asm --enable-libx265 --enable-gpl --enable-postproc --enable-libx264 --enable-libxvid --enable-nonfree --enable-libfdk-aac
libavutil 56. 18.102 / 56. 18.102
libavcodec 58. 19.102 / 58. 19.102
libavformat 58. 16.100 / 58. 16.100
libavdevice 58. 4.100 / 58. 4.100
libavfilter 7. 24.100 / 7. 24.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
libpostproc 55. 2.100 / 55. 2.100
[h264 @ 0x7f807b023200] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 0x7f807b023200] decode_slice_header error
[h264 @ 0x7f807b023200] no frame!
[h264 @ 0x7f807a049000] Stream #0: not enough frames to estimate rate; consider increasing probesize
[h264 @ 0x7f807a049000] decoding for stream 0 failed
[h264 @ 0x7f807a049000] Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, h264, from 'pipe:0':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264, none, 25 tbr, 1200k tbn, 50 tbc
[NULL @ 0x7f807b023200] non-existing PPS 0 referenced
Last message repeated 5 times
[h264 @ 0x7f807d804000] non-existing PPS 0 referenced
[NULL @ 0x7f807b023200] non-existing PPS 0 referenced
[h264 @ 0x7f807d804000] decode_slice_header error
[h264 @ 0x7f807d804000] no frame!
[NULL @ 0x7f807b023200] non-existing PPS 0 referenced
Last message repeated 10 times
nan M-V: nan fd= 0 aq= 0KB vq= 119KB sq= 0B f=0/0

_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-***@ffmpeg.org with subj
Carl Eugen Hoyos
2018-08-03 08:09:53 UTC
Permalink
Post by Elliott Balsley
I’m trying to use ffplay with a network stream from netcat.
It’s raw h.264, 1280x720, 30fps.
Are you sure about the framerate?
If it really is 30fps and FFmpeg reports it as 25fps, then you
need a filter chain to speed playback up, "-r" only works with
ffmpeg, see the documentation for setpts:
https://ffmpeg.org/ffmpeg-filters.html#setpts_002c-asetpts
Post by Elliott Balsley
When I play it with ffplay, there is about 10 seconds
latency over the LAN. Is there any way to reduce this?
I’ve tried -probesize 32 and —fflags nobuffer.
You can also test -analyzeduration.
Post by Elliott Balsley
I notice it plays at 25fps, so maybe that’s part of the problem.
I can’t figure out how to force the rate to 30.
I wonder if the ten seconds are the start value for the
latency that increases over time.

And please test current FFmpeg git head, nothing else is
supported here.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ
Elliott Balsley
2018-08-05 01:50:35 UTC
Permalink
Post by Carl Eugen Hoyos
Are you sure about the framerate?
If it really is 30fps and FFmpeg reports it as 25fps, then you
need a filter chain to speed playback up, "-r" only works with
I’m pretty sure. The stream comes from a raspberry pi like this:
raspivid -n -ih -t 0 -w 1280 -h 720 -b 1000000 -fps 30 -o - | nc -lkv4 8080
If I lower the framerate to 5, then latency improves to about 3 seconds, but ffplay still detects it as 25. See full output below from the latest build (with some duplicate error lines removed). I’m piping ffmpeg to ffplay so I can use the -r option.

According to mplayer, it says "FPS not specified in the header or invalid, use the -fps option”. If I use “-fps 60” then it plays with no latency, but if I use “-fps 30” it has bad latency like ffmpeg. I don’t understand why. nc 192.168.1.3 8080 | mplayer -fps 60 -demuxer h264es -

Also, this stream plays with no latency in this app: https://github.com/ShawnBaker/iOS_RPiCameraViewer <https://github.com/ShawnBaker/iOS_RPiCameraViewer>
Post by Carl Eugen Hoyos
You can also test -analyzeduration.
Thanks, I tried setting that to zero but it doesn’t help.


$ nc 192.168.3.172 8080 | /usr/local/bin/ffmpeg -r 5 -i pipe:0 -analyzeduration 0 -probesize 32 -f h264 -an -c:v copy pipe:1 | /usr/local/bin/ffplay -i pipe:0
ffplay version N-91560-g476fd6ba3a Copyright (c) 2003-2018 the FFmpeg developers
built with gcc 7.3.0 (MacPorts gcc7 7.3.0_1)
ffmpeg version N-91560-g476fd6ba3a configuration: --enable-libopenjpeg --enable-libass --enable-libbluray --enable-libfreetype --enable-libx264 --enable-libx265 --enable-nonfree --enable-libfdk-aac --enable-gpl
Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.0 (MacPorts gcc7 7.3.0_1)
configuration: --enable-libopenjpeg --enable-libass --enable-libbluray --enable-libfreetype --enable-libx264 --enable-libx265 --enable-nonfree --enable-libfdk-aac --enable-gpl
libavutil 56. 18.102 / 56. 18.102
libavcodec 58. 22.100 / 58. 22.100
libavformat 58. 17.101 / 58. 17.101
libavdevice 58. 4.101 / 58. 4.101
libavfilter 7. 26.100 / 7. 26.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
libpostproc 55. 2.100 / 55. 2.100
libavutil 56. 18.102 / 56. 18.102
libavcodec 58. 22.100 / 58. 22.100
libavformat 58. 17.101 / 58. 17.101
libavdevice 58. 4.101 / 58. 4.101
libavfilter 7. 26.100 / 7. 26.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
libpostproc 55. 2.100 / 55. 2.100
[h264 @ 0x7fb52580ea00] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 0x7fb52580ea00] decode_slice_header error
[h264 @ 0x7fb52580ea00] no frame!
[h264 @ 0x7fb52580ea00] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 0x7fb52580ea00] decode_slice_header error
[h264 @ 0x7fb52580ea00] no frame!
Input #0, h264, from 'pipe:0':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (High), yuv420p(progressive), 1280x720, 25 fps, 25 tbr, 1200k tbn, 50 tbc
Output #0, h264, to 'pipe:1':
Metadata:
encoder : Lavf58.17.101
Stream #0:0: Video: h264 (High), yuv420p(progressive), 1280x720, q=2-31, 25 fps, 25 tbr, 5 tbn, 5 tbc
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Input #0, h264, from 'pipe:0':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (High), yuv420p(progressive), 1280x720, 25 fps, 25 tbr, 1200k tbn, 50 tbc
nan M-V: nan fd= 0 aq= 0KB vq= 0KB sq= 0B f=0/0 451.5kbits/s speed=1.81x
av_interleaved_write_frame(): Broken pipe
Error writing trailer of pipe:1: Broken pipeime=00:01:11.80 bitrate= 450.5kbits/s speed= 1.8x
frame= 335 fps=8.4 q=-1.0 Lsize= 3949kB time=00:01:11.80 bitrate= 450.5kbits/s speed=1.79x
video:3964kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!

_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-***@ffmpe
Elliott Balsley
2018-08-06 01:41:37 UTC
Permalink
I discovered an option in picamera python module to include the framerate in the SPS headers, so now I will use that instead of raspivid. Plus it’s more flexible, allowing for more advanced text overlays.
Now ffplay detects it correctly as 30 tbr, although it shows 60 tbc and it shows different numbers for fps like 28.83 or 29.25 each time I run it. Why is that? Anyway, it still has the same 10 seconds latency, with or without ffmpeg up front.

_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-***@ffmpeg.org with subject
Roger Pack
2018-08-07 20:55:37 UTC
Permalink
https://trac.ffmpeg.org/wiki/StreamingGuide#Latency
may be useful to you...

On Sun, Aug 5, 2018 at 7:41 PM, Elliott Balsley
Post by Elliott Balsley
I discovered an option in picamera python module to include the framerate in the SPS headers, so now I will use that instead of raspivid. Plus it’s more flexible, allowing for more advanced text overlays.
Now ffplay detects it correctly as 30 tbr, although it shows 60 tbc and it shows different numbers for fps like 28.83 or 29.25 each time I run it. Why is that? Anyway, it still has the same 10 seconds latency, with or without ffmpeg up front.
_______________________________________________
ffmpeg-user mailing list
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
To unsubscribe, visit link above, or email
_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-request
Carl Eugen Hoyos
2018-08-07 21:42:32 UTC
Permalink
Post by Elliott Balsley
I discovered an option in picamera python module to include the framerate in
the SPS headers, so now I will use that instead of raspivid. Plus it’s more
flexible, allowing for more advanced text overlays.
Now ffplay detects it correctly as 30 tbr, although it shows 60 tbc and it
This would be expected for an interlaced stream.
Post by Elliott Balsley
shows different numbers for fps like 28.83 or 29.25 each time I run it. Why
is that?
I guess the timing is not exact for this kind of hardware.
Post by Elliott Balsley
Anyway, it still has the same 10 seconds latency, with or without
ffmpeg up front.
Did you already try the options that are proposed in the wiki?

Is there a reason why you have to use FFplay? ffmpeg supports
several output devices and it may be easier to convince it to
hurry up.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-***@ffmpeg.org wi

Carl Eugen Hoyos
2018-08-07 21:27:46 UTC
Permalink
Post by Elliott Balsley
$ nc 192.168.3.172 8080 | /usr/local/bin/ffmpeg -r 5 -i pipe:0
-analyzeduration 0 -probesize 32 -f h264 -an -c:v copy pipe:1 |
/usr/local/bin/ffplay -i pipe:0
This is just duplicating the latency.

As said, the first thing to check is the actual framerate:
If it really is 30fps, this has to be fixed first.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-***@ffmpeg.org with subje
Elliott Balsley
2018-08-07 21:37:55 UTC
Permalink
Post by Carl Eugen Hoyos
This is just duplicating the latency.
Ok, understood, so I will avoid piping.
Post by Carl Eugen Hoyos
If it really is 30fps, this has to be fixed first.
I did change the stream, so now ffmpeg detects it correctly at 30 tbr, did you see my last message?
_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-***@ffmpeg.
Loading...