libextractor  1.11
About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.
  Fossies Dox: libextractor-1.11.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

thumbnailffmpeg_extractor.c File Reference

this extractor produces a binary encoded thumbnail of images and videos using the ffmpeg libs. More...

#include "platform.h"
#include "extractor.h"
#include <magic.h>
#include <libavutil/avutil.h>
#include <libavutil/imgutils.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
Include dependency graph for thumbnailffmpeg_extractor.c:

Go to the source code of this file.

Data Structures

struct  MIMEToDecoderMapping
 

Macros

#define PIX_OUTPUT_FORMAT   AV_PIX_FMT_RGB24
 
#define USE_JPEG   1
 
#define OUTPUT_FILE   0
 
#define DEBUG   0
 
#define MAX_THUMB_DIMENSION   128
 
#define MAX_THUMB_BYTES   (100 * 1024)
 
#define BUFFER_SIZE   (32 * 1024)
 
#define PADDED_BUFFER_SIZE   (BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE)
 
#define AV_CODEC_FLAG_QSCALE   CODEC_FLAG_QSCALE
 
#define ENUM_CODEC_ID   enum AVCodecID
 

Functions

static int read_cb (void *opaque, uint8_t *buf, int buf_size)
 
static int64_t seek_cb (void *opaque, int64_t offset, int whence)
 
static size_t create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height, int src_stride[], enum AVPixelFormat src_pixfmt, const uint8_t *const src_data[], int dst_width, int dst_height, uint8_t **output_data, size_t output_max_size)
 
static void calculate_thumbnail_dimensions (int src_width, int src_height, int src_sar_num, int src_sar_den, int *dst_width, int *dst_height)
 
static void extract_image (enum AVCodecID image_codec_id, struct EXTRACTOR_ExtractContext *ec)
 
static void extract_video (struct EXTRACTOR_ExtractContext *ec)
 
void EXTRACTOR_thumbnailffmpeg_extract_method (struct EXTRACTOR_ExtractContext *ec)
 
void EXTRACTOR_thumbnail_extract_method (struct EXTRACTOR_ExtractContext *ec)
 
static void thumbnailffmpeg_av_log_callback (void *ptr, int level, const char *format, va_list ap)
 
void thumbnailffmpeg_lib_init (void)
 
void thumbnailffmpeg_ltdl_fini ()
 

Variables

static magic_t magic
 
static const struct MIMEToDecoderMapping m2d_map []
 

Detailed Description

this extractor produces a binary encoded thumbnail of images and videos using the ffmpeg libs.

Author
Heikki Lindholm
Christian Grothoff

This is a thumbnail extractor using the ffmpeg libraries that will eventually support extracting thumbnails from both image and video files.

Note that ffmpeg has a few issues: (1) there are no recent official releases of the ffmpeg libs (2) ffmpeg has a history of having security issues (parser is not robust)

So this plugin cannot be recommended for system with high security requirements.

Definition in file thumbnailffmpeg_extractor.c.

Macro Definition Documentation

◆ AV_CODEC_FLAG_QSCALE

#define AV_CODEC_FLAG_QSCALE   CODEC_FLAG_QSCALE

Definition at line 103 of file thumbnailffmpeg_extractor.c.

◆ BUFFER_SIZE

#define BUFFER_SIZE   (32 * 1024)

Number of bytes to feed to libav in one go.

Definition at line 90 of file thumbnailffmpeg_extractor.c.

◆ DEBUG

#define DEBUG   0

Set to 1 to use jpeg.

Definition at line 75 of file thumbnailffmpeg_extractor.c.

◆ ENUM_CODEC_ID

#define ENUM_CODEC_ID   enum AVCodecID

Definition at line 406 of file thumbnailffmpeg_extractor.c.

◆ MAX_THUMB_BYTES

#define MAX_THUMB_BYTES   (100 * 1024)

Maximum size in bytes for the thumbnail.

Definition at line 85 of file thumbnailffmpeg_extractor.c.

◆ MAX_THUMB_DIMENSION

#define MAX_THUMB_DIMENSION   128

max dimension in pixels for the thumbnail.

Definition at line 80 of file thumbnailffmpeg_extractor.c.

◆ OUTPUT_FILE

#define OUTPUT_FILE   0

Set to 1 to enable a output file for testing.

Definition at line 69 of file thumbnailffmpeg_extractor.c.

◆ PADDED_BUFFER_SIZE

#define PADDED_BUFFER_SIZE   (BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE)

Number of bytes to feed to libav in one go, with padding (padding is zeroed).

Definition at line 99 of file thumbnailffmpeg_extractor.c.

◆ PIX_OUTPUT_FORMAT

#define PIX_OUTPUT_FORMAT   AV_PIX_FMT_RGB24

Definition at line 57 of file thumbnailffmpeg_extractor.c.

◆ USE_JPEG

#define USE_JPEG   1

Set to 1 to use JPEG, PNG otherwise

Definition at line 64 of file thumbnailffmpeg_extractor.c.

Function Documentation

◆ calculate_thumbnail_dimensions()

static void calculate_thumbnail_dimensions ( int  src_width,
int  src_height,
int  src_sar_num,
int  src_sar_den,
int *  dst_width,
int *  dst_height 
)
static

calculate the thumbnail dimensions, taking pixel aspect into account

Parameters
src_widthsource image width
src_heightsource image height
src_sar_num
src_sar_den
dst_widthdesired thumbnail width (set)
dst_heightdesired thumbnail height (set)

Definition at line 369 of file thumbnailffmpeg_extractor.c.

References MAX_THUMB_DIMENSION.

Referenced by extract_image(), and extract_video().

◆ create_thumbnail()

static size_t create_thumbnail ( AVCodecContext *  pCodecCtx,
int  src_width,
int  src_height,
int  src_stride[],
enum AVPixelFormat  src_pixfmt,
const uint8_t *const  src_data[],
int  dst_width,
int  dst_height,
uint8_t **  output_data,
size_t  output_max_size 
)
static

Rescale and encode a PNG thumbnail.

Parameters
src_widthsource image width
src_heightsource image height
src_stride
src_pixfmt
src_datasource data
dst_widthdesired thumbnail width
dst_heightdesired thumbnail height
output_datawhere to store the resulting PNG data
output_max_sizemaximum size of result that is allowed
Returns
the number of bytes used, 0 on error

Definition at line 174 of file thumbnailffmpeg_extractor.c.

References AV_CODEC_FLAG_QSCALE, NULL, and PIX_OUTPUT_FORMAT.

Referenced by extract_image(), and extract_video().

◆ extract_image()

static void extract_image ( enum AVCodecID  image_codec_id,
struct EXTRACTOR_ExtractContext ec 
)
static

Perform thumbnailing when the input is an image.

Parameters
image_codec_idffmpeg codec for the image format
ecextraction context to use

Definition at line 415 of file thumbnailffmpeg_extractor.c.

References BUFFER_SIZE, calculate_thumbnail_dimensions(), EXTRACTOR_ExtractContext::cls, create_thumbnail(), EXTRACTOR_METAFORMAT_BINARY, EXTRACTOR_METATYPE_THUMBNAIL, MAX_THUMB_BYTES, NULL, PADDED_BUFFER_SIZE, EXTRACTOR_ExtractContext::proc, and EXTRACTOR_ExtractContext::read.

Referenced by EXTRACTOR_thumbnailffmpeg_extract_method().

◆ extract_video()

static void extract_video ( struct EXTRACTOR_ExtractContext ec)
static

◆ EXTRACTOR_thumbnail_extract_method()

void EXTRACTOR_thumbnail_extract_method ( struct EXTRACTOR_ExtractContext ec)

This plugin sometimes is installed under the alias 'thumbnail'. So we need to provide a second entry method.

Parameters
ecextraction context

Definition at line 835 of file thumbnailffmpeg_extractor.c.

References EXTRACTOR_thumbnailffmpeg_extract_method().

◆ EXTRACTOR_thumbnailffmpeg_extract_method()

void EXTRACTOR_thumbnailffmpeg_extract_method ( struct EXTRACTOR_ExtractContext ec)

◆ read_cb()

static int read_cb ( void *  opaque,
uint8_t *  buf,
int  buf_size 
)
static

Read callback.

Parameters
opaquethe 'struct EXTRACTOR_ExtractContext'
bufwhere to write data
buf_sizehow many bytes to read
Returns
-1 on error (or for unknown file size)

Definition at line 122 of file thumbnailffmpeg_extractor.c.

References EXTRACTOR_ExtractContext::cls, and EXTRACTOR_ExtractContext::read.

Referenced by extract_video().

◆ seek_cb()

static int64_t seek_cb ( void *  opaque,
int64_t  offset,
int  whence 
)
static

Seek callback.

Parameters
opaquethe 'struct EXTRACTOR_ExtractContext'
offsetwhere to seek
whencehow to seek; AVSEEK_SIZE to return file size without seeking
Returns
-1 on error (or for unknown file size)

Definition at line 147 of file thumbnailffmpeg_extractor.c.

References EXTRACTOR_ExtractContext::cls, EXTRACTOR_ExtractContext::get_size, and EXTRACTOR_ExtractContext::seek.

Referenced by extract_video().

◆ thumbnailffmpeg_av_log_callback()

static void thumbnailffmpeg_av_log_callback ( void *  ptr,
int  level,
const char *  format,
va_list  ap 
)
static

Log callback. Does nothing.

Parameters
ptrNULL
levellog level
formatformat string
aparguments for format

Definition at line 850 of file thumbnailffmpeg_extractor.c.

Referenced by thumbnailffmpeg_lib_init().

◆ thumbnailffmpeg_lib_init()

void thumbnailffmpeg_lib_init ( void  )

Initialize av-libs and load magic file.

Definition at line 865 of file thumbnailffmpeg_extractor.c.

References magic, NULL, and thumbnailffmpeg_av_log_callback().

◆ thumbnailffmpeg_ltdl_fini()

void thumbnailffmpeg_ltdl_fini ( )

Destructor for the library, cleans up.

Definition at line 880 of file thumbnailffmpeg_extractor.c.

References magic, and NULL.

Variable Documentation

◆ m2d_map

const struct MIMEToDecoderMapping m2d_map[]
static
Initial value:
= {
{ "image/x-bmp", AV_CODEC_ID_BMP },
{ "image/gif", AV_CODEC_ID_GIF },
{ "image/jpeg", AV_CODEC_ID_MJPEG },
{ "image/png", AV_CODEC_ID_PNG },
{ "image/x-png", AV_CODEC_ID_PNG },
{ "image/x-portable-pixmap", AV_CODEC_ID_PPM },
{ NULL, AV_CODEC_ID_NONE }
}
#define NULL
Definition: getopt1.c:60

map MIME image types to an ffmpeg decoder

Definition at line 549 of file thumbnailffmpeg_extractor.c.

Referenced by EXTRACTOR_thumbnailffmpeg_extract_method().

◆ magic

magic_t magic
static

Global handle to MAGIC data.

Definition at line 110 of file thumbnailffmpeg_extractor.c.

Referenced by EXTRACTOR_thumbnailffmpeg_extract_method(), thumbnailffmpeg_lib_init(), and thumbnailffmpeg_ltdl_fini().