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 frame
->get_audio
= mlt_properties_get_data( frame_properties
, "get_audio", NULL
);
43 // Call the original get_audio
44 mlt_frame_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 mlt_position position
= mlt_properties_get_position( producer_properties
, "dub_position" );
52 // We need a frame from the producer
53 mlt_frame producer_frame
;
56 mlt_properties_set_double( producer_properties
, "fps", mlt_properties_get_double( frame_properties
, "fps" ) );
58 // Seek to the position
59 mlt_producer_seek( producer
, position
);
62 producer
->get_frame( producer
, &producer_frame
, 0 );
64 if ( !mlt_properties_get_int( producer_properties
, "end_of_clip" ) )
66 // Now get the audio from this frame
67 producer_frame
->get_audio( producer_frame
, buffer
, format
, frequency
, channels
, samples
);
69 // This producer frame will be destroyed automatically when frame is destroyed
70 mlt_properties_set_data( frame_properties
, "ffmpeg_dub_frame", producer_frame
, 0, ( mlt_destructor
)mlt_frame_close
, NULL
);
72 // Incrment the position
73 mlt_properties_set_position( producer_properties
, "dub_position", position
+ 1 );
80 /** Filter processing.
83 static mlt_frame
filter_process( mlt_filter
this, mlt_frame frame
)
85 // Obtain the filter properties
86 mlt_properties filter_properties
= mlt_filter_properties( this );
88 // Get the producer used.
89 mlt_producer producer
= mlt_properties_get_data( filter_properties
, "producer", NULL
);
91 // Obtain the frame properties
92 mlt_properties frame_properties
= mlt_frame_properties( frame
);
94 // Get the producer properties
95 mlt_properties producer_properties
= mlt_producer_properties( producer
);
97 // Only do this if we have not reached end of clip and ffmpeg_dub has not already been done
98 if ( !mlt_properties_get_int( producer_properties
, "end_of_clip" ) &&
99 mlt_properties_get_data( frame_properties
, "get_audio", NULL
) == NULL
)
101 // Backup the original get_audio (it's still needed)
102 mlt_properties_set_data( frame_properties
, "get_audio", frame
->get_audio
, 0, NULL
, NULL
);
104 // Pass the producer on the frame
105 mlt_properties_set_data( frame_properties
, "producer", producer
, 0, NULL
, NULL
);
107 // Override the get_audio method
108 frame
->get_audio
= filter_get_audio
;
114 /** Constructor for the filter.
117 mlt_filter
filter_ffmpeg_dub_init( char *file
)
119 // Create the filter object
120 mlt_filter
this = calloc( sizeof( struct mlt_filter_s
), 1 );
123 mlt_filter_init( this, NULL
);
125 // Overide the filter process method
126 this->process
= filter_process
;
128 // Obtain the properties
129 mlt_properties properties
= mlt_filter_properties( this );
131 // Create an ffmpeg producer
132 mlt_producer producer
= mlt_factory_producer( "ffmpeg", file
);
135 mlt_properties_set_data( properties
, "producer", producer
, 0, ( mlt_destructor
)mlt_producer_close
, NULL
);
137 // Initialise the audio frame position
138 mlt_properties_set_position( properties
, "dub_position", 0 );