+
+ // If "MRL", then create AVInputFormat
+ AVInputFormat *format = NULL;
+ AVFormatParameters *params = NULL;
+ char *standard = NULL;
+ char *mrl = strchr( file, ':' );
+
+ // Only if there is not a protocol specification that avformat can handle
+ if ( mrl && !url_exist( file ) )
+ {
+ // 'file' becomes format abbreviation
+ mrl[0] = 0;
+
+ // Lookup the format
+ format = av_find_input_format( file );
+
+ // Eat the format designator
+ file = ++mrl;
+
+ if ( format )
+ {
+ // Allocate params
+ params = calloc( sizeof( AVFormatParameters ), 1 );
+
+ // These are required by video4linux (defaults)
+ params->width = 640;
+ params->height = 480;
+ params->frame_rate = 25;
+ params->frame_rate_base = 1;
+ params->device = file;
+ params->channels = 2;
+ params->sample_rate = 48000;
+ }
+
+ // Parse out params
+ mrl = strchr( file, '?' );
+ while ( mrl )
+ {
+ mrl[0] = 0;
+ char *name = strdup( ++mrl );
+ char *value = strchr( name, '=' );
+ if ( value )
+ {
+ value[0] = 0;
+ value++;
+ char *t = strchr( value, '&' );
+ if ( t )
+ t[0] = 0;
+ if ( !strcmp( name, "frame_rate" ) )
+ params->frame_rate = atoi( value );
+ else if ( !strcmp( name, "frame_rate_base" ) )
+ params->frame_rate_base = atoi( value );
+ else if ( !strcmp( name, "sample_rate" ) )
+ params->sample_rate = atoi( value );
+ else if ( !strcmp( name, "channels" ) )
+ params->channels = atoi( value );
+ else if ( !strcmp( name, "width" ) )
+ params->width = atoi( value );
+ else if ( !strcmp( name, "height" ) )
+ params->height = atoi( value );
+ else if ( !strcmp( name, "standard" ) )
+ {
+ standard = strdup( value );
+ params->standard = standard;
+ }
+ }
+ free( name );
+ mrl = strchr( mrl, '&' );
+ }
+ }