3 * \brief video output definition
5 * Copyright (C) 2007-2008 Ushodaya Enterprises Limited
6 * \author Dan Dennedy <dan@dennedy.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "mlt_profile.h"
24 #include "mlt_factory.h"
25 #include "mlt_properties.h"
31 #define PROFILES_DIR "/share/mlt/profiles/"
33 /** Load a profile from the system folder
36 static mlt_profile
mlt_profile_select( const char *name
)
38 char *filename
= NULL
;
39 const char *prefix
= getenv( "MLT_PROFILES_PATH" );
40 mlt_properties properties
= mlt_properties_load( name
);
41 mlt_profile profile
= NULL
;
43 // Try to load from file specification
44 if ( properties
&& mlt_properties_get_int( properties
, "width" ) )
46 filename
= calloc( 1, strlen( name
) + 1 );
48 // Load from $prefix/share/mlt/profiles
49 else if ( prefix
== NULL
)
52 filename
= calloc( 1, strlen( prefix
) + strlen( PROFILES_DIR
) + strlen( name
) + 2 );
53 strcpy( filename
, prefix
);
54 if ( filename
[ strlen( filename
) - 1 ] != '/' )
55 filename
[ strlen( filename
) ] = '/';
56 strcat( filename
, PROFILES_DIR
);
58 // Use environment variable instead
61 filename
= calloc( 1, strlen( prefix
) + strlen( name
) + 2 );
62 strcpy( filename
, prefix
);
63 if ( filename
[ strlen( filename
) - 1 ] != '/' )
64 filename
[ strlen( filename
) ] = '/';
68 strcat( filename
, name
);
69 profile
= mlt_profile_load_file( filename
);
72 mlt_properties_close( properties
);
78 /** Construct a profile.
81 mlt_profile
mlt_profile_init( const char *name
)
83 mlt_profile profile
= NULL
;
85 // Explicit profile by name gets priority over environment variables
87 profile
= mlt_profile_select( name
);
89 // Try to load by environment variable
90 if ( profile
== NULL
)
92 // MLT_PROFILE is preferred environment variable
93 if ( getenv( "MLT_PROFILE" ) )
94 profile
= mlt_profile_select( getenv( "MLT_PROFILE" ) );
95 // MLT_NORMALISATION backwards compatibility
96 else if ( getenv( "MLT_NORMALISATION" ) && strcmp( getenv( "MLT_NORMALISATION" ), "PAL" ) )
97 profile
= mlt_profile_select( "dv_ntsc" );
99 profile
= mlt_profile_select( "dv_pal" );
101 // If still not loaded (no profile files), default to PAL
102 if ( profile
== NULL
)
104 profile
= calloc( 1, sizeof( struct mlt_profile_s
) );
107 mlt_environment_set( "MLT_PROFILE", "dv_pal" );
108 profile
->description
= strdup( "PAL 4:3 DV or DVD" );
109 profile
->frame_rate_num
= 25;
110 profile
->frame_rate_den
= 1;
111 profile
->width
= 720;
112 profile
->height
= 576;
113 profile
->progressive
= 0;
114 profile
->sample_aspect_num
= 16;
115 profile
->sample_aspect_den
= 15;
116 profile
->display_aspect_num
= 4;
117 profile
->display_aspect_den
= 3;
124 /** Load a profile from specific file
127 mlt_profile
mlt_profile_load_file( const char *file
)
129 mlt_profile profile
= NULL
;
131 // Load the profile as properties
132 mlt_properties properties
= mlt_properties_load( file
);
135 // Simple check if the profile is valid
136 if ( mlt_properties_get_int( properties
, "width" ) )
138 profile
= mlt_profile_load_properties( properties
);
140 // Set MLT_PROFILE to basename
141 char *filename
= strdup( file
);
142 mlt_environment_set( "MLT_PROFILE", basename( filename
) );
145 mlt_properties_close( properties
);
148 // Set MLT_NORMALISATION to appease legacy modules
149 char *profile_name
= mlt_environment( "MLT_PROFILE" );
152 if ( strstr( profile_name
, "_ntsc" ) ||
153 strstr( profile_name
, "_60" ) ||
154 strstr( profile_name
, "_30" ) )
156 mlt_environment_set( "MLT_NORMALISATION", "NTSC" );
158 else if ( strstr( profile_name
, "_pal" ) ||
159 strstr( profile_name
, "_50" ) ||
160 strstr( profile_name
, "_25" ) )
162 mlt_environment_set( "MLT_NORMALISATION", "PAL" );
168 /** Load a profile from a properties object
171 mlt_profile
mlt_profile_load_properties( mlt_properties properties
)
173 mlt_profile profile
= calloc( 1, sizeof( struct mlt_profile_s
) );
176 if ( mlt_properties_get( properties
, "name" ) )
177 mlt_environment_set( "MLT_PROFILE", mlt_properties_get( properties
, "name" ) );
178 if ( mlt_properties_get( properties
, "description" ) )
179 profile
->description
= strdup( mlt_properties_get( properties
, "description" ) );
180 profile
->frame_rate_num
= mlt_properties_get_int( properties
, "frame_rate_num" );
181 profile
->frame_rate_den
= mlt_properties_get_int( properties
, "frame_rate_den" );
182 profile
->width
= mlt_properties_get_int( properties
, "width" );
183 profile
->height
= mlt_properties_get_int( properties
, "height" );
184 profile
->progressive
= mlt_properties_get_int( properties
, "progressive" );
185 profile
->sample_aspect_num
= mlt_properties_get_int( properties
, "sample_aspect_num" );
186 profile
->sample_aspect_den
= mlt_properties_get_int( properties
, "sample_aspect_den" );
187 profile
->display_aspect_num
= mlt_properties_get_int( properties
, "display_aspect_num" );
188 profile
->display_aspect_den
= mlt_properties_get_int( properties
, "display_aspect_den" );
193 /** Load an anonymous profile from string
196 mlt_profile
mlt_profile_load_string( const char *string
)
198 mlt_properties properties
= mlt_properties_new();
201 const char *p
= string
;
204 if ( strcmp( p
, "" ) && p
[ 0 ] != '#' )
205 mlt_properties_parse( properties
, p
);
206 p
= strchr( p
, '\n' );
210 return mlt_profile_load_properties( properties
);
213 /** Get the framerate as float
216 double mlt_profile_fps( mlt_profile aprofile
)
219 return ( double ) aprofile
->frame_rate_num
/ aprofile
->frame_rate_den
;
224 /** Get the sample aspect ratio as float
227 double mlt_profile_sar( mlt_profile aprofile
)
230 return ( double ) aprofile
->sample_aspect_num
/ aprofile
->sample_aspect_den
;
235 /** Get the display aspect ratio as float
238 double mlt_profile_dar( mlt_profile aprofile
)
241 return ( double ) aprofile
->display_aspect_num
/ aprofile
->display_aspect_den
;
246 /** Free up the global profile resources
249 void mlt_profile_close( mlt_profile profile
)
253 if ( profile
->description
)
254 free( profile
->description
);
255 profile
->description
= NULL
;