Netgate Store

Author Topic: Optimizing for video stream  (Read 214 times)

0 Members and 1 Guest are viewing this topic.

Offline wgstarks

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
    • View Profile
Optimizing for video stream
« on: May 15, 2018, 08:09:01 pm »
I have recently started a video stream from my home network. I know that it will never have great quality running through youtube, but right now I've had to really set the frame rate very low to avoid dropped frames. I'm wondering if I can use traffic shaping to give the video stream a higher priority and be able to increase the frame rate to a higher level? How would I go about setting this up?
pfSense vs 2.4.3
Box: Minisys IBOX-501 N10E
CPU: Intel Atom E3845
NIC: Intel WG82583 1000M x 4
RAM: 8GB

Offline dusan

  • Full Member
  • ***
  • Posts: 231
  • Karma: +10/-0
    • View Profile
Re: Optimizing for video stream
« Reply #1 on: May 15, 2018, 11:22:17 pm »
Don't prioritize video. Just give it a dedicated queue with sufficient bandwidth.

What's your video protocol (UDP, TCP)? How bigs are video packets? And what is desired packet rate per session?


Offline wgstarks

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
    • View Profile
Re: Optimizing for video stream
« Reply #2 on: May 16, 2018, 09:08:44 am »
Itís a YouTube live stream from OBS. My understanding is that this uses RTMP which should be TCP by default. I havenít verified that though.

Currently video bitrate is 1250. Iíd like to get it up to at least 1500.

Also have a P2P server running on this network with max upload bandwidth limited to 100KBps.

Speed test shows 233.04 Mbps down and 9.06 Mbps up for this network, so hopefully I should be able to improve the streaming if I set it up properly.
pfSense vs 2.4.3
Box: Minisys IBOX-501 N10E
CPU: Intel Atom E3845
NIC: Intel WG82583 1000M x 4
RAM: 8GB

Offline dusan

  • Full Member
  • ***
  • Posts: 231
  • Karma: +10/-0
    • View Profile
Re: Optimizing for video stream
« Reply #3 on: May 16, 2018, 10:28:55 am »
Itís a YouTube live stream from OBS. My understanding is that this uses RTMP which should be TCP by default. I havenít verified that though.

Currently video bitrate is 1250. Iíd like to get it up to at least 1500.

Also have a P2P server running on this network with max upload bandwidth limited to 100KBps.

Speed test shows 233.04 Mbps down and 9.06 Mbps up for this network, so hopefully I should be able to improve the streaming if I set it up properly.

So you'll need a queue, say, qStream, with bandwidth = 1500 Kbps, for the video stream (including ACKs of the stream). Put everything else to the default queue, qDefault.

If you use HFSC, the qStream should have a [real-time and link-share] service curve with [identical parameter] m2 = 1500Kb. Leave the parameters m1 and d unset.

Use _pftop_ to determine actual packet rate, packet size, and bitrate of qStream.

If you still experience many packet drops and/or insufficient bitrate, try to improve latency by setting the parameters m1 and d for the curve.

For example, let's assume packet size is 12 Kb (kilobits). By setting bitrate m2 = 1500 Kbps you'll have guaranteed packet rate 1500/12 = 125 packets per second and delay D = 1/125 = 0.008 s = 8 ms. Furthermore, by setting m1 = 2*m2 = 3000 Kbps, d = D/2 = 4ms, you'll get latency improved to 4 ms (with the same bit rate and packet rate).

The trick with m1 and d works for a single session.
« Last Edit: May 16, 2018, 10:32:19 am by dusan »

Offline wgstarks

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
    • View Profile
Re: Optimizing for video stream
« Reply #4 on: May 16, 2018, 12:05:55 pm »
Thanks for the help. Iíll give that a try.
pfSense vs 2.4.3
Box: Minisys IBOX-501 N10E
CPU: Intel Atom E3845
NIC: Intel WG82583 1000M x 4
RAM: 8GB

Offline Harvy66

  • Hero Member
  • *****
  • Posts: 2394
  • Karma: +224/-13
    • View Profile
Re: Optimizing for video stream
« Reply #5 on: May 16, 2018, 12:19:32 pm »
If you're still having issue, I recommend using FairQ+Codel or fq_codel(bit more complex right now and should be much easier to setup in 2.4.4)

Offline wgstarks

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
    • View Profile
Re: Optimizing for video stream
« Reply #6 on: Yesterday at 05:30:27 pm »
Itís a YouTube live stream from OBS. My understanding is that this uses RTMP which should be TCP by default. I havenít verified that though.

Currently video bitrate is 1250. Iíd like to get it up to at least 1500.

Also have a P2P server running on this network with max upload bandwidth limited to 100KBps.

Speed test shows 233.04 Mbps down and 9.06 Mbps up for this network, so hopefully I should be able to improve the streaming if I set it up properly.

So you'll need a queue, say, qStream, with bandwidth = 1500 Kbps, for the video stream (including ACKs of the stream). Put everything else to the default queue, qDefault.

If you use HFSC, the qStream should have a [real-time and link-share] service curve with [identical parameter] m2 = 1500Kb. Leave the parameters m1 and d unset.

Use _pftop_ to determine actual packet rate, packet size, and bitrate of qStream.

If you still experience many packet drops and/or insufficient bitrate, try to improve latency by setting the parameters m1 and d for the curve.

For example, let's assume packet size is 12 Kb (kilobits). By setting bitrate m2 = 1500 Kbps you'll have guaranteed packet rate 1500/12 = 125 packets per second and delay D = 1/125 = 0.008 s = 8 ms. Furthermore, by setting m1 = 2*m2 = 3000 Kbps, d = D/2 = 4ms, you'll get latency improved to 4 ms (with the same bit rate and packet rate).

The trick with m1 and d works for a single session.
I went through the wizard and used HFSC. Set RTMP to be queued higher with all others set to default. The wizard didn't give me the option to create a queue and I don't see qStream. Not sure where to enter the settings for m1.

pfSense vs 2.4.3
Box: Minisys IBOX-501 N10E
CPU: Intel Atom E3845
NIC: Intel WG82583 1000M x 4
RAM: 8GB

Offline dusan

  • Full Member
  • ***
  • Posts: 231
  • Karma: +10/-0
    • View Profile
Re: Optimizing for video stream
« Reply #7 on: Yesterday at 09:01:14 pm »

I went through the wizard and used HFSC. Set RTMP to be queued higher with all others set to default. The wizard didn't give me the option to create a queue and I don't see qStream. Not sure where to enter the settings for m1.



Go to Firewall -> Rules and check out the Floating tab. There should be a rule for RTMP inbound and you should see the queue name. It's probably qOthersHigh and let's assume it is later on. Edit any other rule that use qOthersHigh and change them to use qDefault. Leave the RTMP inbound rule intact. (If there's no RTMP inbound rule, find the RTMP outbound rule instead and, also, make sure it includes *WAN* Interface and *out* Direction.)

Go to Firewall -> Traffic Shaper and edit the qOthersHigh. (Note that there are multiple queues under that same name and the specific queue you may want to edit is one under *the WAN interface*.) Tick the checkbox at "Real-Time" to enable the real-time service curve and set Bandwidth, Real-Time m2 and Link-Share m2 to the same desired value (1500 Kbps).
« Last Edit: Yesterday at 09:07:30 pm by dusan »

Offline wgstarks

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
    • View Profile
Re: Optimizing for video stream
« Reply #8 on: Today at 05:52:50 pm »
Thanks. Just want to confirm I got this correct. Had to boost the rate to 3000 and might have to go a little higher to keep the stream health in the green.



pfSense vs 2.4.3
Box: Minisys IBOX-501 N10E
CPU: Intel Atom E3845
NIC: Intel WG82583 1000M x 4
RAM: 8GB