Friday, June 06, 2014

HEVC support on Android

HEVC is the new video coding standard which even on the Desktop it is still basically under development. So, having a support for it on mobile device at this moment is even more interesting.

For library , it seems there is two major hevc decoding support currently, that is openhevc (part of libav library) and libde265. Both seems to be usable, at least for low resolution samples. However, their use require you to integrate them to media framework or pipeline like gstreamer.

If you want to just have quick look of hevc playing, right now you can just try Vitamio SDK. It already support hevc through its use of ffmpeg underneath it. It also mimic the API of Media part of Android SDK so it will be straightforward to use compare to using third party media pipeline like gstreamer as mentioned above.

Thursday, June 05, 2014

Conversion and Playing of HEVC on Desktop and Web

HEVC (H.265)  is the new emerging video coding standard. It is made as a success for the widely used H.264. It's implementation and adoption progress is quite fast. It probably because the 4k display has been out for someitme and the video streaming is  currently booming, both of which are being handled nicely by HEVC.

At the moment of this writing you can actually able to convert material to HEVC and playing it. The implementations are mostly still in beta stage and some are not avaiable through the more common publicized channel, but it's quite usable from my tests so far. The quality is quite good too in term of visual quality and compression ratio. So, you can already play around with the technology at this stage.

Conversion :  x265 and Handbrake Nightly Build

x265 project probably is the most used HEVC converter right now. It has progressed quite far, below is the quote from the author on one of the forum :
x265 development is going well.  x265 is often able to exceed the HM reference encoder in quality, with performance that is orders of magnitude faster.  The x265 HEVC encoder is easily able to encode with quality / compression efficiency that far exceeds the best H.264 encoder available, x264.  We've just passed the 0.7 milestone.  Although we have more algorithmic improvement and performance optimization on the development roadmap ahead, x265 is quite usable today, and it includes many advanced features.

So, it is quite a safe bet to choose x265 project for HEVC encoding purpose. However, using it directly means using CLI which is cumbersome and would require manual demuxing and remuxing, so it’s better to use proper video conversion application.

There is no official release version of full-featured video converter that uses x265 yet. However, Handbrake-nightly-build already integrate x265 whitin. The developer said that they won’t be  releasing it until HEVC standard more widely used which probably will still a while. So, you just have to use the nightly-build if you want to have access to HEVC conversion on Handbrake for sometime ahead.

Unfortunately, currently it only exist on Windows version of Handbrake. So, no support for other platform for now.

Now, about the playing.

VLC Nightly Build and Playing on Browser

The latest release version of VLC (2.1.4) can not play HEVC output in container (muxed) yet.  It will complain when you try to play the file you encoded with Handbrake above.  However, hevc playing support is currently progress and can be tested on VLC-nightly-build version (2.2.x). It works well playing output from Handbrake when tested.

Also, the good thing about VLC is that it has browser plugin support for Mozilla and Activex(IE) so it can be used to play HEVC content on the browser. It currently only support Windows though but the plan is to have it on other platforms when 2.2.x finally released. This would be interesting since it means you can now start streaming HEVC stream to wide range of targets.

Another alternative for the web/browser support for HEVC is DivX Web Player whichs seems to be free although not open source.

Monday, April 14, 2014

Better way of combining path in C#

You could do string operation to construct path as below :

string path = path1 + "\\" + path2;

However, more portable and cleaner way would be to use Path.Combine as below :

Path.Combine(path1, path2);

The above avoid you to make manually ensuring the correctness of path separators.

Monday, March 24, 2014

Choosing Logging Library for .Net : NLog

When it comes to logging, printing it out yourself to console or file probably the most straightforward way. However, if you want to get more structured in your log, with level and flexible on/of switching you'll need a more dedicated logging library. However, like any library, choosing the sweet spot where you get the feature you want but with the least complexity and learning curve can be challenging.

As for logging, when I research around the two that pop up most is log4net and NLog. The choise is pretty simple though, log4net is good but pretty outdated now while NLog is quite active, well-supported has rich feature. So, the choice goes to NLog.

Quick Usage :

After you link the library (using NuGet or manually). Declare the logger in your class :

private static Logger logger = LogManager.GetCurrentClassLogger();

and call at the place that needed it :

logger.Debug("log message");

You can add a lot of additional details to your log with its predefined variables. You can consult the manual to see what is available. Also, since you declare logger on each class, it can automatically  print in which class and the point where the log is called. It is quite useful for debugging.

Monday, March 10, 2014

Lesson about delegation from OpenCL

Using OpenCL and the complexities / benefits that comes with it reminds me of an issue of trade-off in delegation. You can always do things the simple straightforward, serial way but there is a limit of how much and how fast it can finish the tasks. We can scale things better by utilizing more external agents and manage it. However using additional agents means delegating tasks to those agents and manage the overhead and unpredictability that comes with it. This is why the code to achieve the same thing using OpenCL can be quite complex since you need to manage the data and logic that comes to and from those computing units and get them to work together properly.

It's not just cost that is increased though, the risk is also higher. When you delegate, you add another factor with its own set of quirkiness to your system. Each agent you add, you add another risk of it fail in some way and effect the overall system. In OpenCL, certain GPU might not behave as it should, your calculation might fail in certain configuration. So, you will need to add more activities to manage the risk. How it can be anticipated, localized and how the system can cope gracefully when it happen.

So, since delegation is not free it is important that the scale of the problem would need to justify the use of delegation.  You can add more things, method, people to your system, but when it does not fit your scale, it will become a burden since your output, what you get, is lower than what you need to expense. In term of OpenCL, the low complexity or low number of calculation probably not worth the trouble. For example, even when you ding the formula is complex and can be paralellize but if your expected data to be processd is not much, it probably better to just code it the traditional way.

Delegation can be costly and risky, but if you need your solution to scale better, the return can be very much worth it.

Friday, February 28, 2014

Translating Traditional Program Logic to OpenCL

If you just started to look at OpenCL and see the example of the code, it can be quite confusing on how it got that way from its traditional program logic counterpart. Take a look at an example of comparison below taken from PDF Overview on OpenCL site :

You can see that the calculation is intact but you can't seem to find where the for loop counterpart is.

It is because, the logic has been separated between host (your main program) and kernel (that will be sent to device). So, you need to look at both of them to get the whole picture. There is some data partitioning done that you can take a look at the code at the host. Together with the batch processing happen in kernel code you can start to see the implied loop there.

Due to its parallelism and batch processing nature, the logic in OpenCL can look more declarative and more separated compare to traditional one. So, the logic that you expect to find will probably be implied somewhere in host and kernel code. This could help if you try to read the existing code.

Thursday, February 27, 2014

Getting Started with OpenCL

I started working with OpenCL recently on the project at work. It's quite exhausting to learn initially since OpenCL has quite steep learning curve. However, once you have started to picked up some of the core concept, it could be quite interesting. Also, you will add another valuable tool to your programming arsenal, especially in the aspect of performance and speedup. You will start to be able to exploit not just CPU but also any other computing device that exist on the system like GPU quite conveniently.

Here's summary and pointers of how to get started with it from what I note so far.


You can get an initial overview from the surces below :

 As for its Wikipedia Page, I don't find it really informative at the moment, at least if you want to get an overview of what OpenCL is and its relevance.

As usual, google search and some blog entries would not hurt too. However, it's better not to take too much time researching things online since I think your time is better spend reading the book below.

Book : OpenCL in Action

There is not many technical book that you can enjoy reading cover to cover. This one is one of them. It's better you read from beginning to end serially. It build up from chapter to chapter. Also, it does not cross reference things too much between materials which could be annoying on some technical books. The materials coverage is very good, from the history, introduction to advanced topics.

If you have some questions on your mind from reading other sources previously, there is a good chance that you will start to piece things together when reading this book. It gives a good foundation for understanding why OpenCL is the way it is. OpenCL syntax and functions will still be quite overwhelming even after you finished with the book but knowing the concept behind will make it much more manageable.

I find the highlights of the book is its use of analogies that helps a lot in explaining the abstract concept and architecture of OpenCL.

Revisit Specification and Reference Card

If you have skimmed the specification and reference card above, it's time to revisit it again. You will now find it much more clearer now and they are starting to be more useful. It will also add more details from what is covered on the book. Personally, I really like the layout on reference card which help in getting a good high level picture of different parts of OpenCL with it's colorful boxes and groupings.

At this point, you can start to work on your specific issues and continue learning from there. As usual, after the initial learning, the actual work is where we will learn most. This is especially true in complex technology like OpenCL.