From: lilo_booter Date: Tue, 24 Feb 2004 11:16:51 +0000 (+0000) Subject: watermark added, minor mods to mlt framework required X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=6e4f3aabfeae526318998c1078213de269ea2e65;p=melted watermark added, minor mods to mlt framework required git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@166 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/docs/services.txt b/docs/services.txt index 2a89586..6500f5f 100644 --- a/docs/services.txt +++ b/docs/services.txt @@ -28,13 +28,8 @@ Producers ffmpeg must be configured as --enable-shared and installed prior to compilation of mlt. - Oddities - - MPEG video remains elusive. - Known Bugs - Fixed frame rate. Audio sync discrepancy with some content. Not all libavformat supported formats are seekable. ogg is currently broken. @@ -558,6 +553,72 @@ Filters none + resample + + Description + + Adjust an audio stream's sampling rate + + Constructor Argument + + frequency - a numeric value for the new sample rate + + Initialisation Properties + + int in - in point + int out - out point + + Mutable Properties + + int frequency - the target sample rate + + Dependencies + + libresample + + Known Bugs + + none + + rescale + + Description + + Scale the producer video frame size to match the consumer. + + Constructor Argument + + interpolation - the rescaling method, one of: + nearest (lowest quality, fastest), + tiles, + bilinear (good quality, moderate speed), + hyper (best quality, slowest) + + Initialisation Properties + + int in - in point + int out - out point + + Mutable Properties + + string interpolation - see constructor argument above + + If a property "consumer_aspect_ratio" exists on the frame, then + rescaler normalises the producer's aspect ratio and maximises the + size of the frame, but may not produce the consumer's requested + dimension. Therefore, this option works best in conjunction with the + resize filter. This behavior can be disabled by another service by + either removing the property, setting it to zero, or setting + frame property "distort" to 1. + + Dependencies + + libgdk_pixbuf-2.0, libglib-2.0, libgobject-2.0, libgmodule-2.0 + + Known Bugs + + none + volume Description @@ -614,67 +675,32 @@ Filters none - resample + watermark Description - Adjust an audio stream's sampling rate + Add a watermark to the frames. Constructor Argument - frequency - a numeric value for the new sample rate + resource - the producer to use (ie: a .png) Initialisation Properties + string resource - the producer to use + string factory - producer required for the resource ('fezzik') + string geometry - composite geometry + string distort - control scaling int in - in point int out - out point Mutable Properties - int frequency - the target sample rate - - Dependencies - - libresample - - Known Bugs - none - rescale - - Description - - Scale the producer video frame size to match the consumer. - - Constructor Argument - - interpolation - the rescaling method, one of: - nearest (lowest quality, fastest), - tiles, - bilinear (good quality, moderate speed), - hyper (best quality, slowest) - - Initialisation Properties - - int in - in point - int out - out point - - Mutable Properties - - string interpolation - see constructor argument above - - If a property "consumer_aspect_ratio" exists on the frame, then - rescaler normalises the producer's aspect ratio and maximises the - size of the frame, but may not produce the consumer's requested - dimension. Therefore, this option works best in conjunction with the - resize filter. This behavior can be disabled by another service by - either removing the property, setting it to zero, or setting - frame property "distort" to 1. - Dependencies - libgdk_pixbuf-2.0, libglib-2.0, libgobject-2.0, libgmodule-2.0 + mlt core modules and optionally, fezzik Known Bugs diff --git a/src/framework/mlt_frame.c b/src/framework/mlt_frame.c index 6c367e9..04bc9ba 100644 --- a/src/framework/mlt_frame.c +++ b/src/framework/mlt_frame.c @@ -293,10 +293,13 @@ int mlt_frame_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *for void mlt_frame_close( mlt_frame this ) { - mlt_deque_close( this->stack_get_image ); - mlt_deque_close( this->stack_frame ); - mlt_properties_close( &this->parent ); - free( this ); + if ( this != NULL ) + { + mlt_deque_close( this->stack_get_image ); + mlt_deque_close( this->stack_frame ); + mlt_properties_close( &this->parent ); + free( this ); + } } /***** convenience functions *****/ diff --git a/src/framework/mlt_producer.h b/src/framework/mlt_producer.h index 7e748c0..6d59712 100644 --- a/src/framework/mlt_producer.h +++ b/src/framework/mlt_producer.h @@ -43,9 +43,6 @@ struct mlt_producer_s /** Public final methods */ -//extern double mlt_producer_convert_position_to_time( mlt_producer this, int64_t frame ); -//extern mlt_position mlt_producer_convert_time_to_position( mlt_producer this, double time ); - extern int mlt_producer_init( mlt_producer this, void *child ); extern mlt_service mlt_producer_service( mlt_producer this ); extern mlt_properties mlt_producer_properties( mlt_producer this ); diff --git a/src/framework/mlt_transition.c b/src/framework/mlt_transition.c index 10d2aee..12443d7 100644 --- a/src/framework/mlt_transition.c +++ b/src/framework/mlt_transition.c @@ -50,13 +50,23 @@ int mlt_transition_init( mlt_transition this, void *child ) mlt_properties_set_position( properties, "out", 0 ); mlt_properties_set_int( properties, "a_track", 0 ); mlt_properties_set_int( properties, "b_track", 1 ); - mlt_properties_set( properties, "resource", "" ); return 0; } return 1; } +/** Create a new transition. +*/ + +mlt_transition mlt_transition_new( ) +{ + mlt_transition this = calloc( 1, sizeof( struct mlt_transition_s ) ); + if ( this != NULL ) + mlt_transition_init( this, NULL ); + return this; +} + /** Get the service associated to the transition. */ @@ -136,7 +146,7 @@ mlt_position mlt_transition_get_out( mlt_transition this ) If we have no process method (unlikely), we simply return the a_frame unmolested. */ -static mlt_frame transition_process( mlt_transition this, mlt_frame a_frame, mlt_frame b_frame ) +mlt_frame mlt_transition_process( mlt_transition this, mlt_frame a_frame, mlt_frame b_frame ) { if ( this->process == NULL ) return a_frame; @@ -186,7 +196,7 @@ static int transition_get_frame( mlt_service service, mlt_frame_ptr frame, int i if ( position >= in && position <= out ) { // Process the transition - *frame = transition_process( this, this->a_frame, this->b_frame ); + *frame = mlt_transition_process( this, this->a_frame, this->b_frame ); this->a_held = 0; } else diff --git a/src/framework/mlt_transition.h b/src/framework/mlt_transition.h index 1dad6c1..e4dd154 100644 --- a/src/framework/mlt_transition.h +++ b/src/framework/mlt_transition.h @@ -54,6 +54,7 @@ struct mlt_transition_s */ extern int mlt_transition_init( mlt_transition this, void *child ); +extern mlt_transition mlt_transition_new( ); extern mlt_service mlt_transition_service( mlt_transition this ); extern mlt_properties mlt_transition_properties( mlt_transition this ); extern int mlt_transition_connect( mlt_transition this, mlt_service producer, int a_track, int b_track ); @@ -62,6 +63,7 @@ extern int mlt_transition_get_a_track( mlt_transition this ); extern int mlt_transition_get_b_track( mlt_transition this ); extern mlt_position mlt_transition_get_in( mlt_transition this ); extern mlt_position mlt_transition_get_out( mlt_transition this ); +extern mlt_frame mlt_transition_process( mlt_transition this, mlt_frame a_frame, mlt_frame b_frame ); extern void mlt_transition_close( mlt_transition this ); #endif diff --git a/src/modules/core/Makefile b/src/modules/core/Makefile index d1d05d7..41f7b34 100644 --- a/src/modules/core/Makefile +++ b/src/modules/core/Makefile @@ -3,16 +3,17 @@ TARGET = ../libmltcore.so OBJS = factory.o \ producer_ppm.o \ + filter_brightness.o \ filter_deinterlace.o \ filter_greyscale.o \ filter_gamma.o \ filter_obscure.o \ filter_resize.o \ filter_volume.o \ + filter_watermark.o \ transition_composite.o \ transition_luma.o \ - transition_mix.o \ - filter_brightness.o + transition_mix.o CFLAGS = -O3 -I../../ -Wall -g -D_FILE_OFFSET_BITS=64 -pthread diff --git a/src/modules/core/configure b/src/modules/core/configure index e6ef263..dec3e77 100755 --- a/src/modules/core/configure +++ b/src/modules/core/configure @@ -8,13 +8,14 @@ ppm libmltcore.so EOF cat << EOF >> ../filters.dat +brightness libmltcore.so deinterlace libmltcore.so gamma libmltcore.so greyscale libmltcore.so +obscure libmltcore.so resize libmltcore.so volume libmltcore.so -obscure libmltcore.so -brightness libmltcore.so +watermark libmltcore.so EOF cat << EOF >> ../transitions.dat diff --git a/src/modules/core/factory.c b/src/modules/core/factory.c index 5096656..650cca8 100644 --- a/src/modules/core/factory.c +++ b/src/modules/core/factory.c @@ -21,16 +21,17 @@ #include #include "producer_ppm.h" +#include "filter_brightness.h" #include "filter_deinterlace.h" #include "filter_gamma.h" #include "filter_greyscale.h" #include "filter_obscure.h" #include "filter_resize.h" #include "filter_volume.h" +#include "filter_watermark.h" #include "transition_composite.h" #include "transition_luma.h" #include "transition_mix.h" -#include "filter_brightness.h" void *mlt_create_producer( char *id, void *arg ) { @@ -41,6 +42,8 @@ void *mlt_create_producer( char *id, void *arg ) void *mlt_create_filter( char *id, void *arg ) { + if ( !strcmp( id, "brightness" ) ) + return filter_brightness_init( arg ); if ( !strcmp( id, "deinterlace" ) ) return filter_deinterlace_init( arg ); if ( !strcmp( id, "gamma" ) ) @@ -53,8 +56,8 @@ void *mlt_create_filter( char *id, void *arg ) return filter_resize_init( arg ); if ( !strcmp( id, "volume" ) ) return filter_volume_init( arg ); - if ( !strcmp( id, "brightness" ) ) - return filter_brightness_init( arg ); + if ( !strcmp( id, "watermark" ) ) + return filter_watermark_init( arg ); return NULL; } diff --git a/src/modules/core/filter_obscure.c b/src/modules/core/filter_obscure.c index b3c1622..ed06492 100644 --- a/src/modules/core/filter_obscure.c +++ b/src/modules/core/filter_obscure.c @@ -230,7 +230,10 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format mlt_filter this = mlt_deque_pop_back( deque ); // Get the image from the frame - if ( mlt_frame_get_image( frame, image, format, width, height, 1 ) == 0 ) + int error = mlt_frame_get_image( frame, image, format, width, height, 1 ); + + // Get the image from the frame + if ( error == 0 && *format == mlt_image_yuv422 ) { if ( this != NULL ) { @@ -261,7 +264,7 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format } } - return 0; + return error; } /** Filter processing. diff --git a/src/modules/core/filter_resize.c b/src/modules/core/filter_resize.c index 60a2887..a511eb2 100644 --- a/src/modules/core/filter_resize.c +++ b/src/modules/core/filter_resize.c @@ -26,14 +26,6 @@ #include #include -static int get_value( mlt_properties properties, char *preferred, char *fallback ) -{ - int value = mlt_properties_get_int( properties, preferred ); - if ( value == 0 ) - value = mlt_properties_get_int( properties, fallback ); - return value; -} - /** Do it :-). */ @@ -148,10 +140,7 @@ mlt_filter filter_resize_init( char *arg ) if ( mlt_filter_init( this, this ) == 0 ) { this->process = filter_process; - if ( arg != NULL ) - mlt_properties_set( mlt_filter_properties( this ), "scale", arg ); - else - mlt_properties_set( mlt_filter_properties( this ), "scale", "off" ); + mlt_properties_set( mlt_filter_properties( this ), "scale", arg == NULL ? "off" : arg ); } return this; } diff --git a/src/modules/core/filter_watermark.c b/src/modules/core/filter_watermark.c new file mode 100644 index 0000000..a7d0b0b --- /dev/null +++ b/src/modules/core/filter_watermark.c @@ -0,0 +1,117 @@ +/* + * filter_watermark.c -- watermark filter + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "filter_watermark.h" + +#include +#include +#include +#include + +#include +#include + +/** Do it :-). +*/ + +static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ) +{ + int error = 0; + mlt_properties frame_properties = mlt_frame_properties( this ); + mlt_filter filter = mlt_properties_get_data( frame_properties, "watermark", NULL ); + mlt_properties properties = mlt_filter_properties( filter ); + mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL ); + mlt_transition composite = mlt_properties_get_data( properties, "composite", NULL ); + + if ( composite == NULL ) + { + char *geometry = mlt_properties_get( properties, "geometry" ); + composite = mlt_factory_transition( "composite", geometry == NULL ? "85%,5%:10%x10%" : geometry ); + if ( composite != NULL ) + { + mlt_properties composite_properties = mlt_transition_properties( composite ); + char *distort = mlt_properties_get( properties, "distort" ); + if ( distort != NULL ) + mlt_properties_set( composite_properties, "distort", distort ); + mlt_properties_set_data( properties, "composite", composite, 0, ( mlt_destructor )mlt_transition_close, NULL ); + } + } + + if ( producer == NULL ) + { + char *resource = mlt_properties_get( properties, "resource" ); + char *factory = mlt_properties_get( properties, "factory" ); + producer = mlt_factory_producer( factory, resource ); + if ( producer != NULL ) + { + mlt_properties producer_properties = mlt_producer_properties( producer ); + mlt_properties_set( producer_properties, "eof", "loop" ); + mlt_properties_set_data( properties, "producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL ); + } + } + + if ( composite != NULL && producer != NULL ) + { + mlt_service service = mlt_producer_service( producer ); + mlt_frame b_frame = NULL; + + if ( mlt_service_get_frame( service, &b_frame, 0 ) == 0 ) + mlt_transition_process( composite, this, b_frame ); + + error = mlt_frame_get_image( this, image, format, width, height, 1 ); + + mlt_frame_close( b_frame ); + } + else + { + error = mlt_frame_get_image( this, image, format, width, height, 1 ); + } + + return error; +} + +/** Filter processing. +*/ + +static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) +{ + mlt_properties properties = mlt_frame_properties( frame ); + mlt_properties_set_data( properties, "watermark", this, 0, NULL, NULL ); + mlt_frame_push_get_image( frame, filter_get_image ); + return frame; +} + +/** Constructor for the filter. +*/ + +mlt_filter filter_watermark_init( void *arg ) +{ + mlt_filter this = mlt_filter_new( ); + if ( this != NULL ) + { + mlt_properties properties = mlt_filter_properties( this ); + this->process = filter_process; + mlt_properties_set( properties, "factory", "fezzik" ); + if ( arg != NULL ) + mlt_properties_set( properties, "resource", arg ); + } + return this; +} + diff --git a/src/modules/core/filter_watermark.h b/src/modules/core/filter_watermark.h new file mode 100644 index 0000000..bf844b0 --- /dev/null +++ b/src/modules/core/filter_watermark.h @@ -0,0 +1,28 @@ +/* + * filter_watermark.h -- watermark filter + * Copyright (C) 2003-2004 Ushodaya Enterprises Limited + * Author: Charles Yates + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef _FILTER_WATERMARK_H_ +#define _FILTER_WATERMARK_H_ + +#include + +extern mlt_filter filter_watermark_init( void *arg ); + +#endif diff --git a/src/modules/ffmpeg/filter_ffmpeg_dub.c b/src/modules/ffmpeg/filter_ffmpeg_dub.c index 0d678af..c46dcd8 100644 --- a/src/modules/ffmpeg/filter_ffmpeg_dub.c +++ b/src/modules/ffmpeg/filter_ffmpeg_dub.c @@ -117,25 +117,27 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) mlt_filter filter_ffmpeg_dub_init( char *file ) { // Create the filter object - mlt_filter this = calloc( sizeof( struct mlt_filter_s ), 1 ); + mlt_filter this = mlt_filter_new( ); // Initialise it - mlt_filter_init( this, NULL ); - - // Overide the filter process method - this->process = filter_process; + if ( this != NULL ) + { + // Obtain the properties + mlt_properties properties = mlt_filter_properties( this ); - // Obtain the properties - mlt_properties properties = mlt_filter_properties( this ); + // Create an ffmpeg producer + // TODO: THIS SHOULD NOT BE HERE.... + mlt_producer producer = mlt_factory_producer( "ffmpeg", file ); - // Create an ffmpeg producer - mlt_producer producer = mlt_factory_producer( "ffmpeg", file ); + // Overide the filter process method + this->process = filter_process; - // Pass the producer - mlt_properties_set_data( properties, "producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL ); + // Pass the producer + mlt_properties_set_data( properties, "producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL ); - // Initialise the audio frame position - mlt_properties_set_position( properties, "dub_position", 0 ); + // Initialise the audio frame position + mlt_properties_set_position( properties, "dub_position", 0 ); + } return this; } diff --git a/src/modules/gtk2/filter_rescale.c b/src/modules/gtk2/filter_rescale.c index f70c039..f4c69ac 100644 --- a/src/modules/gtk2/filter_rescale.c +++ b/src/modules/gtk2/filter_rescale.c @@ -205,14 +205,11 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) mlt_filter filter_rescale_init( char *arg ) { - mlt_filter this = calloc( sizeof( struct mlt_filter_s ), 1 ); - if ( mlt_filter_init( this, this ) == 0 ) + mlt_filter this = mlt_filter_new( ); + if ( this != NULL ) { this->process = filter_process; - if ( arg != NULL ) - mlt_properties_set( mlt_filter_properties( this ), "interpolation", arg ); - else - mlt_properties_set( mlt_filter_properties( this ), "interpolation", "bilinear" ); + mlt_properties_set( mlt_filter_properties( this ), "interpolation", arg == NULL ? "bilinear" : arg ); } return this; } diff --git a/src/modules/resample/filter_resample.c b/src/modules/resample/filter_resample.c index f40384c..b8da760 100644 --- a/src/modules/resample/filter_resample.c +++ b/src/modules/resample/filter_resample.c @@ -134,8 +134,8 @@ static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) mlt_filter filter_resample_init( char *arg ) { - mlt_filter this = calloc( sizeof( struct mlt_filter_s ), 1 ); - if ( this != NULL && mlt_filter_init( this, NULL ) == 0 ) + mlt_filter this = mlt_filter_new( ); + if ( this != NULL ) { int error; SRC_STATE *state = src_new( RESAMPLE_TYPE, 2 /* channels */, &error );