added more media formats: mod, sid, au
[platform/upstream/gstreamer.git] / tools / gst-launch-ext
1 #!/usr/bin/perl -w
2
3 # launch a gst-launch pipeline for the supplied media file
4 # use the extension to determine the gst-launch pipeline
5 # make use of default output sinks
6
7 ### packages
8
9 use File::Basename;
10
11
12 my (%pipes, %cfg);
13
14 sub extension
15 {
16   my $path = shift;
17   my $ext = (fileparse ($path, '\..*?'))[2];
18   $ext =~ s/^\.//;
19   return $ext;
20 }
21
22 sub read_config
23 {
24   my $config_file = `echo -n ~`."/.gst";
25   if (-e $config_file)
26   {
27     open CONFIG, $config_file;
28     while (<CONFIG>)
29     {
30       chomp;
31       s/#.*//;
32       s/\s+$//;
33       next unless length;
34       my ($var, $value) = split (/\s*=\s*/, $_, 2);
35       $cfg{$var} = $value;
36     }
37     if (!($cfg{AUDIOSINK}))
38     {
39       print "Please add an AUDIOSINK to $config_file !\n";
40     }
41     if (!($cfg{VIDEOSINK}))
42     {
43       print "Please add a VIDEOSINK to $config_file !\n";
44     }
45   }
46   else
47   {
48     print "No configuration file $config_file found.  You might want to create one.\n";
49   }
50   if (!defined $cfg{AUDIOSINK})  { $cfg{AUDIOSINK} = "osssink"; }
51   if (!defined $cfg{VIDEOSINK})  { $cfg{VIDEOSINK} = "sdlvideosink"; }
52   if (!defined $cfg{CVS_PATH})   { $cfg{CVS_PATH} =  `echo -n ~`."/gst/cvs"; }
53 }
54
55 sub playfile($$)
56 {
57     my ($file, $ext) = @_;
58
59     my $pipe;
60     if ($cfg{VISUALIZER} && ($pipe = $pipes{"vis." . $ext}))
61     {
62         $command = "gst-launch filesrc location=\"$file\" ! $pipe";
63         print "Running $command\n";
64         system ("PATH=\$PATH:".$cfg{CVS_PATH}."/gstreamer/tools $command");
65     }
66     elsif ($pipe = $pipes{$ext})
67     {
68         $command = "gst-launch filesrc location=\"$file\" ! $pipe";
69         print "Running $command\n";
70         system ("PATH=\$PATH:".$cfg{CVS_PATH}."/gstreamer/tools $command");
71     }
72     else
73     {
74         print "No suitable pipe found for extension $ext.\n";
75     }
76 }
77
78 ### main
79
80 read_config ();
81
82 %pipes = ( 
83   "mp3", "mad ! $cfg{AUDIOSINK}",
84   "ogg", "vorbisdec ! $cfg{AUDIOSINK}",
85   "mpg", "mpegdemux video_00! { queue ! mpeg2dec ! $cfg{VIDEOSINK} } mpegdemux0.audio_00! { queue ! mad ! $cfg{AUDIOSINK} }",
86   "avi", "avidemux video_00! { queue ! windec ! $cfg{VIDEOSINK} } avidemux0.audio_00! { queue ! mad ! $cfg{AUDIOSINK} }",
87   "vob", "mpegdemux video_00! { queue max_level=500 ! mpeg2dec ! $cfg{VIDEOSINK} } mpegdemux0.private_stream_1.0! { queue max_level=500 ! a52dec ! $cfg{AUDIOSINK} }",
88   "wav", "wavparse ! $cfg{AUDIOSINK}",
89   "fli", "flxdec ! colorspace ! $cfg{VIDEOSINK}",
90   "mod", "modplug !  $cfg{AUDIOSINK}",
91   "sid", "siddec ! $cfg{AUDIOSINK}",
92   "au", "auparse ! $cfg{AUDIOSINK}"
93 );
94
95 if ($cfg{VISUALIZER}) {
96   %pipes = (
97     %pipes,
98     "vis.mp3", "mad ! tee silent=true 'tee1.src0!' queue leaky=1 ! { $cfg{VISUALIZER} ! colorspace ! $cfg{VIDEOSINK} } 'tee1.src1!' $cfg{AUDIOSINK}",
99     "vis.ogg", "vorbisdec ! tee silent=true 'tee1.src0!' queue leaky=1 ! { $cfg{VISUALIZER} ! colorspace ! $cfg{VIDEOSINK} } 'tee1.src1!' $cfg{AUDIOSINK}",
100     "vis.wav", "wavparse ! tee silent=true 'tee1.src0!' queue leaky=1 ! { $cfg{VISUALIZER} ! colorspace ! $cfg{VIDEOSINK} } 'tee1.src1!' $cfg{AUDIOSINK}",
101   );
102 }              
103
104 if ($#ARGV == -1) {
105     print STDERR "Usage: gst-launch-ext filename[s]\n";
106     exit 1;
107 }
108
109 my $file;
110 while ($file = shift @ARGV) {
111     my $ext = extension ($file);
112     if ($ext eq 'm3u')
113     {
114         open (PLAYLIST, '<', $file);
115         my $file2;
116         while ($file2 = <PLAYLIST>) {
117             chomp $file2;
118             my $ext2 = extension ($file2);
119             playfile($file2, $ext2);
120         }
121         close PLAYLIST;
122     } else {
123         playfile($file, $ext);
124     }
125 }