2 * filter_ffmpeg_dub.c -- simple ffmpeg dub test case
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "filter_ffmpeg_dub.h"
24 #include <framework/mlt.h>
29 static int filter_get_audio( mlt_frame frame
, int16_t **buffer
, mlt_audio_format
*format
, int *frequency
, int *channels
, int *samples
)
31 // Obtain the frame properties
32 mlt_properties frame_properties
= mlt_frame_properties( frame
);
34 // Get the producer used.
35 mlt_producer producer
= mlt_properties_get_data( frame_properties
, "producer", NULL
);
37 // Get the producer properties
38 mlt_properties producer_properties
= mlt_producer_properties( producer
);
40 // Get the original get_audio
41 int ( *get_audio
)( mlt_frame
, int16_t **, mlt_audio_format
*, int *, int *, int * ) = mlt_properties_get_data( frame_properties
, "get_audio", NULL
);
43 // Call the original get_audio
44 get_audio( frame
, buffer
, format
, frequency
, channels
, samples
);
46 // Now if our producer is still producing, override the audio
47 if ( !mlt_properties_get_int( producer_properties
, "end_of_clip" ) )
50 double position
= mlt_properties_get_double( producer_properties
, "dub_position" );
52 // We need a frame from the producer
53 mlt_frame producer_frame
;
55 // Seek to the position
56 mlt_producer_seek_frame( producer
, ( int64_t )position
);
59 producer
->get_frame( producer
, &producer_frame
, 0 );
61 if ( !mlt_properties_get_int( producer_properties
, "end_of_clip" ) )
63 // Now get the audio from this frame
64 producer_frame
->get_audio( producer_frame
, buffer
, format
, frequency
, channels
, samples
);
66 // This producer frame will be destroyed automatically when frame is destroyed
67 mlt_properties_set_data( frame_properties
, "ffmpeg_dub_frame", producer_frame
, 0, ( mlt_destructor
)mlt_frame_close
, NULL
);
69 // Incrment the position
70 mlt_properties_set_double( producer_properties
, "dub_position", position
+ 1 );
77 /** Filter processing.
80 static mlt_frame
filter_process( mlt_filter
this, mlt_frame frame
)
82 // Obtain the filter properties
83 mlt_properties filter_properties
= mlt_filter_properties( this );
85 // Get the producer used.
86 mlt_producer producer
= mlt_properties_get_data( filter_properties
, "producer", NULL
);
88 // Obtain the frame properties
89 mlt_properties frame_properties
= mlt_frame_properties( frame
);
91 // Backup the original get_audio (it's still needed)
92 mlt_properties_set_data( frame_properties
, "get_audio", frame
->get_audio
, 0, NULL
, NULL
);
94 // Pass the producer on the frame
95 mlt_properties_set_data( frame_properties
, "producer", producer
, 0, NULL
, NULL
);
97 // Override the get_audio method
98 frame
->get_audio
= filter_get_audio
;
103 /** Constructor for the filter.
106 mlt_filter
filter_ffmpeg_dub_init( char *file
)
108 // Create the filter object
109 mlt_filter
this = calloc( sizeof( struct mlt_filter_s
), 1 );
112 mlt_filter_init( this, NULL
);
114 // Overide the filter process method
115 this->process
= filter_process
;
117 // Obtain the properties
118 mlt_properties properties
= mlt_filter_properties( this );
120 // Create an ffmpeg producer
121 mlt_producer producer
= mlt_factory_producer( "ffmpeg", file
);
124 mlt_properties_set_data( properties
, "producer", producer
, 0, ( mlt_destructor
)mlt_producer_close
, NULL
);
126 // Initialise the audio frame position
127 mlt_properties_set_double( properties
, "dub_position", 0 );