FFMPEG Streaming webcam on Windows 10 to RTP - ffmpeg

I am still trying to figure out exactly what I am doing with ffmpeg and dshow. However I am trying to stream a 4k capture device I have, so that I can use this as an IPTV server downstream.
So far I have:
ffmpeg -rtbufsize 2100M -y -loglevel warning -f dshow -i video="Video (00 Pro Capture HDMI 4K+)" -s 3840x2160 -vcodec v410 -f rtp rtp://192.168.1.31:8554
...however this is throwing up the following errors:
C:\Program Files\VideoLAN\VLC>ffmpeg -rtbufsize 2100M -y -loglevel warning -f dshow -i video="Video (00 Pro Capture HDMI 4K+)" -s 3840x2160 -vcodec libx265 -f rtp rtp://192.168.1.31:8554
[udp # 000002c207a7d080] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)
[udp # 000002c207a8d380] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)
x265 [info]: HEVC encoder version 3.1+2-b36c03e4e771
x265 [info]: build info [Windows][GCC 9.1.1][64 bit] 8bit+10bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main 4:2:2 10 profile, Level-5.1 (Main tier)
x265 [info]: Thread pool created using 8 threads
x265 [info]: Slices : 1
x265 [info]: frame threads / pool features : 3 / wpp(34 rows)
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge : hex / 57 / 2 / 3
x265 [info]: Keyframe min / max / scenecut / bias: 25 / 250 / 40 / 5.00
x265 [info]: Lookahead / bframes / badapt : 20 / 4 / 2
x265 [info]: b-pyramid / weightp / weightb : 1 / 1 / 0
x265 [info]: References / ref-limit cu / depth : 3 / off / on
x265 [info]: AQ: mode / str / qg-size / cu-tree : 2 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress : CRF-28.0 / 0.60
x265 [info]: tools: rd=3 psy-rd=2.00 early-skip rskip signhide tmvp b-intra
x265 [info]: tools: strong-intra-smoothing lslices=8 deblock sao
SDP:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 192.168.1.31
t=0 0
a=tool:libavformat 58.28.100
m=video 8554 RTP/AVP 96
a=rtpmap:96 H265/90000
[dshow # 000002c207a69f80] real-time buffer [Video (00 Pro Capture HDMI 4K+)] [video input] too full or near too full (62% of size: 2100000000 [rtbufsize parameter])! frame dropped!
[dshow # 000002c207a69f80] real-time buffer [Video (00 Pro Capture HDMI 4K+)] [video input] too full or near too full (64% of size: 2100000000 [rtbufsize parameter])! frame dropped!
[dshow # 000002c207a69f80] real-time buffer [Video (00 Pro Capture HDMI 4K+)] [video input] too full or near too full (67% of size: 2100000000 [rtbufsize parameter])! frame dropped!
...
...
...
[dshow # 000002c207a69f80] real-time buffer [Video (00 Pro Capture HDMI 4K+)] [video input] too full or near too full (99% of size: 2100000000 [rtbufsize parameter])! frame dropped!
Last message repeated 1 times
[dshow # 000002c207a69f80] real-time buffer [Video (00 Pro Capture HDMI 4K+)] [video input] too full or near too full (100% of size: 2100000000 [rtbufsize parameter])! frame dropped!
Last message repeated 149 times
[dshow # 000002c207a69f80] real-time buffer [Video (00 Pro Capture HDMI 4K+)] [video input] too full or near too full (99% of size: 2100000000 [rtbufsize parameter])! frame dropped!
[dshow # 000002c207a69f80] real-time buffer [Video (00 Pro Capture HDMI 4K+)] [video input] too full or near too full (100% of size: 2100000000 [rtbufsize parameter])! frame dropped!
I am unsure why this occurring, as the buffer size is pretty much at the maximum permitted by dshow.
Can anyone suggest a remedy?
Thanks

In the ffmpeg cmd you are using -vcodec v410.
v410 is a raw format/uncompressed format.
v410: packed yuv 4:4:4, 30bpp (32bpp)
v410 – (Uncompressed 4:4:4 10-bit / SheerVideo?)
In ffmpeg, rtp may not support raw format packetization, check this link.
RFC 4175 support in ffmpeg?
As per the logs :
m=video 8554 RTP/AVP 96
a=rtpmap:96 H265/90000
rtp is expecting h265 codec format.
Try and change the packetization format

Related

Ffmpeg: 4K RGB->YUV realtime conversion

I'm trying to use Ffmpeg for creating a hevc realtime stream from a Decklink input. The goal is high quality HDR stream usage with 10 bits.
The Decklink SDI input is fed RGB 10 bits, which is well handled by ffmpeg with the decklink option -raw_format rgb10, which gets recognized by ffmpeg as 'gbrp10le'.
I have a Nvidia pascal-based card, which supports yuv444 10 bit (as 'yuv444p16le') and when when using '-c:v hevc_nvenc' the auto_scaler kicks in and converts to 'yuv444p16le', which I guess is the same conversion as giving '-pix_fmt yuv444p16le'.
This is working very well in 1920x1080 resolution, but in 4096x2160 resolution ffmpeg can't keep up realtime 24 or 25 fps, and I get input buffer overruns.
The culprit seems to be the RGB->YUV conversion in ffmpeg swscale because;
When piping the Decklink 4K RGB input with '-c:v copy' straight to /dev/null, there's is no problems with buffer underruns,
And when feeding the Decklink YUV and giving '-raw_format yuv422p10’ (no YUV444 input for decklink seems available for decklink in ffmpeg) I get no underrun and everything works well in 4K. Even if I set '-pix_fmt yuv444p16le'.
Any ideas how I could accomplish a 4K hevc in NVENC with the 10-bit RGB signal from the Decklink? Is there a way to make NVENC accept and use the RGB data without first converting to YUV? Or is there maybe a way to convert gbrp10le->yuv444p16le with cuda or scale_npp filter? I have compiled ffmpeg with npp and cuda, but I cannot figure out if I can get it to work with RGB? Whenever I try to do '-vf "hwupload_cuda"', auto_scaler kicks in and tries to convert to yuv on the cpu, which again creates underruns.
Another thing I guess could help is if there was a way to make the swscale cpu filter(or if there is another suitable filter?) use multiple threads? Right now it seems to only use one thread at a time, maxing out at 99% on my Ryzen 3950x (3,5GHz, 32 threads).
Example ffmpeg output:
$ ffmpeg -loglevel verbose -f decklink -raw_format rgb10 -i "Blackmagic Card 1" -c:v hevc_nvenc -preset medium -profile:v main10 -cbr 1 -b:v 20M -f nut - > /dev/null
--
Stream #0:1: Video: r210, 1 reference frame, gbrp10le(progressive), 4096x2160, 6635520 kb/s, 25 tbr, 1000k tbn, 1000k tbc
--
[graph 0 input from stream 0:1 # 0x4166180] w:4096 h:2160 pixfmt:gbrp10le tb:1/1000000 fr:25000/1000 sar:0/1
[auto_scaler_0 # 0x4168480] w:iw h:ih flags:'bicubic' interl:0
[format # 0x4166080] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_null_0' and the filter 'format'
[auto_scaler_0 # 0x4168480] w:4096 h:2160 fmt:gbrp10le sar:0/1 -> w:4096 h:2160 fmt:yuv444p16le sar:0/1 flags:0x4
[hevc_nvenc # 0x4139640] Loaded Nvenc version 11.0
--
Stream #0:0: Video: hevc (Rext), 1 reference frame (HEVC / 0x43564548), yuv444p16le(tv, progressive), 4096x2160 (0x0), q=2-31, 2000 kb/s, 25 fps, 51200 tbn
--
[decklink # 0x40f0900] Decklink input buffer overrun!:02.52 bitrate= 30471.3kbits/s speed=0.627x

ffmpeg and ffserver, rc buffer underflow?

I am attempting to write a simple streaming server for a project. I have an AWS Linux machine that will be running ffserver. Curently, as it stands, my config file looks like the following:
#Server Configs
HTTPPort 8090
HTTPBindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 1000
CustomLog -
#Create a Status Page
<Stream stat.html>
Format status
ACL allow localhost
ACL allow 255.255.255.255 #Allow everyone to view status, for now
</Stream>
#Creates feed, only allow from self
<Feed feed1.ffm>
File /tmp/feed1.ffm
FileMaxSize 50M
ACL allow 127.0.0.1
ACL allow <MY_PERSONAL_COMPUTER'S_PUBLIC_IP_HERE>
</Feed>
#Creates stream, allow everyone
<Stream tagLive.mpg>
Format mpeg
Feed feed1.ffm
VideoFrameRate 30
VideoSize 640x480
AudioSampleRate 44100
</Stream>
I then am capturing my Webcam and sending it up to the server using the following command:
ffmpeg -f dshow
-i video="Webcam C170":audio="Microphone (Webcam C170)"
-b:v 1400k
-maxrate 2400k
-bufsize 1200k
-ab 64k
-s 640x480
-ac 1
-ar 44100
-y http://<AWS_SERVER_PUBLIC_DNS>:8090/feed1.ffm
When I run this however, I get the following output from my console:
Guessed Channel Layout for Input Stream #0.1 : stereo
Input #0, dshow, from 'video=Webcam C170:audio=Microphone (Webcam C170)':
Duration: N/A, start: 12547.408000, bitrate: N/A
Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 30 tbr, 10000k tbn, 30 tbc
Stream #0:1: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s
Output #0, ffm, to '<AWS_SERVER_PUBLIC_DNS>:8090/feed1.ffm':
Metadata:
creation_time : 2017-04-26 14:55:27
encoder : Lavf57.25.100
Stream #0:0: Audio: mp2, 44100 Hz, mono, s16, 64 kb/s
Metadata:
encoder : Lavc57.24.102 mp2
Stream #0:1: Video: mpeg1video, yuv420p, 640x480, q=2-31, 64 kb/s, 30 fps, 1000k tbn, 30 tbc
Metadata:
encoder : Lavc57.24.102 mpeg1video
Side data:
unknown side data type 10 (24 bytes)
Stream mapping:
Stream #0:1 -> #0:0 (pcm_s16le (native) -> mp2 (native))
Stream #0:0 -> #0:1 (rawvideo (native) -> mpeg1video (native))
Press [q] to stop, [?] for help
[mpeg1video # 02e95180] rc buffer underflow
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
[mpeg1video # 02e95180] rc buffer underflow
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
[mpeg1video # 02e95180] rc buffer underflow
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
[mpeg1video # 02e95180] rc buffer underflow
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
[mpeg1video # 02e95180] rc buffer underflow
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
[mpeg1video # 02e95180] rc buffer underflow
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
[mpeg1video # 02e95180] rc buffer underflow
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
[mpeg1video # 02e95180] rc buffer underflow
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
[mpeg1video # 02e95180] rc buffer underflowtime=00:00:01.13 bitrate= 404.8kbits/s dup=13 drop=0 speed=2.22x
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
[mpeg1video # 02e95180] rc buffer underflow
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
[mpeg1video # 02e95180] rc buffer underflowtime=00:00:01.63 bitrate= 361.1kbits/s dup=13 drop=0 speed=1.61x
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
[mpeg1video # 02e95180] rc buffer underflowtime=00:00:02.13 bitrate= 368.6kbits/s dup=13 drop=0 speed= 1.4x
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
[mpeg1video # 02e95180] rc buffer underflowtime=00:00:02.66 bitrate= 344.1kbits/s dup=13 drop=0 speed=1.32x
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
[mpeg1video # 02e95180] rc buffer underflowtime=00:00:03.16 bitrate= 331.1kbits/s dup=13 drop=0 speed=1.25x
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
[mpeg1video # 02e95180] rc buffer underflow
[mpeg1video # 02e95180] max bitrate possibly too small or try trellis with large lmax or increase qmax
frame= 117 fps= 36 q=31.0 Lsize= 156kB time=00:00:03.86 bitrate= 330.5kbits/s dup=13 drop=0 speed= 1.2x
video:118kB audio:27kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 7.659440%
Exiting normally, received signal 2.
And on my viewer, I just get a black screen.
Is there something I'm missing? Searching lead to nothing on "increasing qmax" or anything similar to what ffmpeg complained about. There have been questions asked here, but nothing has been done/answered.
Thanks in advance
You can set qmax and qmin in the server config
<Stream test_3840.flv>
...
VideoQMin 1
VideoQMax 15
...
</Stream>
More details can be found in that answer https://stackoverflow.com/a/18566361/4010173

What does the fps mean in the ffmpeg output?

I am streaming a static png file with ffmpeg and it uses basically all my CPU. It seems a bit greedy to me, and even though I limited the fps on the input and output size, I am seeing a huge fps printed out.
w:\ffmpeg\bin>ffmpeg.exe -loop 1 -framerate 1 -i w:\colorbar2.png -r 10 -vcodec libx264 -pix_fmt yuv420p -r 10 -f mpegts udp://127.0.0.1:10001?pkt_size=1316
ffmpeg version N-68778-g5c7227b Copyright (c) 2000-2014 the FFmpeg developers
built on Dec 29 2014 22:12:54 with gcc 4.9.2 (GCC)
Input #0, png_pipe, from 'w:\colorbar2.png':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: png, pal8, 320x240 [SAR 3779:3779 DAR 4:3], 1 fps, 1 tbr, 1 tbn, 1 tbc
[libx264 # 00000000002fb320] using SAR=1/1
[libx264 # 00000000002fb320] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 # 00000000002fb320] profile High, level 1.2
Output #0, mpegts, to 'udp://127.0.0.1:10001?pkt_size=1316':
Metadata:
encoder : Lavf56.16.102
Stream #0:0: Video: h264 (libx264), yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=-1--1, 10 fps, 90k tbn, 10 tbc
Metadata:
encoder : Lavc56.19.100 libx264
Stream mapping:
Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame=561310 fps=579 q=25.0 size= 144960kB time=15:35:25.80 bitrate= 21.2kbits/s dup=505179 drop=0
As you can see the frame counter goes up quickly and fps=579 is reported on the last line. I am confused now, what does that fps mean, if above the low frame per secs are also mentioned (output 10fps, input 1 fps)
What am I doing wrong and how could I reduce CPU load more given that it's a static file that is being streamed.
Thanks!
ffmpeg attempts to decode and encode as fast as it can. Just because you set the output to be 10 frames per second does not mean that it will (de|en)code realtime at 10 frames per second.
Try the -re input option. From the ffmpeg cli-tool documentation:
Read input at native frame rate. Mainly used to simulate a grab device
or live input stream (e.g. when reading from a file). Should not be
used with actual grab devices or live input streams (where it can
cause packet loss). By default ffmpeg attempts to read the input(s)
as fast as possible. This option will slow down the reading of the
input(s) to the native frame rate of the input(s). It is useful for
real-time output (e.g. live streaming).
Example:
ffmpeg.exe -re -loop 1 -framerate 10 -i w:\colorbar2.png -c:v libx264 \
-tune stillimage -pix_fmt yuv420p -f mpegts udp://127.0.0.1:10001?pkt_size=1316

flv to mp4 using ffmpeg cli on debian

I'm trying to convert this flv file into .mp4 using ffmpeg on debian.
Stream 0 Type: Video Codec: Flash Video (FLV1) Resolution: 640x480
Frame rate: 1000 Decoded format: Planar 4:2:0 YUV
Stream 1 Type: Audio Codec: NellyMoser ASAO (NELL) Channels: Mono
Sample rate: 22050 Hz Bits per sample: 32
I'm currently using this simple command...
sudo avconv -i videoStream_1424268207948_854.flv videoStream_1424268207948_854.mp4
These are the warnings I receive:
[flv # 0x14fab20] Estimating duration from bitrate, this may be inaccurate
[libx264 # 0x14fdaa0] MB rate (1200000) > level limit (983040)
Multiple frames in a packet from stream 0
[flv # 0x14fca60] Bad picture start code
[flv # 0x14fca60] header damaged
Error while decoding stream #0:0
... and it results in messed up video and audio.
Can anyone help with some parameters?
It worked for me using ffmpeg version 2.5.4. Try upgrading avconv, or switching to ffmpeg.

How can I generate encoded HEVC bitstream using ffmpeg?

I am able to encoded YUV file to mp4 using HEVC:
ffmpeg.exe -f rawvideo -s 1920x1080 -pix_fmt yuv420p -i input.yuv -c:v hevc -r 30 -x265-params crf=27 -vframes 300 -an -y test.mp4
Here is the mp4box -info test.mp4 shows:
* Movie Info *
Timescale 1000 - Duration 00:00:10.000
1 track(s)
Fragmented File: no
File suitable for progressive download (moov before mdat)
File Brand isom - version 512
Created: UNKNOWN DATE Modified: UNKNOWN DATE File has no MPEG4 IOD/OD
iTunes Info:
Encoder Software: Lavf56.11.100
Track # 1 Info - TrackID 1 - TimeScale 15360 - Media Duration 00:00:10.000 Track has 1 edit lists: track duration is 00:00:10.000 Media Info: Language "Undetermined" - Type "vide:hev1" - 300 samples Visual Track layout: x=0 y=0 width=1920 height=1080 MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x23 HEVC Video - Visual Size 1920 x 1080
HEVC Info: Profile Main # Level 5 - Chroma Format 1
NAL Unit length bits: 32 - general profile compatibility 0x60000000
Parameter Sets: 1 VPS 1 SPS 1 PPS
SPS resolution 1920x1080
Bit Depth luma 8 - Chroma 8 - 1 temporal layers
But how can I get the decodeble bit stream? I tried
mp4box -raw 1 test.mp4 -out out.bin
It gives:
Extracting MPEG-H HEVC stream to hevc
But the out.bin couldn't be decoded by HM or elecard.
Thanks
Use
ffmpeg -i input.mp4 -c:v hevc -f hevc out.bin
to generate an Annex B bytestream. This can be fed to another decoder.

Resources