libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 7cf17f598af0dc0194beb5224d5493b83959f70e
parent 21d4464f2dd32afe60f3c5cb6d59723f7241a80e
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 18 Dec 2009 18:04:55 +0000

mpeg

Diffstat:
Msrc/include/extractor.h | 2+-
Msrc/main/extractor_metatypes.c | 4++--
Msrc/plugins/Makefile.am | 16++++++++--------
Asrc/plugins/mpeg_extractor.c | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/plugins/mpegextractor.c | 118-------------------------------------------------------------------------------
5 files changed, 127 insertions(+), 129 deletions(-)

diff --git a/src/include/extractor.h b/src/include/extractor.h @@ -271,8 +271,8 @@ enum EXTRACTOR_MetaType EXTRACTOR_METATYPE_CONTRIBUTOR_PICTURE = 139, EXTRACTOR_METATYPE_EVENT_PICTURE = 140, EXTRACTOR_METATYPE_LOGO = 141, + EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM = 142, - EXTRACTOR_METATYPE_PLAY_COUNTER = 118, EXTRACTOR_METATYPE_LYRICS = 67, EXTRACTOR_METATYPE_CONDUCTOR = 64, EXTRACTOR_METATYPE_INTERPRET = 65, diff --git a/src/main/extractor_metatypes.c b/src/main/extractor_metatypes.c @@ -349,8 +349,8 @@ static const struct MetaTypeDescription meta_type_descriptions[] = { gettext_noop ("picture of an associated event") }, { gettext_noop ("logo"), gettext_noop ("logo of an associated organization") }, - { gettext_noop (""), - gettext_noop ("") }, + { gettext_noop ("broadcast television system"), + gettext_noop ("name of the television system for which the data is coded") }, { gettext_noop (""), gettext_noop ("") }, { gettext_noop (""), diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am @@ -82,6 +82,7 @@ plugin_LTLIBRARIES = \ libextractor_man.la \ libextractor_mime.la \ libextractor_mp3.la \ + $(mpeg) \ libextractor_odf.la \ $(ogg) \ $(ole2) \ @@ -191,6 +192,13 @@ libextractor_mp3_la_LIBADD = \ $(top_builddir)/src/common/libextractor_common.la \ $(LE_LIBINTL) +libextractor_mpeg_la_SOURCES = \ + mpeg_extractor.c +libextractor_mpeg_la_LDFLAGS = \ + $(PLUGINFLAGS) +libextractor_mpeg_la_LIBADD = \ + -lmpeg2 + libextractor_odf_la_SOURCES = \ odf_extractor.c libextractor_odf_la_LDFLAGS = \ @@ -338,14 +346,6 @@ libextractor_zip_la_LDFLAGS = \ libextractor_zip_la_LIBADD = \ $(top_builddir)/src/main/libextractor.la -libextractor_mpeg_la_SOURCES = \ - mpegextractor.c -libextractor_mpeg_la_LDFLAGS = \ - $(PLUGINFLAGS) -libextractor_mpeg_la_LIBADD = \ - -lmpeg2 \ - $(top_builddir)/src/main/libextractor.la - libextractor_riff_la_SOURCES = \ riffextractor.c libextractor_riff_la_LDFLAGS = \ diff --git a/src/plugins/mpeg_extractor.c b/src/plugins/mpeg_extractor.c @@ -0,0 +1,116 @@ + +/* + This file is part of libextractor. + (C) 2004, 2005, 2006, 2009 Vidyut Samanta and Christian Grothoff + + libextractor 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, or (at your + option) any later version. + + libextractor 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 libextractor; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include "platform.h" +#include "extractor.h" +#include <mpeg2dec/mpeg2.h> + +#define ADD(s,t) do { if (0 != (ret = proc (proc_cls, "mpeg", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1))) goto EXIT; } while (0) + + +/* video/mpeg */ +int +EXTRACTOR_wav_extract (const unsigned char *data, + size_t size, + EXTRACTOR_MetaDataProcessor proc, + void *proc_cls, + const char *options) +{ + mpeg2dec_t *handle; + uint8_t *start; + uint8_t *end; + const mpeg2_info_t *info; + mpeg2_state_t state; + int ret; + char format[256]; + + if ((size < 4) || + (!((data[0] == 0x00) && + (data[1] == 0x00) && + (data[2] == 0x01) && ((data[3] == 0xB3) || (data[3] == 0xBA))))) + return 0; + + handle = mpeg2_init (); + if (handle == NULL) + return 0; + start = (uint8_t *) data; + end = (uint8_t *) & data[size]; + mpeg2_buffer (handle, start, end); + state = mpeg2_parse (handle); + if (state != STATE_SEQUENCE) + { + mpeg2_close (handle); + return 0; + } + info = mpeg2_info (handle); + if (info == NULL) + { + mpeg2_close (handle); + return 0; + } + ret = 0; + ADD ("video/mpeg", EXTRACTOR_METATYPE_MIMETYPE); + if (info->sequence != NULL) + { + snprintf (format, + sizeof(format), "%ux%u", + info->sequence->width, info->sequence->height); + ADD (format, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS); + switch (info->sequence->flags & SEQ_VIDEO_FORMAT_UNSPECIFIED) + { + case SEQ_VIDEO_FORMAT_PAL: + ADD ("PAL", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM); + break; + case SEQ_VIDEO_FORMAT_NTSC: + ADD ("NTSC", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM); + break; + case SEQ_VIDEO_FORMAT_SECAM: + ADD ("SECAM", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM); + break; + case SEQ_VIDEO_FORMAT_MAC: + ADD ("MAC", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM); + break; + default: + break; + } + if ((info->sequence->flags & SEQ_FLAG_MPEG2) > 0) + ADD ("MPEG2", EXTRACTOR_METATYPE_FORMAT_VERSION); + else + ADD ("MPEG1", EXTRACTOR_METATYPE_FORMAT_VERSION); + } + if (info->gop != NULL) + { + /* this usually does not work yet, since gop's are not + often at the beginning of the stream (and we + don't iterate over the stream hoping to find one). + Hence we usually don't get the size. Not sure how + to *efficiently* get the gop (without scanning + through the entire file) */ + snprintf (format, + sizeof(format), "%u:%u:%u (%u frames)", + info->gop->hours, + info->gop->minutes, info->gop->seconds, info->gop->pictures); + ADD (format, EXTRACTOR_METATYPE_DURATION); + } + EXIT: + mpeg2_close (handle); + return ret; +} diff --git a/src/plugins/mpegextractor.c b/src/plugins/mpegextractor.c @@ -1,118 +0,0 @@ - -/* - This file is part of libextractor. - (C) 2004, 2005, 2006 Vidyut Samanta and Christian Grothoff - - libextractor 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, or (at your - option) any later version. - - libextractor 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 libextractor; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - */ - -#include "platform.h" -#include "extractor.h" -#include <mpeg2dec/mpeg2.h> - -static void -addKeyword (struct EXTRACTOR_Keywords **list, - char *keyword, EXTRACTOR_KeywordType type) -{ - EXTRACTOR_KeywordList *next; - next = malloc (sizeof (EXTRACTOR_KeywordList)); - next->next = *list; - next->keyword = strdup (keyword); - next->keywordType = type; - *list = next; -} - -/* video/mpeg */ -struct EXTRACTOR_Keywords * -libextractor_mpeg_extract (const char *filename, - const unsigned char *data, - size_t size, struct EXTRACTOR_Keywords *prev) -{ - mpeg2dec_t *handle; - uint8_t *start; - uint8_t *end; - const mpeg2_info_t *info; - mpeg2_state_t state; - char format[256]; - - if ((size < 4) || - (!((data[0] == 0x00) && - (data[1] == 0x00) && - (data[2] == 0x01) && ((data[3] == 0xB3) || (data[3] == 0xBA))))) - return prev; - - handle = mpeg2_init (); - if (handle == NULL) - return prev; - start = (uint8_t *) data; - end = (uint8_t *) & data[size]; - mpeg2_buffer (handle, start, end); - state = mpeg2_parse (handle); - if (state != STATE_SEQUENCE) - { - mpeg2_close (handle); - return prev; - } - info = mpeg2_info (handle); - if (info == NULL) - { - mpeg2_close (handle); - return prev; - } - addKeyword (&prev, "video/mpeg", EXTRACTOR_MIMETYPE); - if (info->sequence != NULL) - { - snprintf (format, 256, "%ux%u", - info->sequence->width, info->sequence->height); - addKeyword (&prev, format, EXTRACTOR_SIZE); - switch (info->sequence->flags & SEQ_VIDEO_FORMAT_UNSPECIFIED) - { - case SEQ_VIDEO_FORMAT_PAL: - addKeyword (&prev, "PAL", EXTRACTOR_FORMAT); - break; - case SEQ_VIDEO_FORMAT_NTSC: - addKeyword (&prev, "NTSC", EXTRACTOR_FORMAT); - break; - case SEQ_VIDEO_FORMAT_SECAM: - addKeyword (&prev, "SECAM", EXTRACTOR_FORMAT); - break; - case SEQ_VIDEO_FORMAT_MAC: - addKeyword (&prev, "MAC", EXTRACTOR_FORMAT); - break; - default: - break; - } - if ((info->sequence->flags & SEQ_FLAG_MPEG2) > 0) - addKeyword (&prev, "MPEG2", EXTRACTOR_RESOURCE_TYPE); - else - addKeyword (&prev, "MPEG1", EXTRACTOR_RESOURCE_TYPE); - } - if (info->gop != NULL) - { - /* this usually does not work yet, since gop's are not - often at the beginning of the stream (and we - don't iterate over the stream hoping to find one). - Hence we usually don't get the size. Not sure how - to *efficiently* get the gop (without scanning - through the entire file) */ - snprintf (format, 256, "%u:%u:%u (%u frames)", - info->gop->hours, - info->gop->minutes, info->gop->seconds, info->gop->pictures); - addKeyword (&prev, format, EXTRACTOR_DURATION); - } - mpeg2_close (handle); - return prev; -}