CodeBlocks

Thursday 22 May 2014

Steam In-Home Streaming

A few hours ago Valve released the once beta only Steam In-Home Streaming to everyone. Steam In-Home Streaming allows one to remotely play a game via any machine that supports the steam client. That it and it is really that simple.

How it works
Now you might think there is some magic at play with this but in reality the implementation is very simple. What In-Home Streaming does is create a Client Host setup the host being the machine that does the heavy lifting and the client receives the end result of said heavy lifting.

In-Home Streaming will launch the game on the host machine as if someone is physically going to play on it, it then capture the monitor view(not the end product of the GFX), then compresses it with H264 and video streams it to the client. This means that if you alt-tab the Host machine the desktop will still be streamed to the client. So really the client machine becomes a duplicate display of the host machine. 

This does have some drawbacks.

How to setup
Setting it up is really simple
  1. First install steam on both host and client devices make sure both are running the latest version.
  2. Run steam client on both machines
  3. Log into the same account on both steam clients
  4. On the client machine select the game and click stream.
Note the host machine HAS to be logged into a user account.

How well does it work
Now this will all depend on various factors. Since there are 4 bottlenecks at play
  1. Rending time - The time it takes for the host machine to render a frame
  2. Encoding time - Time it takes to compress frame to H264
  3. Network - The time it will take to correctly send the Frame data
  4. Decode time - The time it takes to decode a Frame
Now I tested this on both a wired and wireless machine that  would in no way be capable of running the game. The performance does depend on the games some games stream better than others, I'm sure CPU intense games will suffer more due to the H264 encoding overhead.

The games I tested were NFS Hot Pursuit and HL2, on average the wireless connection did appear to drop frames from time to time which in NFS was kinda annoying, it did perform well it could just... be better. The wired connection performed better dropping less frames due to network issues and overall performed really well and very playable. You do from time to time notice a latency issue but overall it worked really well and very very simple. 

Conclusion 
The approach Valve went for is a very simple but limited implementation of game streaming that for advance user might be a bit of a crux as you can't really create a server to host games to the level some would want to. 

You also can't change the codec settings which for me at least is a very lame, I'd love to be able to play around and see how influences the gameplay.

In-Home Streaming does what it says and it works very easily with very few hickups which is great for quickly setting up a home entertainment system, but it lacks advance options and the ability to scale beyond a mere slave for the client, the client essentially renders the host machine unusable.

Saturday 18 January 2014

x264 CRF Guide

Along with x264 came a new rate control method Constant Rate Factor(CRF) to me this is one of the best ways to encode videos. Unfortunately there isn't a lot of data on how CRF actually work and the results it creates. The reason for this is because it is based off of Constant Quantizer(QP) to understand this one must know how QP works first.

Constant Quantizer(QP)
Quantization works by breaking large input sets into smaller ones by removing information that might not be as relevant. A small example of this is, instead of storing data like: 28.56 we store it  28.56204234672.

So QP work by keeping the information it throws away consistent, thus resulting in a constant quality. In the H263 (xvid,divx, mpeg part 4, 3ivx) days a QP of 1 = 100% quality and every step was 5 less, so a QP 3 would be 90% and QP 5 = 85% and so on.

In H264 a QP 0 = 100% and there are 51 steps suggesting that every step is roughly 2% quality loss of course that is all mathematical and in the real world we deal with perceptual. And that is where CRF comes in. 

Constant Rate Factor
CRF works similarly to QP in that it tries and mimics the perceptual quality output of QP, such that a QP 21 would look to the human eye near identical to a CRF 21, it does this by reducing information in areas the human eye can't perceive and redistributes them in other areas that might need more data.

CRF-25
QP-25
As you can see the images have a very similar image quality even during playback but has a significant difference in file-size:
QP: 2.6 GB
CRF: 2.1 GB(24% smaller)

Resolution scaling

So lets take a look at how CRF scales with different resolution sizes. The y-axis represents file size and the x-axis the vertical lines from 96x52p to 1920x1040p. The first step is 5% pixels of max and the second is 10%, the 3rd 15% and so on until 100% of/or 1920x1040.
As you can see the there is a slight indication that the amount of data needed to represent an image with CRF scales slightly exponentially in regards to the number of pixels.
And if we look at the encoding performance above we can see that as the resolution increases there is a sharp drop in encoding speed that tapers of has the resolution reaches the higher end.

So what is a good CRF value? It mainly depends on what you want, if you want a near identical copy then 18, High Quality 19-21.

But lets see how various CRF values impact the compression of a file. y-axis is file-size and x-axis is the CRF value
Again an exponential trend occurs, the lower the CRF value the significantly larger the file-size. As for image quality its hard to see the exact difference between still images when you compare the visual quality of CRF value with each other, you only notice a significant difference when its in motion. However I would suggest no higher value than 25.

CRF 21

CRF 25

CRF 30

Sunday 5 January 2014

Hollywood still uses film

It might come as a surprise to know that the majority of major hollywood films are still shot using analog film. Inception, Dark Knight, Star Trek into the Darkness, Man of Steel are a small sample of movies still shot in film [link]. 

And at first glance you might think its silly to still use film, after all film productions is significantly more expensive. The film needs to be developed(creating the negatives) then turned into digital content via a film scanner, before they can add in any CGI. Not to mention the costs of developing the film alone to be displayed.

“It costs about $1,500 to print one copy of a movie on 35 mm film and ship it to theaters in its heavy metal canister. Multiply that by 4,000 copies — one for each movie on each screen in each multiplex around the country — and the numbers start to get ugly. By comparison, putting out a digital copy costs a mere $150.” [Link]

If film is more expensive and harder to work with, why do they still use it? One reason is that film is analog and is not really subject to resolution boundaries like digital. The reason why they can remaster Indiana Jones, Star Wars (4,5,6) and all those other old films to HD(1920x1080) is because all they have to do is rescan the negative at a higher resolution. Where as with digital you're stuck with the resolution you shot in. So when 4k(3840 x 2160) comes out the old movies will be rescanned at sold again and when 8k(7680 x 4320) comes out its the same process.

Of course there is a limit to how much resolution you can get out of an analog film. Theoretically all you have to do is:  ((lpm * w * 2) * (lpm * h * 2)) / 1 000 000 = Mega Pixel count [link]
Where:
lpm = lines per millimeter
w = width of film in millimeter
h = height of film in millimeter

So according to that a 35mm(academy ratio) film at 160 lines per millimeter would result in ((160 * 22 * 2) * (160 * 16 * 2))/ 1000000 = 36MP

This is of course assuming perfect conditions which never occurs in the real world. And other have done side by side comparisons between the two. It turns out that in practice 35mm film is about 9MP and if you take Kenrock Well's lie factor into account its 18MP [link]. Digital film cameras are not yet at that level, although the gap is narrowing and more films are being shot in Digital [link] such as the Hobbit shot using the RED digital camera.

Friday 27 December 2013

Doge Coins

Recently as of the 6th December a new crypto currency has popped onto the market and gained a huge following in a very short amount of time, it is one of the fastest growing crypto currencies. That currency is Dodgecoin.



WoW much coin

With a market cap of 100 billion coins and over 13% of those already mined and with its biggest heist occurring on the on Christmas 2013 it also has tons of support in the reddit community. Dogecoin is gaining tons of attention and still growing strong.

Mining Dogecoin is similar to Litecoin since it also uses scrypt in its proof-of-work algorithm, meaning that you can configure cgminer to mine Dogecoins. Dogecoins currently get mined at a ridiculous speed, in only a few hours I've been able to mine 300 Dogecoins using a R9 270 graphics card. Ypool.net also support dogecoin with use of a proxy to work with their push through protocol.

The things that really separates dogecoins from all the other is the community, the community is extremely open and friendly and will constantly tip dogecoins to other members. And becuase of this dogecoins makes it easier to get into crypto currencies as a whole. It allows you to play around with it, with very little risk to you and you can then test the waters. Since all crypto currencies essentially work the same, you can transfer that knowledge to other currency.

So start mining play around with it the trading and get a general feel for how crypto currencies operate. It all quite simple really, it just seems scary.

Mining Dogecoins

To mine dogecoin using ypool.net you first have to download cgminer, then go to ypool.net login and select dogecoin as you currency(at current coin mode), then click on "how dig coin" and select the "Dogecoin | Doge" tab and download the proxy.

Then setup a worker under the "Many workers" -> "Many worker" links

Extract and run the proxy and keep it running, then in your cgminer folder create a new .bat file inside that put the following:

cgminer --scrypt --fix-protocol -o localhost:8332 -u <login username>.<worker name> -p <worker password>

so that it looks something like this

cgminer --scrypt --fix-protocol -o localhost:8332 -u accountName.workerName -p workerPassword 

Save and run the .bat file



DBSwVKhJax1DtUm7CKPZ3ZaRzmnGkX8aNM 

Thursday 26 December 2013

Mining Crypto Coins

Bit coins(Crypto Currency) have recently gained a lot of attention which has caused it's value to shoot through the roof and made early miners - people that get paid in bitcoins for compute power - scramble to find the coins they mined to cash in. Since the complexity and time it takes to mine bitcoins increases at regular intervals until 21million coins have been mined.

However for regular users mining bitcoins is no longer practical since ASIC (application-specific integrated circuit) for mining came along, these ASIC allows for far faster mining but can be costly, not to mention the power requirements it takes to mine a bitcoin with a decent setup is somewhat unpractical.

However there exists other Crypto Currencies such as LiteCoin, PeerCoin, PrimeCoin here a list of other crypto currencies. And one can always trade one crypto currency for another relatively easily.

So how do you mine crypto currencies? Well first you need a few things, 
  1. Type of crypto currency you want to mine (LiteCoin, BitCoin etc..)
  2. Mining hardware (CPU, GPU, FPGA, ASIC)
    1. Not all coins can be mined with GPU, FPGA, ASIC
  3. Mining Software for that crypto currency
  4. Wallet to store you coins for that crypto currency
  5. An account at a pool
So lets work with Primecoins which at this moment can only be mined with cpu, the process to mine other coins are almost exactly the same and if lost reddit will most likely have a community that can help you out.

Step 1 - Mining software
Typically just google for primecoin mining software but as of now the most popular software is  jhPrimeminer which you can get here

Step 2 - Get a wallet
A wallet is a program that will store you coins, you can get a wallet here
The wallet will take a while to update but you can start mining before it is done. 

Step 3 - Create an account
Setup an account at ypool.net here your mining software will connect to and get job to compute they will then either store the money with them or payout into your wallet. Once there click on workers there should already be one. Add a password to it and click on update

Step 4 - Setup the mining software
Go to the folder where you extracted jhPrimeminer create a new .bat file which you can name mine.bat, inside that .bat file add the following:
start jhPrimeMiner.exe -o http://ypool.net -xpt -u <username>.<workername> -p <password>

eg.
start jhPrimeMiner.exe -o http://ypool.net -xpt -u jj.worker_1 -p badpass

Where username is you ypool account username, workername is the name your worker (found in the worker tab of ypool) and password is the worker password NOT you ypool password

Step 5 - Setup payment to you wallet
To get the money to go to you wallet you have to get your wallets address which can be found in the wallet under the Transactions tab and will look like a hash string of random characters. Copy this address right click -> copy address. Then in ypool go to account-> main options and put that address in there.

Now double click on the .bat file you created and presto.

Sunday 6 October 2013

Finding Duplicate Videos

Absence

Well its been a while since my last post mainly due to work and when I wasn't working I was doing my hobbies which involved traveling a lot, so past while Ive been going places rock climbing. But I'm not going to go into too much detail about that.





So anyway in this post I wanted to talk about how to find duplicate videos files, now I have written a while ago a program that can do this with a high accuracy. I wanted to talk about the different approaches I've tried and how to go about doing those approaches.

The hard part is deciding what information about the video you are going to use to compare against other videos, the simplest is using metadata such as the name, length and resolution however this is far from optimal and many videos can go unmatched.

The better option would be to match the visual content or perceptual information from a video to other videos, or some other technique such as key frame intervals, match audio tracks.

The method I chose was to extract the RGB values for a frame and calculate its kurtosis, variance and average and then build a timeline(and array of values) of how each of these values changes per frame per colour channel. I have created a earlier post that details how to do this here (its pretty much doing that image processing and storing the results). After the timeline was created I would perform a kurtosis and variance on the timeline itself and then loosely match videos that had a similar resulting values. 

Note that is wasn't necessary to process the whole video but only about 2min of footage to build a fairly unique timeline

Using this method I was capable of correctly matching videos that had a offset, encoding artifacts, different frame rates, different resolutions combinations of all four.

Sunday 7 July 2013

JQuery Mobile Tips

So over the past month I was developing a mobile webapp using JQuery Mobile and Grails and during that time the amount of silly glitches and bugs I encountered was relatively small but SO GOD DAMN annoying. So im going to post some of the common once I encounteted and how to solve them.

First off if you're experiencing JQueryMobile performance issues add the following CSS settings.

/*JQuery Mobile Optimisation */
.ui-shadow,.ui-btn-up-a,.ui-btn-hover-a,.ui-btn-down-a,
.ui-body-b,.ui-btn-up-b,.ui-btn-hover-b,.ui-btn-down-b,
.ui-bar-c,.ui-body-c,.ui-btn-up-c,.ui-btn-hover-c,
.ui-btn-down-c,.ui-bar-c,.ui-body-d,.ui-btn-up-d,
.ui-btn-hover-d,.ui-btn-down-d,.ui-bar-d,
.ui-body-e,.ui-btn-up-e,.ui-btn-hover-e,
.ui-btn-down-e,.ui-bar-e,.ui-overlay-shadow,
.ui-shadow,.ui-btn-active,.ui-body-a,.ui-bar-a 
{
    text-shadow: none;
    box-shadow: none;
    -webkit-box-shadow: none;
}

/*Enable CSS hardware acceleration*/ 
.hwaccel {  -webkit-transform: translateZ(0); } 


The visual impact is quite small but the performance gained is about 100% If you're having strange visual problems when linking from one page to another such as flashes, blinking where the screens flickers first then displays the page, the problem is with JQueryMobile transitions, there are 3ways to fix this. Set the transition in the to none this doesnt always want to work and its to much work to maintain. 2nd you can download a plugin that fixes the transitions but doesn't work with the new JQueryMobile 1.3.1. Or do this:

This will disable transitions for all links in a page. If you want to link to a page without using AJAX is sometimes it causes weird issues with redirects and linking add this to a tag data-rel="external" data-ajax="false" If you're mobile app support rotation(Which IT SHOULD!) and you have JQueryMobile Headers and Footers that don't always resize on rotation add the following Javascript:

If you're developing for Apple iOS as well then you might encounter a small zooming glitch where the device will automatically zoom in when selecting form items, to fix this disable zooming.

And there you go that will fix most of the annoying issues you might encounter with JQueryMobile. I'll update this when I encounter more bugs and fixes.