Video output distortion on ffpmeg live stream
I am helping build a node server that runs ffmpeg to stream a live WebRTC input to HLS and MPEGDASH. Often when the encoding starts it produces a corrupted video output that looks something like this (viewed using VLC): HLS output distorted image <https://i.stack.imgur.com/Dxx03.png> MPEGDASH output distorted image <https://i.stack.imgur.com/9YQri.png> It isn't doing this every time, but roughly 50%. The ffmpeg commands being run are: ffmpeg -re -y -loglevel error -hide_banner -threads 1 -use_wallclock_as_timestamps 1 -f rawvideo -pix_fmt yuv420p -s 640x480 -framerate 30.000030517578125 -thread_queue_size 512 -i tcp://127.0.0.1:43713 -thread_queue_size 512 -i tcp://127.0.0.1:41871 -vsync 1 -r 30.000030517578125 -c:a aac -c:v h264 -profile:v high -b_strategy 0 -bf 1 -f dash -use_template 1 -use_timeline 1 -window_size 5 -live 1 -min_seg_duration 2000000 -preset veryfast -crf 22 -g 48 -keyint_min 48 -sc_threshold 0 -filter_complex [0]format=pix_fmts=yuv420p[temp0];[temp0]scale=-2:240[A0] -map [A0]:v -b:v:0 400k -maxrate 428k -bufsize 600k -map 1:a -b:a:0 64k -filter_complex [0]format=pix_fmts=yuv420p[temp1];[temp1]scale=-2:360[A1] -map [A1]:v -b:v:1 700k -maxrate 749k -bufsize 1050k -map 1:a -b:a:1 96k /usr/src/app/cdn-path/webrtc_test.mpd ffmpeg -re -y -loglevel error -hide_banner -threads 1 -use_wallclock_as_timestamps 1 -f rawvideo -pix_fmt yuv420p -s 640x480 -framerate 30.000030517578125 -thread_queue_size 512 -i tcp://127.0.0.1:43713 -thread_queue_size 512 -i tcp://127.0.0.1:41871 -vsync 1 -r 30.000030517578125 -c:a copy -c:v h264 -profile:v high -b_strategy 0 -bf 1 -f mpegts /usr/src/app/cdn-stream-save/webrtc_test_1567437442625.ts -c:a aac -c:v h264 -profile:v high -b_strategy 0 -bf 1 -f hls -hls_time 2 -hls_list_size 5 -hls_flags delete_segments -preset veryfast -crf 22 -g 48 -keyint_min 48 -sc_threshold 0 -filter_complex [0]format=pix_fmts=yuv420p[temp0];[temp0]scale=-2:240[A0] -map [A0]:v -b:v:0 400k -maxrate 428k -bufsize 600k -map 1:a -b:a 64k /usr/src/app/cdn-path/webrtc_test_1.m3u8 -hls_time 2 -hls_list_size 5 -hls_flags delete_segments -preset veryfast -crf 22 -g 48 -keyint_min 48 -sc_threshold 0 -filter_complex [0]format=pix_fmts=yuv420p[temp1];[temp1]scale=-2:360[A1] -map [A1]:v -b:v:1 700k -maxrate 749k -bufsize 1050k -map 1:a -b:a 96k /usr/src/app/cdn-path/webrtc_test_2.m3u8 ffmpeg details: ffmpeg version 3.4.6 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.11) 20160609 configuration: --disable-debug --disable-doc --disable-ffplay --enable-shared --enable-avresample --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-gpl --enable-libass --enable-libfreetype --enable-libvidstab --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxvid --enable-libx264 --enable-nonfree --enable-openssl --enable-libfdk_aac --enable-libkvazaar --enable-postproc --enable-small --enable-version3 --extra-cflags=-I/opt/ffmpeg/include --extra-ldflags=-L/opt/ffmpeg/lib --extra-libs=-ldl --prefix=/opt/ffmpeg libavutil 55. 78.100 / 55. 78.100 libavcodec 57.107.100 / 57.107.100 libavformat 57. 83.100 / 57. 83.100 libavdevice 57. 10.100 / 57. 10.100 libavfilter 6.107.100 / 6.107.100 libavresample 3. 7. 0 / 3. 7. 0 libswscale 4. 8.100 / 4. 8.100 libswresample 2. 9.100 / 2. 9.100 libpostproc 54. 7.100 / 54. 7.100 Does anyone have any ideas on what might cause this type of distortion on the output stream or how I can test further to track it down? Thank you
Hi Ben, On Tue, Sep 10, 2019 at 06:09:30 +0100, Ben Houghton wrote:
I am helping build a node server that runs ffmpeg to stream a live WebRTC input to HLS and MPEGDASH. Often when the encoding starts it produces a corrupted video output that looks something like this (viewed using VLC):
Are you saying that after a few frames the video becomes correct?
HLS output distorted image <https://i.stack.imgur.com/Dxx03.png> MPEGDASH output distorted image <https://i.stack.imgur.com/9YQri.png>
This doesn't look like an encoding error by ffmpeg, but it could be a decoding artifact. In particular if the first frame is not a keyframe or just partially received. There's possibly nothing you can do, because that's the way the stream is initially picked up. (Just guessing so far.)
Does anyone have any ideas on what might cause this type of distortion on the output stream or how I can test further to track it down?
To see what ffmpeg is doing with your input, it would have been helpful to look at ffmpeg's complete log output. But:
ffmpeg -re -y -loglevel error -hide_banner
Without "-loglevel error" and without "-hide_banner" please. To see whether the input is at fault, you would strip all the output magic and just dump a few seconds to file, by keeping all the input options, but just writing a simple file, for example: $ ffmpeg { input options } -map 0:v -map 1:a -t 5 testout.mp4 to check whether the same effects are to be seen in that file.
ffmpeg version 3.4.6 Copyright (c) 2000-2019 the FFmpeg developers
Though it probably isn't part of your issue, we always recommend to test (or even use) a very recent version of ffmpeg. This rules out debugging fixed bugs. If you can't find a newer ffmpeg in some other repository, and you don't want to build yourself, you can grab a static binary from here and test with that: https://johnvansickle.com/ffmpeg/ (Left column, "git master", please.) Regards, Moritz
Hi Moritz, Many thanks for the detailed response.
I am helping build a node server that runs ffmpeg to stream a live WebRTC input to HLS and MPEGDASH. Often when the encoding starts it produces a corrupted video output that looks something like this (viewed using VLC):
Are you saying that after a few frames the video becomes correct?
No, once it starts “bad", it stays “bad".
Does anyone have any ideas on what might cause this type of distortion on the output stream or how I can test further to track it down?
To see what ffmpeg is doing with your input, it would have been helpful to look at ffmpeg's complete log output. But:
ffmpeg -re -y -loglevel error -hide_banner
Without "-loglevel error" and without "-hide_banner" please.
I’ve attached the stout produced from ffmpeg when the issue is occurring with just those options removed. I don’t see any issues there so I am thinking you may be right about it being an issue with the Web RTC input. If you do spot anything "interesting" please let me know.
To see whether the input is at fault, you would strip all the output magic and just dump a few seconds to file, by keeping all the input options, but just writing a simple file, for example:
$ ffmpeg { input options } -map 0:v -map 1:a -t 5 testout.mp4
to check whether the same effects are to be seen in that file.
Yes, I’ll try this - but because it’s all being run programmatically using nodeJS it will take me a little while to make the code so that all commands are running under the same conditions.
ffmpeg version 3.4.6 Copyright (c) 2000-2019 the FFmpeg developers
Though it probably isn't part of your issue, we always recommend to test (or even use) a very recent version of ffmpeg. This rules out debugging fixed bugs. If you can't find a newer ffmpeg in some other repository, and you don't want to build yourself, you can grab a static binary from here and test with that:
https://johnvansickle.com/ffmpeg/
(Left column, "git master", please.)
Yes - again this is inside a docker build so it will take a little while to bring it up to date, but if it is looking like ffmpeg is the issue then I’ll give it a go. Thank you Ben
On 10 Sep 2019, at 10:41, Moritz Barsnick <barsnick@gmx.net> wrote:
Hi Ben,
On Tue, Sep 10, 2019 at 06:09:30 +0100, Ben Houghton wrote:
I am helping build a node server that runs ffmpeg to stream a live WebRTC input to HLS and MPEGDASH. Often when the encoding starts it produces a corrupted video output that looks something like this (viewed using VLC):
Are you saying that after a few frames the video becomes correct?
HLS output distorted image <https://i.stack.imgur.com/Dxx03.png> MPEGDASH output distorted image <https://i.stack.imgur.com/9YQri.png>
This doesn't look like an encoding error by ffmpeg, but it could be a decoding artifact. In particular if the first frame is not a keyframe or just partially received. There's possibly nothing you can do, because that's the way the stream is initially picked up. (Just guessing so far.)
Does anyone have any ideas on what might cause this type of distortion on the output stream or how I can test further to track it down?
To see what ffmpeg is doing with your input, it would have been helpful to look at ffmpeg's complete log output. But:
ffmpeg -re -y -loglevel error -hide_banner
Without "-loglevel error" and without "-hide_banner" please.
To see whether the input is at fault, you would strip all the output magic and just dump a few seconds to file, by keeping all the input options, but just writing a simple file, for example:
$ ffmpeg { input options } -map 0:v -map 1:a -t 5 testout.mp4
to check whether the same effects are to be seen in that file.
ffmpeg version 3.4.6 Copyright (c) 2000-2019 the FFmpeg developers
Though it probably isn't part of your issue, we always recommend to test (or even use) a very recent version of ffmpeg. This rules out debugging fixed bugs. If you can't find a newer ffmpeg in some other repository, and you don't want to build yourself, you can grab a static binary from here and test with that:
https://johnvansickle.com/ffmpeg/
(Left column, "git master", please.)
Regards, Moritz _______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user
To unsubscribe, visit link above, or email ffmpeg-user-request@ffmpeg.org with subject "unsubscribe".
participants (2)
-
Ben Houghton -
Moritz Barsnick