Smooth video playback @Youtube [Linux]

So recently I’ve been researching about how to get a better video playback experience on Linux when browsing sites like Youtube. Video playback from the early days of Linux was most of the times a headache, especially because there were not many “good” alternative to a lot of proprietary codecs. Especially now that flashplayer is long dead and is no longer being supported widely, we look up to html5 to solve our media playback woes online.

But the thing is html5 doesn’t solve our problem yet. On sites like Youtube, vp9 is the codec that is being served by default when html5 is enabled on your browser. Vp9 is a successor to vp8 and is about 5-15% improvement over it’s predecessor but on the downside hardware acceleration for vp9 is not built onto most hardware other than the latest smartphones like the Samsung Galaxy S6, etc.

Hardware based decoding is important because it is more efficient than software based decoding, not only in terms of raw performance but the overall cpu usage goes down resulting in less energy being used on your laptops or mobile devices. Therefore hardware based decoding also helps conserve battery life by a big margin when watching videos.

Even if hardware acceleration of vp9 is built into your hardware, the software side of things aren’t ready yet on almost all platforms since vp9 is still a pretty recent development and the industry needs some time to catch up.

Anyway long story short, I turned towards various browsers at first without doing much research hoping that they would magically solve my problem but that was not the case. After a while I learned about this open sourced api being developed by intel (vaapi) thats allows hardware decoding of various codecs using the built in intel gpu on most CPUs. Vaapi on Arch Linux can be accessed by installing the packages “libva-intel-driver” and “libva”. On other distros should be something similar.

Another thing I discovered while testing the browsers is that Firefox for some reason uses a lot more cpu during video playback than a Google chrome based browser like Chromium although they both rely on software based decoding methods. It probably has something to do with how Firefox renders the video internally.

Anyway, the bad news is that vaapi doesn’t yet support vp9 decoding but what you can do is install a browser plugin that forces h264 codec only and then take advantage of hardware acceleration using vaapi as h264 decoding is supported. In my case I used an external player (mpv) with my custom config  (placed in ~/.config/mpv/config) and a firefox plugin called open-with and I can just right click on any video and select open_with mpv to have awesome video playback with negligible cpu usage.

Before hardware accelerated video playback my average cpu usage on Chromium was around 20-25% where as on Firefox was around 40-50%. After hardware acceleration on my netbook with n3700 processor, cpu usage is less than 10% using Firefox. Power usage dropped from 9-10W to 5-6W. That’s a pretty big improvement not to mention the video playback seemed more crisp compared to the software decoded version.

It might seem that I was complaining about Firefox at the start, but after switching video playback to mpv it seems to be a much better solution than even chromium.

If you have some tricks of your own, feel free to comment and share below!:)

 

So you use Linux?

So recently I saw this video explaining the frustrations of using Linux on a daily basis (Click Here), and it reminded me of the same thing.

As a Linux user who has been using Linux non stop for over 6-7 years I can totally relate.

I’ve blogged about this in the past on how life as a Linux user is quite challenging if you don’t get the right hardware. Even if you do get the right hardware, getting things to work the way you want might take more than just few hours of tinkering. As a beginner Linux user, if you value your time then just closing your eyes and going for Windows sometimes is a better alternative if you want to get some real work done.

There’s a steep learning curve when it comes to Linux, that’s mainly because Linux is an open system and there’s just too many choices that you can make. There’s no right or wrong way to do something. That leaves a lot of Linux users (especially beginners) frustrated because they are so used to pointing and clicking on closed systems like Windows that they just expect things to work in a minimal number of steps. Actually it’s not that simple on Linux because it is the operating system built by hackers and programmers and they have this mentality that you should be able to quickly edit a config file somewhere, do some research and make things work. That’s the mentality that makes Linux seem so complex for beginners in my opinion because they don’t feel comfortable with the idea of changing the way they usually do things. People are afraid of change and it’s one of the many reasons why desktop Linux may never be a reality, but it’s good to see that Distros like Ubuntu are giving it a shot anyway.

Having spent 6-7 years of my life learning and taming the wild beast that is Linux, I’ve learnt a lot of stuff and I’m thankful to the community, the forums, the users for being so generous with their time, sharing knowledge and most importantly for being so patient with me. Without Linux and the community behind it I would not be able to define my identity as I’ve grown so attached to it and it has slowly won over my heart. It’s like falling in love with a wild beast, that initially barks and whines at you. Then slowly you start to understand the reasons behind why it is misbehaving. It took me a lot of frustration, sleepless nights, doses of caffeine and socializing with geeks over IRC to tame this beast but in the end it is totally worth it and I have no regrets.

Yes, it is frustrating as a Linux user but once you get to the point that you have figured every single detail about what makes the underlying operating system tick you have nothing to worry about. It’s like reaching GOD mode on your computer, and you have complete control over everything…from the type of cipher being used to encrypt your hard disk to the firewall rules that allow packet to traverse your network, everything is under your control with no abstractions, no bloat, no hidden third party code written by uncle Gates that might spy on you. It’s just your hand written configurations and the Linux kernel bridging the gap between you and your hardware.

Even though I love Linux so much but I definitely would not recommend it to a friend or family. That is because the headache and the babysitting that you have to do or the investment of time towards someone completely new to Linux is not worth it. You may be thinking that may be I am selfish, but actually I have a point. Out of 10 people only may be 2 or at most 3 people would have the time or interest to learn how to do things differently and most people that I’ve seen from my experience don’t want to consider investing time towards learning a new operating system. Especially one where if something doesn’t work you try to fix the problem yourself.

 

Linux Mint Hacked (/rant)

So I recently  heard in the news that a quite popular Linux distro that is currently a competitor to Ubuntu (Linux Mint) has been hacked. The hackers took control of their servers and infected one of the downloadable ISO.

It’s not the first time a distribution has been hacked and I really don’t blame the Linux Mint admins for that. Security is a quite complex topic and it’s even harder if you’re on the defender side. All the attacker needs to do is find a single flaw,  whether it’s a plugin on the blog you’re using or something that might seem really insignificant. But the results can be really devastating even though you have taken strict security measures on the network side of things.

Anyway, what I really wanted to talk about is the important role gpg has to play in this. For example, I’ve recently made a fresh Arch Linux install from scratch. Before getting started I had to verify the integrity of the ISO that I downloaded to make sure the downloaded image is the same image that I’m supposed to receive from the server. But just verifying the integrity of the image successfully doesn’t guarantee that it is the exact image that the original authors had created. To verify that it is coming from the intended author I also had to download the signature file that came with it, receive the key from key-server and verify the signature using gpg.

This extra step of verifying the signature is something that I’ve noticed on distros like Arch, Gentoo, etc. Personally I think gpg is not that hard to use, although some people find it confusing and even most distros like Ubuntu (back when I was using it) doesn’t provide this extra step of signature verification.

So why is this important? Well let’s say in the case of Linux Mint after it was hacked, if signature verification was there the users could see if the image came signed with a key from one of the official developers and could further inquire about it if anything looked suspicious. I don’t think it’s easy for a random attacker to forge the signature of the developers but it does provide an extra layer of security on the user side.

Anyway, I actually support the decision made by the Linux Mint community to immediately announce to it’s users of the compromise and taking appropriate measures. There are perhaps a lot of distros out there that don’t like to reveal such stuff publicly for fear of losing their image in the community. But Linux Mint developers do really care about their users so props to them for being so transparent about the whole thing.

P.S. If you’re really paranoid about your security/privacy, try doing an Arch Linux install from scratch. I know it takes a lot of time on your first run but the learning experience is totally worth it. Goodluck!:)

 

 

 

 

 

Efficient browsing / productivity with Vimium

For quite a while now I’ve been doing pretty much everything on Linux with just keyboard shortcuts. I’ve switched to a tiling window manager called i3 which eliminates the need for a mouse as everything from resizing window frames, making them full screen or tiling them in a certain way can be done with the press of a few buttons. I’ve found that it increased my productivity by quite a big margin and I feel like mouse was just a block in the road towards productivity.

Only place mouse was needed for me was for browsing the web. Luckily, even though a bit late I’ve found a way to even get rid of that by using a plugin called Vimium for Chrome. I’m a big time Vim user and it’s kind of funny that I thought the learning curve that I had to go through for vim and the hours I spent learning it could only be used for stuff like coding / text editing. The time I invested learning vim actually pays off when you consider plugins like Vimium, which allows you to use the same keyboard shortcut like features you’re used to in Vim and works as a replacement for your mouse.

It’s actually difficult to imagine how the experience is like when you consider the fact that there’s no mouse at all, you just press keys and things work the same way as if you had a mouse. From opening links in new tabs, scrolling, interacting with custom frames, clicking on elements, opening older tabs from history or going through your bookmarks; everything works smoothly as if you’re doing it with a real mouse.

I’m starting to get used to it, so far it seems pretty easy to get started and I highly encourage people to try it out and see for yourself how it’s like. You don’t actually need previous experience with vim and the shortcuts can be configured as the plugin is quite flexible. Try it out, who knows you might even like it:)

 

 

 

 

Linux Kernel Module / Hardware Tinkering

When I first got into the Linux world (5-6 years ago), I was a beginner at the time and as usual if something didn’t work out of the box (hardware / software) I used to blame the distro and move on to the next one. I thought it was a “fair” way to do things coming from the Windows world as a Windows user. Given that there were so many distros out there at the time it wasn’t actually a bad move though, but I knew that I’d have to change my mentality if I were to survive in the Linux world.

Slowly, as my experience and skills with Linux matured I realized that I actually enjoyed if things didn’t work and I wanted things to not work as expected so that I can learn how to fix it and make it better.

In most cases just a simple google will work, but if the problem is complex; like something related to hardware perhaps the only way to go about fixing it is by being really persistent. Like the old saying goes “If there’s a will, there’s a way”.

Today I will share some of the little things I’ve learned as a Linux user on how to mess around with kernel modules, learn what features of your hardware are supported by the module and how to disable / enable them.

Mainly I’m documenting this as a self reference in case I forget somethings in the near future.

Okay first of all, if you want to see what hardware you have; which kernel modules are being used by them or in general learn more about what’s happening with your hardware you can use the following commands:

1) lspci -k
2) lshw -short
3) inxi -b
4) lsusb
5) dmesg | grep -i “keyword” //Replace keyword with something specific to your hardware / kernel module

Note that you may have to install inxi and lshw, they’re by default not installed on most distros.

Okay now, let’s say you’ve found the kernel module being used by the hardware you want to debug (Command #1).

You can see what options are supported by the kernel module with the command below.

modinfo -p [module name]

In my case, I wanted to debug my internal atheros wireless card ath9k.

To see what parameters / options are enabled / disabled by the module at the moment you can try:

systool -v -m [module name]

Selection_008

Note that in the section parameters, 1 means enabled and 0 means disabled.

By default most distributions try to have some basic module configs so that your hardware works as expected or so that some other module doesn’t interfere with your hardware by blacklisting them. But it’s not practical to predict what kind of hardware you might have and there’s so many different types of hardware, so it’s better to debug your own hardware and tune the configs to something that is optimal for you.

At the time when I was debugging my wireless card, the powersaving option was disabled (ps_enable=0) and hardware crypt was enabled (nohwcrypt=0) which is why my wireless card was using a lot of power and was slow at the same time.

You can configure them to use the parameters that you want by writing a config file in the /etc/modprobe.d/ directory. What you name the file doesn’t matter, but it needs to have a .conf extension for it to be recognized as a config file.

Usually it’s a good practice to name the file according to the module name, in my case it’s ath9k.conf.

This is the format of how you enter the parameters in the config file:

options [module name] [parameter=value]

Selection_009

You can have multiple parameters side by side separated by space.

After the changes have been written, you can simply remove the module and reload it to have the changes implemented or a reboot works fine too like in windows:)

Removing module:
modprobe -r [module name]

Reloading module:
modprobe [module name]

Another thing that was interesting to learn was that let’s say there are some hardware or module that you want to disable or don’t want running.

For example, I find that I never really use the webcam and bluetooth devices on my laptop so disabling them is also a good way to save power and increase battery life.

You can blacklist modules by just having a config file with they key word blacklist followed by the module name. But in some cases, a module may be a dependency to another module and therefore blacklist feature might not work as expected and the module might end up being loaded anyway.

So to prevent that you can write the config file this way:

install [module name] /bin/false

For those wondering the bluetooth module by default is btusb and webcam module being uvcvideo.

Anyway, that’s it for today. I really didn’t wanna make this post since a lot of this info can be found publicly or in Arch Wiki.

But a part of me insisted that I do since a lot of stuff I learned were by trial and error. Usually Arch Wiki tells you what to do but not why, it is up to you to figure out why and that’s the most important part of the learning process in my opinion.

Hopefully this might be helpful to some of you:)

Cutting off the slack

I’ve been an avid Linux user and a fan of opensource for many years; I’m fascinated by how the Linux community always manages to find solutions to problems that are limited by our own imagination.

For far too long I’ve been guilty of slacking, wasting time with plenty of distractions (social media, news, gaming, etc.) and doing non trivial tasks; also I have not contributed much to Opensource and the community. I’ve decided to completely go offline on my life with social media such as facebook, reddit, twitter, youtube and things that have no purpose in life other than to waste your time and make you a consumer of news and entertainment. They say time is the most valuable resource in the universe, I wish I could have realised that earlier.

Also from now and on words I’ve decided I just don’t want to be someone who just watches from the distance and benefits from opensource, but I will actively contribute and give back to the community that has always stood beside me in my time of need.

In my lifetime, I’ve used various Linux distributions from Ubuntu to Mint, Sabayon, Crunchbang and now in Manjaro, hoping to finally switch to Arch. Even though I no longer use some of the mentioned distros but the experience that I’ve had on forums / irc with the moderators and the more advanced users as they stood by and taught me the ways of being resilient and finding solutions to problems no matter how impossible it might seem is something that will always stay with me.

Using the distribution as a normal user is one thing, but in my point of view the real fun part is contributing in the forums and learning new stuff that might seem too daunting at first. Found a fix to a bug that has been bothering you for a long time? Good, now you can share on the forum where it’ll help thousands of people who have been dealing with the same issue but had no clue on how to fix.

The forum is not only a place where one can gain a more mature understanding of various kernel / hardware issues, but they can meet with people with similar interests. Perhaps they use the same window manager, have some cool scripts / configs that can make things more efficient and useful for you. The best part is that if you’re a coder, you’ll be able to work on your coding skills by forking existing code from github and see where you can take it from there.

I hope to post regularly on my blog from now on and hopefully I will get back with more useful posts that will make a difference.

Thanks for reading:)

Using YouTube playlists as your offline music collection [Linux]

youtube

Hi guys! Been so long since I’ve made a post…well over a year now. Work, studies and commitment to life keeps me busy but it’s good to be back every once in a while.

I’m a big music fan and at times I use various YouTube  music playlist to listen to a good collection of cherry picked music that interests me. Also there are times when I don’t have internet connectivity so a thought came to my mind on why not just get the entire playlist backed up locally so that I can listen to good music whenever I want.

So first of all since I’m a coder, I thought to myself on why not just go ahead and create a script to automate the entire process; from parsing and downloading content to batch processing and conversion of the videos to be audio only. But then again one of the things I’ve learned in the long run as a coder is to make good use of code reuse; in other words, why reinvent the wheel when there are already existing solutions out there that addresses the problem. This led me to the excellent feature friendly youtube downloading and conversion software for Linux known as youtube-dl.

You can download youtube-dl from your local linux repo or you can go to their hosting site over here.

TLDR; This is the command format to make youtube-dl download all the tracks along with cover photos from a given playlist and convert it to audio only without going through a hiccup.

youtube-dl –yes-playlist -c –write-thumbnail -x -i [ url ]

The command line flags are pretty much self explanatory; youtube-dl works smooth and with in minutes you will have your favorite genre of music all backed up for your convenience.

Disclaimer: The author is not responsible for violation of youtube’s copyright policy in anyway, what you do with this information is your own responsibility. This post has been made for Educational purposes only.