FFmpeg Not Transcoding In Real Time

0

Been setting up a recording build for a friend to resemble mine, but I can't seem to get things to work in real-time despite sufficient (as far as I can tell) hardware.

System specs: 8600K, GTX 1050ti, 16Gb RAM, 1tb 860 EVO

Test command (updated for simplicity):

ffmpeg -y -hide_banner -thread_queue_size 9999 -f dshow -rtbufsize 2147.48M -video_size 1920x1080 -framerate 60 `
-i video="@device_pnp_\\?\usb#vid_07ca&pid_0570&mi_00#7&3886ab1a&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global" `
-thread_queue_size 9999 -f dshow -rtbufsize 2147.48M -video_size 1920x1080 -framerate 60 `
-i video="@device_pnp_\\?\usb#vid_07ca&pid_0570&mi_00#7&24df76f&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global" `
-map 0 -c:v h264_nvenc -r 60 -preset: llhp -pix_fmt yuv420p -b:v 1M -minrate 1M -maxrate 1M -bufsize 1M `
C:\Users\Jordan\Videos\FFmpeg\Left\Left.ts `
-map 1 -c:v h264_nvenc -r 60 -preset: llhp -pix_fmt yuv420p -b:v 1M -minrate 1M -maxrate 1M -bufsize 1M `
C:\Users\Jordan\Videos\FFmpeg\Right\Right.ts

The goal of this command is to record 2 seperate syncronized outputs. However, for one reason or another this command is not transcoding video in real-time, which is a big issue when you're trying to record, not simply convert a file. When I omit one of the two outputs or if I halve the resolution of each input / output everything works in real-time. This would make me believe there is a bottleneck in the system somewhere but when monitoring everything in task manager nothing is even close to capping out (GPU encoder, cpu, ram, and SSD below 30% usage).

Furthermore when I try recording both streams in one 4K60 video via OBS things work perfectly fine, as in real-time. So I don't understand how transcoding two 1080p60 streams in FFmpeg would be anymore intensive than one 4K60 stream in OBS...

I have since swapped the 1050ti out for a GTX 1080 with no difference in performance. This would lead me to believe the CPU is at fault. It looks like FFmpeg is really only hitting 1-2 threads... any way to force it to use more? -threads doesn't seem to have any affect regardless of where I inject it into the command. What's really weird is I have have a very similar command but I'm doing two 4K60 streams as opposed two 1080p60 streams with a GTX 1080 and 6800K... As far as I can tell the 8600K has higher per thread performance in comparison to the 6800K so I'm not sure how I'm able to get away with so much more.

Any insight would be higly appreciated.

Nimble

Posted 2018-12-02T19:28:59.367

Reputation: 75

It's not using more threads because you are compressing with nvenc. – chew socks – 2018-12-02T21:42:07.257

Most of that CPU is probably audio, actually. You could try remove all the audio related flags and putting in -an in their place to test this. – chew socks – 2018-12-02T21:45:33.007

Thank you for the comment, I tried removing all audio and put -an in place. Things are still starting far below real-time and then creeping up, looks like it would take about 40-50 minutes... What I don't understand is if I use the same command on my PC (change the capture cards) everything just works right from the get go and it has a theoretically inferior CPU. Could it be something to do with this CPU lacking hyper threading? nvenc is encoding but the CPU is still decoding right? The GPUs encoder is barely being touched. – Nimble – 2018-12-03T03:12:06.173

Your inputs are dshow, so there's not much "decoding" to speak of, mostly memory I/O ops. – Gyan – 2018-12-03T05:44:14.760

Wouldn't that infer that the CPU isn't needed much in the process? The reason I suggested he get an 8600K over the 8700K is I assumed the GPU was doing all the heavy lifting. I'm just comparing his PC to mine and really the only notable difference is that my CPU hyperthreads while his does not. It's all very frustrating, been here about a millions times with FFmpeg though and I eventually figure it out. – Nimble – 2018-12-03T06:09:54.667

What A/B testing have you performed? Input (from two files), CPU encoder (x264), nvenc parameters like lookahead or bitrate? If you haven't, change them one at a time and check. – Gyan – 2018-12-03T06:21:37.067

I've stripped the command one flag at a time down to bare minimum with no effect unfortunately... I set the bitrate to 1M at one point and was surprised to find nothing changed, file sizes were extremely small. The only thing that has had an effect was lowering the resolution or omitting one output entirely. The fact the lowering the resolution affects anything confuses me as I can encode a 4k stream via OBS no problem. I haven't tried CPU encoding, I guess I just assumed the GPU couldn't be the problem after testing with a GTX 1080. But I will test now, surprised I didn't think of that. – Nimble – 2018-12-03T06:58:35.273

Update: running libx264 with bare minimum options at a 1M bitrate still doesn't encode realtime with two outputs at 1920x1080. Even when running these options (bare minimum low bitrate) via libx264 or nvenc with no audio I'm still not encoding realtime. Just doesn't make any sense, especially while knowing that the same works fine on my PC which has the same GPU and SSD... Other than hyper-threading the only other major difference between the 6800K and 8600K is the 6800K has twice the cache, not sure if that could affect anything. – Nimble – 2018-12-03T07:24:52.380

Sounds like some combination of system memory throughput or bus transfer limitation. Try changing RAM to higher speed modules, if you can, and check. Also, combine the inputs into one 3840x1080 stream and encode that to check. – Gyan – 2018-12-03T08:04:34.520

1/ 2 The RAM I put in the build is faster than the ram in my capture PC, but I do have some faster DDR4 in my main desktop I can test with. We can get our hands on an 8700 (non-k) tonight, I'll also bring an M.2 to replace the 860 EVO, if we can swap everything out but the motherboard we can determine if it is the problem. When I put the build together for him I suggested the ASRock H370M Pro4, I reviewed the manual several times before suggesting it to make sure no lanes were being shared between needed PCIe slots and other devices. We have the GPU in slot 1, capture cards in slots 3 & 4, and – Nimble – 2018-12-03T17:15:21.413

2/2 the SSD in Sata port 0. Here is a link to the manual: http://asrock.pc.cdn.bitgravity.com/Manual/H370M%20Pro4.pdf not expecting you dig through it or anything but if you have a second and see any glaring problems that I don’t let me know. I haven’t tried encoding both files into a 3840x1080 stream, but I have tried encoding them into the same file as separate streams, that didn’t seem to make a difference. I’ll make it a point to try and merge them tonight, a lot more testing ahead I suppose…

– Nimble – 2018-12-03T17:16:18.577

@nimble are software and driver versus the same between machines? – chew socks – 2018-12-03T19:37:34.463

You might encoding from a file to make sure it isn't something weird about capturing. Make a longish clip with something like ffv1 (fast to decode) and then use that as the input to your above command. – chew socks – 2018-12-03T19:39:19.230

Just tried merging the input streams into one output file using -filter_complex "[0:v][1:v]hstack=inputs=2[v]" -map "[v]", minimum options, 1M bitrate, libx264 & nvenc, still no luck. This is particularly interesting considering that I can do the same in OBS with no issue at all. @chewsocks I thought that may be the issue so one of the first things I did was load the same driver and copied my FFmpeg folder to his computer, no luck. I'm not sure what you mean by try encoding a file? – Nimble – 2018-12-03T20:07:17.933

@Nimble I meant that it could be capture cards or their drivers that are the problem, so if you could use a video file (like an mkv) as the input to cut them from the picture. – chew socks – 2018-12-04T19:26:17.167

Answers

0

The problem was with the capture cards, I pulled one from his system and put it in mine and was able to replicate the issue. This is not reproducible with any of my other capture cards and I have 4 of them.

The issue seems to be caused by Avermedia's stream engine bloatware stored on the card itself. The card actually shows as two devices, one without stream engine in the name and one with, if you select the one with the issues are alleviated but still present. Anyways seeing as I can confirm the issue is non-existent on Elgato's HD60 Pro we've placed an order for 2 of those.

In retrospect bloatware / unconventional firmware easily explains the extremely hard to diagnose issues. Luckily we purchased the Avermedia Live Gamer HD 2s on deal and can resell them for a full refund, good riddance.

Nimble

Posted 2018-12-02T19:28:59.367

Reputation: 75