LibVLC SampleCode Thumbnailer: Difference between revisions
Jump to navigation
Jump to search
Pdherbemont (talk | contribs) Initial Creation. |
Pdherbemont (talk | contribs) Use <pre> |
||
| Line 1: | Line 1: | ||
This sample code will generate a thumbnail from any media. | This sample code will generate a thumbnail from any media. | ||
<pre> | |||
/* Copyright [[User:Funman|Rafael Carre]] (licence [http://en.wikipedia.org/wiki/WTFPL WTFPL]) */ | /* Copyright [[User:Funman|Rafael Carre]] (licence [http://en.wikipedia.org/wiki/WTFPL WTFPL]) */ | ||
#include <stdio.h> | |||
#include <vlc/libvlc.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include <unistd.h> | |||
static libvlc_exception_t ex; | |||
static void catch (void) | |||
{ | |||
if (libvlc_exception_raised (&ex)) | if (libvlc_exception_raised (&ex)) | ||
{ | { | ||
| Line 17: | Line 18: | ||
exit(1); | exit(1); | ||
} | } | ||
libvlc_exception_clear (&ex); | libvlc_exception_clear (&ex); | ||
} | |||
#define usage() \ | |||
fprintf( stderr, \ | fprintf( stderr, \ | ||
"Usage: %s input output\n" \ | "Usage: %s input output\n" \ | ||
"input being any video VLC can read, and output a png file" \ | "input being any video VLC can read, and output a png file" \ | ||
, argv[0] ) | , argv[0] ) | ||
int main( int argc, const char **argv ) | |||
{ | |||
if( argc != 3 ) | if( argc != 3 ) | ||
{ | { | ||
| Line 37: | Line 38: | ||
return 1; | return 1; | ||
} | } | ||
const char *input = argv[1]; | const char *input = argv[1]; | ||
const char *output = argv[2]; | const char *output = argv[2]; | ||
libvlc_exception_init( &ex ); | libvlc_exception_init( &ex ); | ||
const char* const args[] = { | const char* const args[] = { | ||
"-I", "dummy", /* no interface */ | "-I", "dummy", /* no interface */ | ||
| Line 55: | Line 56: | ||
"--extraintf", "" /* AT ALL ! */ | "--extraintf", "" /* AT ALL ! */ | ||
}; | }; | ||
int nargs = sizeof(args) / sizeof(args[0]); | int nargs = sizeof(args) / sizeof(args[0]); | ||
libvlc_instance_t *libvlc = libvlc_new( nargs, args, &ex ); | libvlc_instance_t *libvlc = libvlc_new( nargs, args, &ex ); | ||
catch(); | catch(); | ||
libvlc_media_instance_t *mi; | libvlc_media_instance_t *mi; | ||
libvlc_media_descriptor_t *md; | libvlc_media_descriptor_t *md; | ||
md = libvlc_media_descriptor_new( libvlc, input, &ex ); | md = libvlc_media_descriptor_new( libvlc, input, &ex ); | ||
catch(); | catch(); | ||
mi = libvlc_media_instance_new_from_media_descriptor( md, &ex ); | mi = libvlc_media_instance_new_from_media_descriptor( md, &ex ); | ||
catch(); | catch(); | ||
libvlc_media_descriptor_release( md ); | libvlc_media_descriptor_release( md ); | ||
libvlc_media_instance_play( mi, &ex ); | libvlc_media_instance_play( mi, &ex ); | ||
catch(); | catch(); | ||
/* go to position 30% to avoid introductions */ | /* go to position 30% to avoid introductions */ | ||
libvlc_media_instance_set_position( mi, 0.30, &ex ); | libvlc_media_instance_set_position( mi, 0.30, &ex ); | ||
catch(); | catch(); | ||
/* leave vlc some time to start playing */ | /* leave vlc some time to start playing */ | ||
sleep(1); | sleep(1); | ||
libvlc_video_take_snapshot( mi, (char*)output, &ex ); | libvlc_video_take_snapshot( mi, (char*)output, &ex ); | ||
catch(); | catch(); | ||
libvlc_media_instance_stop( mi, &ex ); | libvlc_media_instance_stop( mi, &ex ); | ||
catch(); | catch(); | ||
libvlc_media_instance_release( mi ); | libvlc_media_instance_release( mi ); | ||
libvlc_release( libvlc, &ex ); | libvlc_release( libvlc, &ex ); | ||
catch(); | catch(); | ||
return 0; | return 0; | ||
} | |||
</pre> | |||
Revision as of 23:35, 3 December 2007
This sample code will generate a thumbnail from any media.
/* Copyright [[User:Funman|Rafael Carre]] (licence [http://en.wikipedia.org/wiki/WTFPL WTFPL]) */
#include <stdio.h>
#include <vlc/libvlc.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static libvlc_exception_t ex;
static void catch (void)
{
if (libvlc_exception_raised (&ex))
{
fprintf (stderr, "Exception: %s\n",
libvlc_exception_get_message (&ex));
exit(1);
}
libvlc_exception_clear (&ex);
}
#define usage() \
fprintf( stderr, \
"Usage: %s input output\n" \
"input being any video VLC can read, and output a png file" \
, argv[0] )
int main( int argc, const char **argv )
{
if( argc != 3 )
{
usage();
if( argc == 2 && ( !strcmp( argv[1], "-h" ) || strcmp( argv[1], "--help") ) )
return 0;
else
return 1;
}
const char *input = argv[1];
const char *output = argv[2];
libvlc_exception_init( &ex );
const char* const args[] = {
"-I", "dummy", /* no interface */
"--vout", "dummy", /* we don't want video */
"--no-audio", /* we don't want audio */
"--verbose=1", /* show only errors & warnings */
"--no-media-library", /* don't want that */
"--services-discovery", "", /* nor that */
"--no-video-title-show", /* nor the filename displayed */
"--no-sub-autodetect", /* don't want subtitles */
"--control", "", /* don't want interface */
"--extraintf", "" /* AT ALL ! */
};
int nargs = sizeof(args) / sizeof(args[0]);
libvlc_instance_t *libvlc = libvlc_new( nargs, args, &ex );
catch();
libvlc_media_instance_t *mi;
libvlc_media_descriptor_t *md;
md = libvlc_media_descriptor_new( libvlc, input, &ex );
catch();
mi = libvlc_media_instance_new_from_media_descriptor( md, &ex );
catch();
libvlc_media_descriptor_release( md );
libvlc_media_instance_play( mi, &ex );
catch();
/* go to position 30% to avoid introductions */
libvlc_media_instance_set_position( mi, 0.30, &ex );
catch();
/* leave vlc some time to start playing */
sleep(1);
libvlc_video_take_snapshot( mi, (char*)output, &ex );
catch();
libvlc_media_instance_stop( mi, &ex );
catch();
libvlc_media_instance_release( mi );
libvlc_release( libvlc, &ex );
catch();
return 0;
}