Le fourre-tout à Geo

Aller au contenu | Aller au menu | Aller à la recherche

Tag - VLC media player

Fil des billets - Fil des commentaires

mardi, décembre 8 2009

Utterly useless uses of VLC

Last time, I told you how to take a video from some website and see it in VLC media player. Pretty cool, huh?

Yesterday, I was trying to think of funny and useless thing to do with VLC, and it occured to me that Lua gives a lot of opportunities to do that.

So, it is my pleasure to present you with the "Flickr diaporama Lua script for VLC"!

--[[

 Copyright © 2009 the VideoLAN team

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]]

-- Probe function.
function probe()
    if vlc.access ~= "http" then
        return false
    end
    vlc.msg.info( vlc.path )
	koreus_site = string.match( vlc.path, "www.flickr.com" )
    if not koreus_site then
        return false
    end
    return (  string.match( vlc.path, "sets" )  )
end

-- Parse function.
function parse()
    _,_,artist = string.find( vlc.path, "photos/(.-)/sets/" )
    vlc.msg.info( artist )
    while true do
        line = vlc.readline()
        if not line then break end
        if string.match( line,"<div id=\"setThumbs\"") then
            start = 0
            pl = {}
            line = vlc.readline()
            while true do
                _,start,url = string.find(line, "<img src=\"(.-)_s.jpg\"", start)
                if start == nil then
                    return pl
                end
                _,_,description = string.find(line, "alt=\"(.-)\"", start)
                opt = { ":fake-duration=5000"; ":fullscreen" }
                pth = "fake://" .. url .. ".jpg"
                table.insert(pl, {path = pth; name = start; title=description; 
                description = description; artist = artist;options=opt})
            end
        end
    end
end

So, how does it work? Give some Flickr album url to VLC, like this one with the funny cats. VLC will parse the page, find all the thumbnails urls (the ones finishing with _s.jpg), deduce the urls of the the full pictures (replacing "_s.jpg" by ".jpg"), and show them. As simple as that.

The fake access module is used to tell VLC that "hey, this is not one picture, it's a video with a lot of frames like this picture". I added the "fake-duration" option, to choose how much time (in ms) the picture will be displayed, and the "fullscreen" option. You can of course tweak it, and, let's say, use the directx wallpaper mode to have a flickr diaporama as your wallpaper!

To use this script, you can either place it in C:\Program Files\VideoLAN\VLC\lua\playlist, or in C:\Users\YOURUSERNAME\AppData\Roaming\vlc\lua\playlist.

I strongly encourage you to try and write your own Lua scripts, it's really easy! Come to the Videolan forum to share your scripts or ask for help.

See also

mercredi, novembre 25 2009

VLC: now with DxVA support

So, this is it. My summer of code has been merged into the main tree, thanks to Laurent's hard work!

You may test and enjoy the GPU acceleration for your H.264 videos using future nightly builds!

lundi, novembre 23 2009

So you want to contribute...

...But you don't want to go through the (sometimes painful) process of building the whole VLC. Well, you can build your own plugin separately. Here is how to do it (this tutorial is Windows centric because 1: I'm too lazy to launch my VM right now; 2:it's easy to do on Ubuntu for the linux trolls):

Ingredients

  • The plugin headers. You can find them in C:\Program Files\VideoLAN\VLC\sdk\include\vlc\plugins on Windows.
  • The libraries. Copy libvlc.dll and libvlccore.dll (you will find them in C:\Program Files\VideoLAN\VLC)
  • A building environment (on Windows, use Mingw+MSYS)
  • Some coffee

Recipe

At the time of writing, the wiki page wasn't really explicit, so I'll detail all the steps, for an example audio filter that switch the left and right audio streams (adapted from the trivial channel mixer plugin).

Let's begin by taking a look at what code you can find in a VLC plugin, like the trivial channel mixer plugin.

Preamble

First, the copyright and license:

/*****************************************************************************
 * trivial.c : trivial channel mixer plug-in (drops unwanted channels)
 *****************************************************************************
 * Copyright (C) 2009 the VideoLAN team
 * $Id: 3ecc0dd8363a50c40f7f123a9e2724a943c0c83c $
 *
 * Authors: Name <email address>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

That's not useful to run the plugin, but you'll have to add it when you send a patch to VideoLAN.

Next, the headers:

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_aout.h>
#include <vlc_filter.h>

the config.h file is generated from the configure step when you build the whole VLC. Each module must include at least vlc_common.h and vlc_plugin.h. The other headers included depend on the type of plugin you want to build (find it in the code of plugins from the category you want).

Note: you will probably need something more like the following for your audio plugin.

#define _(str)  (str)
#define N_(str) (str)

#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_messages.h>
#include <vlc_aout.h>
#include <vlc_filter.h>
#include <vlc_fourcc.h>
#include <vlc_block.h>

Don't hesitate to grep the include directory if you have some missing functions or unknown structures.

Module descriptor
static int  Create    ( vlc_object_t * );

static block_t *DoWork( filter_t *, block_t * );

vlc_module_begin ()
    set_description( N_("Audio channel inverser") )
    set_capability( "channel inverser", 1 )
    set_category( CAT_AUDIO )
    set_subcategory( SUBCAT_AUDIO_MISC )
    set_callbacks( Create, NULL )
    add_shortcut( "channel_inverser" )
vlc_module_end ()

First, you see the prototypes of functions used in this plugin. Create is used, well, to create the plugin, and DoWork will handle all the audio data.

Then, the part between vlc_module_begin and vlc_module_end is a set of macros used to declare the plugin structure. This part is used to define which type of module it will be. These macros create a function exported by the plugin and called when VLC looks for a suitable plugin.

If the module can be used, the core of VLC stores the callback (here, the Create function) and calls it later to initialize the plugin.

Create function
static int Create( vlc_object_t *p_this )
{
    filter_t * p_filter = (filter_t *)p_this;

    if ( (p_filter->fmt_in.audio.i_physical_channels
           == p_filter->fmt_out.audio.i_physical_channels
           && p_filter->fmt_in.audio.i_original_channels
               == p_filter->fmt_out.audio.i_original_channels)
          || p_filter->fmt_in.audio.i_format != p_filter->fmt_out.audio.i_format
          || p_filter->fmt_in.audio.i_rate != p_filter->fmt_out.audio.i_rate
          || (p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32
               && p_filter->fmt_in.audio.i_format != VLC_CODEC_FI32) )
    {
        return VLC_EGENERIC;
    }

    p_filter->pf_audio_filter = DoWork;
    return VLC_SUCCESS;
}

The initialization function is used to set some configuration options, initialize memory structures, etc. Look at other modules to see how you can store variables, and how to create preferences variables.

Here, we verify that the number of channels, the format and the bitrate in the input and output are the same, and that the audio isn't stored in float numbers. If it's ok, we give to libvlc a pointer to the DoWork function, which will be called when audio data is available.

DoWork function
static block_t *DoWork( filter_t * p_filter, block_t * p_in_buf )
{
    int i_input_nb = aout_FormatNbChannels( &p_filter->fmt_in.audio );
    int i_output_nb = aout_FormatNbChannels( &p_filter->fmt_out.audio );

    block_t *p_out_buf;
    if( i_input_nb >= i_output_nb )
    {
        p_out_buf = p_in_buf; /* mix in place */
        p_out_buf->i_buffer = p_in_buf->i_buffer / i_input_nb * i_output_nb;
    }
    else
    {
        p_out_buf = filter_NewAudioBuffer( p_filter,
                              p_in_buf->i_buffer / i_input_nb * i_output_nb );
        if( !p_out_buf )
            goto out;
        p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
    }

    int32_t * p_dest = (int32_t *)p_out_buf->p_buffer;
    const int32_t * p_src = (int32_t *)p_in_buf->p_buffer;


    /* Reverse-stereo mode */
    int i;
    for ( i = p_in_buf->i_nb_samples; i--; )
    {
        *p_dest = p_src[1];
        p_dest++;
        *p_dest = p_src[0];
        p_dest++;
        p_src += 2;
    }

out:
    if( p_in_buf != p_out_buf )
        block_Release( p_in_buf );
    return p_out_buf;
}

The DoWork function manages the buffers and copy them from the input to the output.

Now in the oven

(No preheat please)

Here is the content of my Makefile:

all:
	gcc -I/home/Geal/module/include -L/home/Geal/module/ -lvlccore -shared -std=gnu99 \
	-DWIN32 -D__PLUGIN__ -DMODULE_STRING=\"channel_inverser\" module.c -o libchannel_inverser_plugin.dll
/// 

Adapt it to the name of your plugin, and to the path you use, or copy the one from the wiki. My Makefile only contains what is strictly necessary to build your plugin. Now:

Geal@chezmoi ~/module $ make ///

Eat it while it's still hot

Now, you just need to copy your dll in the plugins directory of VLC media player, and try your plugin! I don't guarantee that it will work (more like I know that it doesn't work and I'm too lazy to fix it because I won't commit it), I just gave you the structure and the Makefile you need to be up and running. Note that you can use the following command line options to help in your development:

  • -vvv: displays a LOT of debug messages
  • --verbose-objects: helps you filter the messages (example: ./vlc -vvv --verbose-objects=-all,+direct3d to display only the messages related to the direct3d module)

Don't forget to send a patch to VideoLAN (subscribe to the vlc-devel mailing-list and attach it to a message). To integrate your module, please read the HACKING file at the root of the VLC source tree.

Now, show me your code!

lundi, septembre 21 2009

Enable DEP and ASLR with MinGW

Every now and then, we see reports about vulnerabilities in numerous applications: buffer overflows and heap overflows are unfortunately very common. Until we find a way to teach all the developers how to think about security while coding (and then, there will still be a lot of programs to fix), we can try some tricks to prevent exploitation of vulnerabilities.These tricks have been Visual Studio only for a long time (and even with VS, not everybody uses them), but now, we have tools to protect as well programs built with GCC.

DEP and ASLR?

DEP provides support for NX bit since Windows XP SP2 and Windows 2003 SP1. This feature flags some part of the memory, like the heap and the stack, as not executable. Then, the shellcodes stored in buffers will have a hard time trying to run.

ASLR randomizes the address of function entry points. This way, exploits with hardcoded functions address like ret2libc attacks won't work.

These two mechanisms are not silver bullets: they can be bypassed. But it makes the process of writing an exploit much harder.

Using it

If you build your program with Visual Studio, it's easy and documented. If you're using MinGW to build for Windows, it's not really documented, but it's easy too.

To mark an executable as DEP and/or ASLR compatible, you have to change the DllCharacteristics field in the Portable Executable header. You can write your own PE modification software, or use one of these two solutions:

Peflags

Peflags is a program you can find in the rebase package from Cygwin. Peflags builds fine with MinGW in MSYS, but you have to tweak a bit the source if you want to run it from Linux, or directly take my modified source.

It is really easy to use:

peflags --dynamicbase=true --nxcompat=true myexecutable

You can add this command to your Makefile. It has to run on the executable and all the dlls it loads, to be effective. If you want to verify that your program has enabled the flags, do:

objdump -p myexecutable

And look for the DllCharacteristics flag. If its value is 140, congratulations! Your executable is now compatible. You can also verify with Process Explorer, from SysInternals. Here is the line for VLC media player:

DEP and ASLR

LD

In March 2009, the support for this DllCharacteristics flag was added to ld, but the new binutils package containing the updated ld hasn't been released (yet). The command line is more or less the same.

Remarks

  • You have to add the flags to every executable used by your program. If you load a vulnerable dll without DEP, it won't protect you.
  • I'll say it again: it's no silver bullet. You still have to fix your bugs. It's a lot harder to exploit, but some may be able to do it.
  • VLC media player now has peflags in its building toolchain! I'm waiting for the release of the next binutils, and then I'll use the new ld.

samedi, septembre 12 2009

VLC tricks: get comfortable

Last time, I showed you how to customize your interface with new skins. I hope you are happy with it :)

Now, I will tell you how to tune VLC to meet your needs. I like it when it just runs, with no tweaking. But what I would like even more is customizing the way it runs once and for all, and forget about it.

So, here is a compilation of VLC settings you may find useful, and info on where you can find them in the preferences:

  • Always on top: in Video. If, like me, you often watch a video while coding/reading/chatting, having a small video window on top of the others in a corner of the screen is convenient.
  • Deinterlacing: in Video->Filters->Deinterlace. I have some DVDs with interlaced videos, and it's annoying to set deinterlacing for each video. Here, choose the deinterlacing algorithm you prefer (test with multiple videos).
  • Sharpening: in Video->Filters->Sharpen video. Here again, set as you see fit (videos will appear a bit more clear).
  • Subtitles: in Video->Subtitles/OSD. You can choose the folder where VLC will search for subtitles, and choose the color and font in Video->Subtitles/OSD->Text renderer.
  • Interface tweaks: in Interface->Main interfaces->Qt. Use Automatically save the volume on exit. you can uncheck Show notification popup on track change if the systray popup bothers you.

Last but not least, the hotkeys: you can control VLC directly from your keyboard. You can see them and change them in Hotkeys in the preferences (not that hard to find...). Here are the handy ones:

  • Play/Pause: space
  • Fullscreen: F
  • Leave fullscreen: Esc
  • Next: N
  • Previous: P
  • Mute: M
  • Increase subtitle delay: H
  • Decrease subtitle delay: G
  • Increase audio delay: K
  • Decrease audio delay: J

There's a lot of configuration settings, so feel free to test the remaining ones and tweak your VLC :)