My thoughts on Slackware, life and everything

Tag: hd

Decoding HD video in VLC

In past posts, I talked a bit about video decoding in VLC, particularly using the GPU (your graphics card’s processor) to decode frames instead of letting the software do all the work. My previous posts mostly revolved around the fact that this did not yet work in the release candidates of VLC 1.1.0 (which will hopefully be released soon).

There is good news however! Last weekend, the bug in VLC was fixed which made the player crash as soon as the VAAPI functions were called. My updated packages (32-bit and 64-bit) for vlc-1.1.0-rc3 are available now, with the patch included, and indeed I have no more crashes. Get those new RC3 packages and enjoy!

So, what is this GPU supported hardware decoding of video and why is it beneficial?

High Definition video has become a de facto standard on the internet, and lots of home video recorders save in HD format too. Playback of a HD video on your computer will stretch the limits of what your CPU can do… resulting in stuttering playback (dropped video frames) or display artefacts because the CPU can not keep up.

This is where the Video Acceleration API (VAAPI) originally drafted by Intel, and adopted by other hardware vendors (Nvidia and Ati of course) comes into play. VAAPI is a software interface which provides access to hardware accelerated video processing, using your computer’s  GPU which is very much suited for computationally intensive operations. For instance, owners of a Nvidia graphics card will notice that VAAPI-supported HD playback will drop the CPU usage from 100 to 30 or less percent.

My VLC package supports VAAPI hardware acceleration, if you add the following package(s):

  • libva: your computer will at least need this one. This is the library which exposes the VA API and adds the driver which VLC will use if your graphics card is an Intel one.
  • vdpau-video: this is only needed if your graphics card is an Nvidia. Vdpau is Nvidia’s own acceleration API and this package adds a VDPAU backend to libva.
  • xvba-video: this is only needed if you own an Ati-powered graphics card. This package adds a XvBA backend to libva. Unfortunately (for you) I do not own an Ati card, so I can not compile this software into a Slackware package. Get the sources here and compile them yourself, after you installed my libva package.

I should mention one caveat:

It depends on your hardware, how good the support for GPU-accelerated video processing is. An Intel card can only accelerate MPEG-2 video, whereas Nvidia and Ati cards will also support acceleration for MPEG-4/H.264/VC-1 video formats. Note that hardware-acceleration is not limited to HD video. VAAPI will for instance be beneficial to Atom-powered netbooks too, their Intel graphics will allow fluent full-screen playback of DVDs in VLC with low CPU usage, thereby saving your battery.

You can easily determine what your card’s capabilities are. After installing libva, run the “vainfo” command and examine the output. This is what my T410 laptop reports:

$ vainfo
libva: libva version 0.31.0-sds6
libva: va_getDriverName() returns 0
libva: Trying to open /usr/lib64/va/drivers/i965_drv_video.so
libva: va_openDriver() returns 0
vainfo: VA API version: 0.31
vainfo: Driver version: i965 Driver 0.1
vainfo: Supported profile and entrypoints
VAProfileMPEG2Simple            : VAEntrypointVLD
VAProfileMPEG2Main              : VAEntrypointVLD

Have fun! Eric

Youtube HD mp4 download

*** This post was updated with new JavaScript code on 27-oct-2009 ***

Sure, you can install Video Downloadhelper for Firefox if you want an easy way to download your favourite YouTube videos.

However, these will be downloaded in “FLV” format (Flash video). Nowadays, many videos on YouTube are available in High-Definition (HD) format and you may want to retrieve the higher quality (MP4) movies instead.

Here is a bit of JavaScript which checks if the movie you selected is available as HD 720p. If a HD format is available it will be the preferred download type (fmt24) instead of the usual “high” (fmt18) or
“regular”quality.

I got the javascript code from this page, which I found after my original javascript code stopped working (I guess Google removed the javascript functions to block folks like us):  http://googlesystem.blogspot.com/2008/04/download-youtube-videos-as-mp4-files.html . The new code is a lot uglier than the initial javascript, but it works. That page also has the same code available, nicely reformatted, as a GreaseMonkey script if you have that firefox extension already installed.

Define the following text as a bookmark and you are only a click away from downloading HD YouTube videos (in Firefox, right-click the link below and select “bookmark this link“):

javascript:var%20video_id=null;var%20video_hash=null;var%20video_player=document.getElementById(‘movie_player’);if(video_player){var%20flash_variables=video_player.attributes.getNamedItem(‘flashvars’);if(flash_variables){var%20flash_values=flash_variables.value;if(flash_values){var%20video_id_match=flash_values.match(/[^a-z]video_id=([^(\&|$)]*)/);if(video_id_match!=null)video_id=video_id_match[1];var%20video_hash_match=flash_values.match(/[^a-z]t=([^(\&|$)]*)/);if(video_hash_match!=null)video_hash=video_hash_match[1]}}}if(video_id==null||video_hash==null){var%20args=null;try{args=yt.getConfig(‘SWF_ARGS’)}catch(e){}if(args){video_id=args[‘video_id’];video_hash=args[‘t’]}}if(video_id!=null&&video_hash!=null){var%20fmt=’18’;try{if(yt.getConfig(‘IS_HD_AVAILABLE’))fmt=’22’}catch(e){}if(!document.getElementById(‘download-youtube-video’)){var%20yt_mp4_path=’http://www.youtube.com/get_video?fmt=’+fmt+’&video_id=’+video_id+’&t=’+video_hash;var%20div_embed=document.getElementById(‘watch-embed-div’);if(div_embed){var%20div_download=document.createElement(‘div’);div_download.innerHTML=’%3Cbr%20/%3E%20%3Cspan%20id=\’download-youtube-video\’%3E%20%3Ca%20href=\”+yt_mp4_path+’\’%20onclick=\’blur(this);\’%3EDownload%20as%20MP4%3C/a%3E%3C/span%3E’;div_embed.appendChild(div_download);}if(navigator.appName!=’Microsoft%20Internet%20Explorer’){document.location.href=’http://www.youtube.com/get_video?fmt=’+fmt+’&video_id=’+video_id+’&t=’+video_hash}}}void(0);

Note: this was the old code which now will no longer work:

javascript:if(document.location.href.match(/http:\/\/[a-zA-Z\.]*youtube\.com\/watch/)){document.location.href=’http://www.youtube.com/get_video?fmt=’+(isHDAvailable?’22’:’18’)+’&video_id=’+swfArgs[‘video_id’]+’&t=’+swfArgs[‘t’]}

The proof of the pudding is in the eating. Select a YouTube video, click on “pause” if you do not want to play it in the embedded video frame. Then, click on the bookmark you created and the video will start downloading. It will (always) be saved with the name “video.mp4” so you will have to rename it after the download finishes.

Have fun! Eric

© 2024 Alien Pastures

Theme by Anders NorenUp ↑