]> git.sesse.net Git - mlt/blob - src/inigo/inigo.c
Added avformat
[mlt] / src / inigo / inigo.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include <framework/mlt.h>
6
7 #include "io.h"
8
9 static void transport_action( mlt_producer producer, char *value )
10 {
11         mlt_properties properties = mlt_producer_properties( producer );
12         mlt_multitrack multitrack = mlt_properties_get_data( properties, "multitrack", NULL );
13
14         if ( strlen( value ) == 1 )
15         {
16                 switch( value[ 0 ] )
17                 {
18                         case 'q':
19                                 mlt_properties_set_int( properties, "done", 1 );
20                                 break;
21                         case '0':
22                                 mlt_producer_set_speed( producer, 1 );
23                                 mlt_producer_seek( producer, 0 );
24                                 break;
25                         case '1':
26                                 mlt_producer_set_speed( producer, -10 );
27                                 break;
28                         case '2':
29                                 mlt_producer_set_speed( producer, -5 );
30                                 break;
31                         case '3':
32                                 mlt_producer_set_speed( producer, -2 );
33                                 break;
34                         case '4':
35                                 mlt_producer_set_speed( producer, -1 );
36                                 break;
37                         case '5':
38                                 mlt_producer_set_speed( producer, 0 );
39                                 break;
40                         case '6':
41                         case ' ':
42                                 mlt_producer_set_speed( producer, 1 );
43                                 break;
44                         case '7':
45                                 mlt_producer_set_speed( producer, 2 );
46                                 break;
47                         case '8':
48                                 mlt_producer_set_speed( producer, 5 );
49                                 break;
50                         case '9':
51                                 mlt_producer_set_speed( producer, 10 );
52                                 break;
53                         case 'd':
54                                 if ( multitrack != NULL )
55                                 {
56                                         int i = 0;
57                                         mlt_position last = -1;
58                                         for ( i = 0; 1; i ++ )
59                                         {
60                                                 mlt_position time = mlt_multitrack_clip( multitrack, mlt_whence_relative_start, i );
61                                                 if ( time == last )
62                                                         break;
63                                                 last = time;
64                                                 fprintf( stderr, "%d: %lld\n", i, time );
65                                         }
66                                         fprintf( stderr, "Current Position: %lld\n", mlt_producer_position( producer ) );
67                                 }
68                                 break;
69
70                         case 'g':
71                                 if ( multitrack != NULL )
72                                 {
73                                         mlt_position time = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, 0 );
74                                         mlt_producer_seek( producer, time );
75                                 }
76                                 break;
77                         case 'H':
78                                 if ( producer != NULL )
79                                 {
80                                         mlt_position position = mlt_producer_position( producer );
81                                         mlt_producer_seek( producer, position - ( mlt_producer_get_fps( producer ) * 60 ) );
82                                 }
83                                 break;
84                         case 'h':
85                                 if ( producer != NULL )
86                                 {
87                                         mlt_position position = mlt_producer_position( producer );
88                                         mlt_producer_set_speed( producer, 0 );
89                                         mlt_producer_seek( producer, position - 1 );
90                                 }
91                                 break;
92                         case 'j':
93                                 if ( multitrack != NULL )
94                                 {
95                                         mlt_position time = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, 1 );
96                                         mlt_producer_seek( producer, time );
97                                 }
98                                 break;
99                         case 'k':
100                                 if ( multitrack != NULL )
101                                 {
102                                         mlt_position time = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, -1 );
103                                         mlt_producer_seek( producer, time );
104                                 }
105                                 break;
106                         case 'l':
107                                 if ( producer != NULL )
108                                 {
109                                         mlt_position position = mlt_producer_position( producer );
110                                         mlt_producer_set_speed( producer, 0 );
111                                         mlt_producer_seek( producer, position + 1 );
112                                 }
113                                 break;
114                         case 'L':
115                                 if ( producer != NULL )
116                                 {
117                                         mlt_position position = mlt_producer_position( producer );
118                                         mlt_producer_seek( producer, position + ( mlt_producer_get_fps( producer ) * 60 ) );
119                                 }
120                                 break;
121                 }
122         }
123 }
124
125 static mlt_consumer create_consumer( char *id, mlt_producer producer )
126 {
127         char *arg = strchr( id, ':' );
128         if ( arg != NULL )
129                 *arg ++ = '\0';
130         mlt_consumer consumer = mlt_factory_consumer( id, arg );
131         if ( consumer != NULL )
132         {
133                 mlt_properties properties = mlt_consumer_properties( consumer );
134                 mlt_properties_set_data( properties, "transport_callback", transport_action, 0, NULL, NULL );
135                 mlt_properties_set_data( properties, "transport_producer", producer, 0, NULL, NULL );
136         }
137         return consumer;
138 }
139
140 static void transport( mlt_producer producer, mlt_consumer consumer )
141 {
142         mlt_properties properties = mlt_producer_properties( producer );
143
144         term_init( );
145
146         if ( mlt_properties_get_int( properties, "done" ) == 0 && !mlt_consumer_is_stopped( consumer ) )
147         {
148                 fprintf( stderr, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
149                 fprintf( stderr, "|1=-10| |2= -5| |3= -2| |4= -1| |5=  0| |6=  1| |7=  2| |8=  5| |9= 10|\n" );
150                 fprintf( stderr, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
151
152                 fprintf( stderr, "+---------------------------------------------------------------------+\n" );
153                 fprintf( stderr, "|               H = back 1 minute,  L = forward 1 minute              |\n" );
154                 fprintf( stderr, "|                 h = previous frame,  l = next frame                 |\n" );
155                 fprintf( stderr, "|           g = start of clip, j = next clip, k = previous clip       |\n" );
156                 fprintf( stderr, "|                0 = restart, q = quit, space = play                  |\n" );
157                 fprintf( stderr, "+---------------------------------------------------------------------+\n" );
158         }
159
160         while( mlt_properties_get_int( properties, "done" ) == 0 && !mlt_consumer_is_stopped( consumer ) )
161         {
162                 int value = term_read( );
163                 if ( value != -1 )
164                         transport_action( producer, ( char * )&value );
165         }
166 }
167
168 int main( int argc, char **argv )
169 {
170         int i;
171         mlt_consumer consumer = NULL;
172         mlt_producer inigo = NULL;
173         FILE *store = NULL;
174         char *name = NULL;
175
176         // Construct the factory
177         mlt_factory_init( getenv( "MLT_REPOSITORY" ) );
178
179         // Check for serialisation switch first
180         for ( i = 1; i < argc; i ++ )
181         {
182                 if ( !strcmp( argv[ i ], "-serialise" ) )
183                 {
184                         name = argv[ ++ i ];
185                         if ( strstr( name, ".inigo" ) )
186                                 store = fopen( name, "w" );
187                 }
188         }
189
190         // Get inigo producer
191         if ( argc > 1 )
192                 inigo = mlt_factory_producer( "inigo", &argv[ 1 ] );
193
194         if ( argc > 1 && inigo != NULL && mlt_producer_get_length( inigo ) > 0 )
195         {
196                 // Get inigo's properties
197                 mlt_properties inigo_props = mlt_producer_properties( inigo );
198
199                 // Get the field service from inigo
200                 mlt_field field = mlt_properties_get_data( inigo_props, "field", 0 );
201
202                 // Get the last group
203                 mlt_properties group = mlt_properties_get_data( inigo_props, "group", 0 );
204
205                 // Parse the arguments
206                 for ( i = 1; i < argc; i ++ )
207                 {
208                         if ( !strcmp( argv[ i ], "-consumer" ) )
209                         {
210                                 consumer = create_consumer( argv[ ++ i ], inigo );
211                                 while ( argv[ i + 1 ] != NULL && strstr( argv[ i + 1 ], "=" ) )
212                                         mlt_properties_parse( group, argv[ ++ i ] );
213                         }
214                         else if ( !strcmp( argv[ i ], "-serialise" ) )
215                         {
216                                 i ++;
217                         }
218                         else
219                         {
220                                 if ( store != NULL )
221                                         fprintf( store, "%s\n", argv[ i ] );
222
223                                 i ++;
224
225                                 while ( argv[ i ] != NULL && argv[ i ][ 0 ] != '-' )
226                                 {
227                                         if ( store != NULL )
228                                                 fprintf( store, "%s\n", argv[ i ] );
229                                         i += 1;
230                                 }
231
232                                 i --;
233                         }
234                 }
235
236                 // If we have no consumer, default to sdl
237                 if ( store == NULL && consumer == NULL )
238                         consumer = create_consumer( "sdl", inigo );
239
240                 if ( consumer != NULL && store == NULL )
241                 {
242                         // Apply group settings
243                         mlt_properties properties = mlt_consumer_properties( consumer );
244                         mlt_properties_inherit( properties, group );
245
246                         // Connect consumer to tractor
247                         mlt_consumer_connect( consumer, mlt_field_service( field ) );
248
249                         // Start the consumer
250                         mlt_consumer_start( consumer );
251
252                         // Transport functionality
253                         transport( inigo, consumer );
254
255                         // Stop the consumer
256                         mlt_consumer_stop( consumer );
257                 }
258                 else if ( store != NULL )
259                 {
260                         fprintf( stderr, "Project saved as %s.\n", name );
261                         fclose( store );
262                 }
263         }
264         else
265         {
266                 fprintf( stderr, "Usage: inigo [ -group [ name=value ]* ]\n"
267                                                  "             [ -consumer id[:arg] [ name=value ]* ]\n"
268                                          "             [ -filter id[:arg] [ name=value ] * ]\n"
269                                          "             [ -transition id[:arg] [ name=value ] * ]\n"
270                                                  "             [ -blank frames ]\n"
271                                                  "             [ -track ]\n"
272                                          "             [ producer [ name=value ] * ]+\n" );
273         }
274
275         // Close the consumer
276         if ( consumer != NULL )
277                 mlt_consumer_close( consumer );
278
279         // Close the producer
280         if ( inigo != NULL )
281                 mlt_producer_close( inigo );
282
283         // Close the factory
284         mlt_factory_close( );
285
286         return 0;
287 }