Sunday, February 10, 2013

HTML5 video live streaming with ffmpeg and mediaelement.js, Round 1

In the era of HD home-videos on YouTube, our current delivery method for online classes in low quality Flash videos is getting kinda unacceptable, especially for maths-type subjects, where it would be nice to actually all those numbers and figures on the whiteboard.
So, enter HTML5 video, H.264, mpeg4 and possibly a new encoding server... Our main problem is that we want to print some custom stuff on the videos, so we need to encode them in realtime.

The player of choice is mediaelement.js, because it comes with the promise on the tin that it just works. Just how we like it.
So, after checking out the samples, the player code looks like this:


<video controls="controls" height="360" id="player2" width="480">
  <source src="relay_video.php?quality=0&id=1469&format=mp4" title="mp4" type="video/mp4"></source>
  <source src="relay_video.php?quality=0&id=1469&format=ogg" title="ogg" type="video/ogg"></source>
  <source src="relay_video.php?quality=0&id=1469&format=wmv" title="wmv" type="video/wmv"></source>
    <object data="flashmediaelement.swf" height="360" type="application/x-shockwave-flash" width="480">
        <param name="movie" value="flashmediaelement.swf" />
        <param name="flashvars" value="controls=true&file=relay_video.php?quality=0&id=1469&format=flv" />
        <!-- Image as a last resort -->
        <img src="noflash.jpg" width="480" height="360" title="No video playback capabilities" />
    </object>
</video>


So far so good, let's give it some video files. Transcoding happens on-the-fly either with mencoder or ffmpeg. As we prefer ffmpeg, let's try to do everything with that.
Large parts are from John's ffmpeg post here:
http://johndyer.name/ffmpeg-settings-for-html5-codecs-h264mp4-theoraogg-vp8webm/

Problem 1: we don't have libvpx support compiled in; for the time we'll try to live without it.
Problem 2: old IE versions. They should at least have native support for WMV, either with Silverstripe or otherwise. FFmpeg supports WMV, so this might actually work.
Problem 3: This is a hard one: ffmpeg can't mux into mp4 on a non-seekable output (ie. socket). Wikipedia tells me that WebM is actually based on Matroska. FFmpeg loves Matroska, we can do this.

So, our current format - container - vcodec - acodec groups are as follows:
mp4 - matroska - libx264 - libfaac
ogg - ogg - libtheora - libvorbis
wmv - asf - wmv2 - wmav2
flv - flv - flv - libmp3lame

And: it works so far! The Mozilla guys are open source believers, so Firefox automatically selects ogg. Chromium uses mp4, or in absence of that, falls back to ogg. A few things to try: iPhones might possibly not like the Matroska container, but supposedly they can do mpegts. Problem with that is that Chromium does not work with that, but doesn't fall back to ogg either.
So for that, I'll try:
mp4 - mpegts - libx264 - libfaac
webm - matroska - libx264 - libfaac

Other problems might arise while finding ancient IE version to test with, and maybe on OS X. If I find more out, there'll be a round 2 of this post.

Saturday, January 26, 2013

Linux filesystem overhead comparison

I needed some temporary data storage for a few days for a migration project, so I wanted to know which filesystem to use, that would give me the most available space.
I'm not considering security, journals or anything here, I just need the maximum amount of space possible. Tests were done on a 2TB SAS disk in a Dell MD1000 array, configured as a one disk RAID0 on a PERC5e controller. The tested ones are the most basic Linux compatible filesystems, by no means is this test academic or universal. The results did surprise me a bit:


I expected FAT to be among the top ones, as it's not a very sophisticated fs, and didn't expect much from ext2/3. I'm also a bit biased towards XFS, so I kind of expected better results.
Tests were done with default mkfs.* settings, only exception is root reserved blocks on ext2/3, which were set to 0. The above output is from df -m. I didn't always pay attention in Operating systems class, so the results of minix surprised me a bit.


I have a sort of love-hate relationship with reiserfs, but for today, it earned itself a job.

Friday, December 14, 2012

Ubiquiti Unifi POE

The Ubiquiti Unifi is a fairly cheap and straightforward managed WiFi solution if you are happy with a L2 bridging architecture with not too much additional stuff.
My biggest issue with the hardware is the non-standard POE implementation, which uses 24V "Ubiquiti POE".

Based on the datasheet and experience (http://www.ubnt.com/downloads/datasheets/unifi/UniFi_AP_Datasheet.pdf), our base UAP devices can't directly use 802.3af POE, only the Pro UAP-Pro models can do that. Luckily, an official POE-adapter is sold by Ubiquiti (http://www.ubnt.com/8023af), and it's pretty cheap.

The 802.3af POE is 48V, but fear not: standard POE uses a detection mechanism before sending out the juice, so it won't fry your Unifi AP if you connect it directly to a POE switch, it just won't start up.

If you want to go with long cable runs, as higher voltage is better suited for longer runs, I'd suggest to use standard 48V POE to drive the cable, and use the Unifi adapter near the AP to convert it to 24V.

Thursday, December 6, 2012

Fun factsheet for Cisco 3500XL and 2900XL switches

It still seems like a popular topic, and these switches never really die, so here are some fun facts about them that I found to be useful (both from my experience and from the documentation):
  • These are layer 2 switches;
  • So they don't have DHCP snooping capabilities;
  • Nor any ARP inspection (DAI).
  • They can't do IP routing, or NAT.
  • Traffic distribution over an etherchannel can be based on source or destination MAC addresses, but not both. Distribution can be configured per etherchannel, not just system-wide. You can't distribute based on layer3-4 (IP,TCP/UDP) info.
  • No layer3 ACLs for switching. (Just for the control plane).
  • They have 2 hardware priority queues.
  • They only support L2 COS, not DSCP or TOS.
  • For IP phones, you have to go with a switchport trunk, encapsulation dot1q, nonegotiate, native vlan , allowed vlan ,, swichport voice vlan  type of setup.
  • The 3500XL and 2900XL use the same software, you can run 2900XL images on a 3500XL box.
  • The only members of the 2900XL family with Gigabit ports are the modular, 2U high chassis.
  • They do not support MSTP and GVRP.
  • They do not support LLDP.
  • The 2900 series does not support POE; but some 3500 series models do: look for the -PWR in the model name.
So far that's it, I might extend the list if something comes to mind.

Friday, November 30, 2012

Ethernet filtering fun in hexa with D-Link DES-3250

Most network admins in education know that the source of the most evil is the dormitory. Mostly ignorance with just a touch of malice for the flavor. Rogue DHCP servers, IPv6 router advertisements, IP collisions and the occasional ARP spoofing.

The D-Link DES-3250 series is our choice of switch for our dormitory, as it's cheap and fairly reliable. It can't perform proper DHCP snooping, dymanic-ARP-inspection or even the ARP protection the DES-3526 can, but it can do some filtering, based on IP, MAC or raw ethernet packets.

Credits for the first two go to Gavin McCullagh, not me.

You can filter DHCP replies easily:


create access_profile ip udp src_port_mask 0xFFFF port 1-48 profile_id 1 
config access_profile profile_id 1 add access_id 1 ip udp src_port 67 deny 


Now this one is a thing of beauty: filtering IPv6 Router advertisements:


create access_profile packet_content_mask offset_0-15  0x0  0x0  0x0  0xFFFF0000 offset_16-31  0x0  0xFF000000  0x0  0x0 offset_48-63  0x0  0xFF00  0x0  0x0 port 1-48 profile_id 2 
config access_profile profile_id 2 add access_id 1 packet_content offset_0-15  0x0  0x0  0x0  0x86DD0000 offset_16-31  0x0  0x3A000000  0x0  0x0 offset_48-63  0x0  0x8600  0x0  0x0 deny 


IPv6 uses ethertype 0x86dd, and the type for RA in ICMPv6 is 0x86

Yesterday I had 4 TP-Link APs configured as 192.168.1.254. This wouldn't be a big issue normally, but these ones were dead-set on sending gratuitous ARPs against each other at speeds of 10Mpps...
The DES-3250 has broadcast control, which was set at 8pps, but something went wrong, as the switches still forwarded around 4kpps of ARPs on all ports.
So next up is IPv4 ARP filtering for anything with the source 192.168.0.0/16:


create access_profile packet_content_mask offset_0-15  0x0  0x0  0x0  0xFFFF0000 offset_16-31  0x0  0x0  0x0  0xFFFF0000 port 1-48 profile_id 3 
config access_profile profile_id 3 add access_id 1 packet_content offset_0-15  0x0  0x0  0x0  0x08060000 offset_16-31  0x0  0x0  0x0  0xC0A80000 deny 

The ethertype for ARP is 0x8060, and 192.168 is 0xc0a8.

ARP spoofing of the gateway is not that popular on this subnet, but next time it happens, I'll do an entry with that.

Edit: 19/02/2013 - fixed ethertype value in ARP filter