VLC struggles to make use of network bandwidth while playing HBR files from a NAS
I have run into problems trying to play high bitrate videos that I store on my NAS using VLC. The NAS is connected using SMB (via macOS Finder) and I have measured around 75MB/s (600Mb/s) for sequential file transfers over LAN.
Blu-Ray
First, a disk image of a 1080p Blu-Ray, which I can open using VLC's Open File...
dialog (mounting it first then using Open Disk...
results in the same following behavior). While playing, VLC will frequently stutter, and it seems as if it is not prefetching data from the NAS. Network usage will remain at zero during playback, and occasionally jump up (and saturate the network, I assume) when it needs to fetch more data. If the response from the NAS is not immediate, the video/audio stutters and VLC emits S_OUT_SET_(GROUP_)PCR is called too late (pts_delay increased to [something] ms)
in the log. This happens at least once every 30 seconds or so, so it is very disruptive. Increasing the buffer lengths in the Input/Codecs settings does nothing other than make the stutters less frequent but longer, seeming to reinforce the idea that the buffer is only being refilled once it is empty or nearly empty (?!?).
Screenshot of Activity Monitor. Update rate is once per second, which is a bit too slow, but you can still see the behavior.
This forum thread indicates people have been experiencing this problem for at least 9 years. #9885 (closed) is another issue seemingly referencing this problem, and commit b8b8c438 (still in the code today) was an alleged fix. As I am experiencing the same symptoms now, this clearly did not fix the problem, and seems to be telling the kernel to prefetch/not prefetch rather than affecting VLC's internal prefetch behavior.
Other Files
As I have no other programs that can play Blu-Rays to do a side-by-side comparison with, I made a 100Mb/s H.264 video file (greater than the ~35Mb/s of the Blu-Ray) and put it on the same NAS. QuickTime Player is able to play the file over the network perfectly, exhibiting bandwidth usage consistent with filling up a prefetch buffer and keeping it full as the video plays. Scrubbing around in the video causes spikes in usage as you'd expect.
VLC is essentially incapable of playing the exact same file. Its network usage is consistently very low, and continuously stutters and cannot maintain playback for more than a few seconds. Interestingly, this behavior is very different (essentially the opposite) from that shown while playing the Blu-Ray image. Regardless, this shows that macOS's SMB implementation is not the problem, as I've seen suggested elsewhere.
Looking at a Wireshark capture, VLC is making smaller file reads, which seems to be making much poorer use of the network bandwidth and latency.
These seem to be separate issues, but the second supports the idea that the SMB connection itself should not be causing the first. I can split them into separate issues if wanted. Please let me know if I can do any further tests with my setup to help understand what's going on.
Versions
- VLC: 3.0.17.3
- macOS: 12.4
- NAS: TrueNAS 12.0 U8.1 (samba 4.13.17)