]> git.sesse.net Git - mlt/blob - src/inigo/inigo.c
cfef4fdd85c5ba11883965d3a0176d992faea9cf
[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 )
141 {
142         mlt_properties properties = mlt_producer_properties( producer );
143
144         term_init( );
145
146         fprintf( stderr, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
147         fprintf( stderr, "|1=-10| |2= -5| |3= -2| |4= -1| |5=  0| |6=  1| |7=  2| |8=  5| |9= 10|\n" );
148         fprintf( stderr, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
149
150         fprintf( stderr, "+---------------------------------------------------------------------+\n" );
151         fprintf( stderr, "|               H = back 1 minute,  L = forward 1 minute              |\n" );
152         fprintf( stderr, "|                 h = previous frame,  l = next frame                 |\n" );
153         fprintf( stderr, "|           g = start of clip, j = next clip, k = previous clip       |\n" );
154         fprintf( stderr, "|                0 = restart, q = quit, space = play                  |\n" );
155         fprintf( stderr, "+---------------------------------------------------------------------+\n" );
156
157         while( mlt_properties_get_int( properties, "done" ) == 0 )
158         {
159                 int value = term_read( );
160                 if ( value != -1 )
161                         transport_action( producer, ( char * )&value );
162         }
163 }
164
165 int main( int argc, char **argv )
166 {
167         int i;
168         mlt_consumer consumer = NULL;
169         mlt_producer inigo = NULL;
170         FILE *store = NULL;
171         char *name = NULL;
172
173         // Construct the factory
174         mlt_factory_init( getenv( "MLT_REPOSITORY" ) );
175
176         for ( i = 1; i < argc; i ++ )
177         {
178                 if ( !strcmp( argv[ i ], "-serialise" ) )
179                 {
180                         name = argv[ ++ i ];
181                         if ( strstr( name, ".inigo" ) )
182                                 store = fopen( name, "w" );
183                 }
184         }
185
186         // Get inigo producer
187         inigo = mlt_factory_producer( "inigo", &argv[ 1 ] );
188
189         if ( argc > 1 && inigo != NULL && mlt_producer_get_length( inigo ) > 0 )
190         {
191                 // Get inigo's properties
192                 mlt_properties inigo_props = mlt_producer_properties( inigo );
193
194                 // Get the field service from inigo
195                 mlt_field field = mlt_properties_get_data( inigo_props, "field", 0 );
196
197                 // Get the last group
198                 mlt_properties group = mlt_properties_get_data( inigo_props, "group", 0 );
199
200                 // Parse the arguments
201                 for ( i = 1; i < argc; i ++ )
202                 {
203                         if ( !strcmp( argv[ i ], "-consumer" ) )
204                         {
205                                 consumer = create_consumer( argv[ ++ i ], inigo );
206                                 while ( argv[ i + 1 ] != NULL && strstr( argv[ i + 1 ], "=" ) )
207                                         mlt_properties_parse( group, argv[ ++ i ] );
208                         }
209                         else if ( !strcmp( argv[ i ], "-serialise" ) )
210                         {
211                                 i ++;
212                         }
213                         else
214                         {
215                                 if ( store != NULL )
216                                         fprintf( store, "%s\n", argv[ i ] );
217
218                                 i ++;
219
220                                 while ( argv[ i ] != NULL && argv[ i ][ 0 ] != '-' )
221                                 {
222                                         if ( store != NULL )
223                                                 fprintf( store, "%s\n", argv[ i ] );
224                                         i += 1;
225                                 }
226
227                                 i --;
228                         }
229                 }
230
231                 // If we have no consumer, default to sdl
232                 if ( store == NULL && consumer == NULL )
233                         consumer = create_consumer( "sdl", inigo );
234
235                 if ( consumer != NULL && store == NULL )
236                 {
237                         // Apply group settings
238                         mlt_properties properties = mlt_consumer_properties( consumer );
239                         mlt_properties_inherit( properties, group );
240
241                         // Connect consumer to tractor
242                         mlt_consumer_connect( consumer, mlt_field_service( field ) );
243
244                         // Start the consumer
245                         mlt_consumer_start( consumer );
246
247                         // Transport functionality
248                         transport( inigo );
249
250                         // Stop the consumer
251                         mlt_consumer_stop( consumer );
252                 }
253                 else if ( store != NULL )
254                 {
255                         fprintf( stderr, "Project saved as %s.\n", name );
256                         fclose( store );
257                 }
258         }
259         else
260         {
261                 fprintf( stderr, "Usage: inigo [ -group [ name=value ]* ]\n"
262                                                  "             [ -consumer id[:arg] [ name=value ]* ]\n"
263                                          "             [ -filter id[:arg] [ name=value ] * ]\n"
264                                          "             [ -transition id[:arg] [ name=value ] * ]\n"
265                                                  "             [ -blank frames ]\n"
266                                                  "             [ -track ]\n"
267                                          "             [ producer [ name=value ] * ]+\n" );
268         }
269
270         // Close the consumer
271         if ( consumer != NULL )
272                 mlt_consumer_close( consumer );
273
274         // Close the producer
275         if ( inigo != NULL )
276                 mlt_producer_close( inigo );
277
278         // Close the factory
279         mlt_factory_close( );
280
281         return 0;
282 }