backmerge
[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 my (%pipes, %cfg);
8
9 sub extension
10 {
11   my $path = shift;
12   my $ext;
13
14   # get only the bit after the last period.  We don't deal with
15   # .tar.gz extensions do we ?
16   if ($path =~ /\./)
17   {
18     my $ext = $path;
19     $ext =~ s/^.*\.//;
20   }
21   else { $ext = ""; }
22
23   return $ext;
24 }
25
26 sub read_config
27 {
28   my $config_file = `echo -n ~`."/.gst";
29   if (-e $config_file)
30   {
31     open CONFIG, $config_file;
32     while (<CONFIG>)
33     {
34       chomp;
35       s/#.*//;
36       s/\s+$//;
37       next unless length;
38       my ($var, $value) = split (/\s*=\s*/, $_, 2);
39       $cfg{$var} = $value;
40     }
41     if (!($cfg{AUDIOSINK}))
42     {
43       print "Please add an AUDIOSINK to $config_file !\n";
44     }
45     if (!($cfg{VIDEOSINK}))
46     {
47       print "Please add a VIDEOSINK to $config_file !\n";
48     }
49   }
50   else
51   {
52     print "No configuration file $config_file found.  You might want to create one.\n";
53   }
54   if (!defined $cfg{AUDIOSINK})  { $cfg{AUDIOSINK} = "osssink"; }
55   if (!defined $cfg{VIDEOSINK})  { $cfg{VIDEOSINK} = "colorspace ! xvideosink"; }
56   if (!defined $cfg{CVS_PATH})   { $cfg{CVS_PATH} =  `echo -n ~`."/gst/cvs"; }
57 }
58
59 sub playfile($$)
60 {
61     my ($file, $ext) = @_;
62     $ext = lc $ext;
63
64     my $pipe;
65     if ($cfg{VISUALIZER} && ($pipe = $pipes{"vis." . $ext}))
66     {
67         $command = "gst-launch filesrc location=\"$file\" ! $pipe";
68         print "Running $command\n";
69         system ("PATH=\$PATH:".$cfg{CVS_PATH}."/gstreamer/tools $command");
70     }
71     elsif ($pipe = $pipes{$ext})
72     {
73         $command = "gst-launch filesrc location=\"$file\" ! $pipe";
74         print "Running $command\n";
75         system ("PATH=\$PATH:".$cfg{CVS_PATH}."/gstreamer/tools $command");
76     }
77     else
78     {
79         print "No suitable pipe found for extension $ext.\n";
80     }
81 }
82
83 ### main
84
85 read_config ();
86
87 %pipes = ( 
88   "ac3", "a52dec ! $cfg{AUDIOSINK}",
89   "au", "auparse ! $cfg{AUDIOSINK}",
90   "avi", "avidemux video_%02d! { queue ! windec ! $cfg{VIDEOSINK} } avidemux0.audio_%02d! { queue ! mad ! $cfg{AUDIOSINK} }",
91   "fli", "flxdec ! colorspace ! $cfg{VIDEOSINK}",
92   "m1v", "mpegdemux video_%02d! { queue ! mpeg2dec ! $cfg{VIDEOSINK} }",
93   "m2v", "mpegdemux video_%02d! { queue ! mpeg2dec ! $cfg{VIDEOSINK} }",
94   "mod", "modplug !  $cfg{AUDIOSINK}",
95   "mp2", "mad ! $cfg{AUDIOSINK}",
96   "mp3", "mad ! $cfg{AUDIOSINK}",
97   "mpg", "mpegdemux video_%02d! { queue ! mpeg2dec ! $cfg{VIDEOSINK} } mpegdemux0.audio_%02d! { queue ! mad ! $cfg{AUDIOSINK} }",
98   "ogg", "vorbisfile ! $cfg{AUDIOSINK}",
99   "sid", "siddec ! $cfg{AUDIOSINK}",
100   "swf", "swfdec video_%02d! { queue ! colorspace ! $cfg{VIDEOSINK} }  swfdec0.audio_%02d! { queue ! $cfg{AUDIOSINK} }",
101   "vob", "mpegdemux video_%02d! { queue ! mpeg2dec ! $cfg{VIDEOSINK} }  mpegdemux0.private_stream_1_%02d! { queue ! a52dec ! $cfg{AUDIOSINK} }",
102   "wav", "wavparse ! $cfg{AUDIOSINK}",
103 );
104
105 if ($cfg{VISUALIZER}) {
106   %pipes = (
107     %pipes,
108     "vis.mp3", "mad ! tee silent=true 'tee1.src0!' queue leaky=1 ! { $cfg{VISUALIZER} ! colorspace ! $cfg{VIDEOSINK} } 'tee1.src1!' $cfg{AUDIOSINK}",
109     "vis.ogg", "vorbisdec ! tee silent=true 'tee1.src0!' queue leaky=1 ! { $cfg{VISUALIZER} ! colorspace ! $cfg{VIDEOSINK} } 'tee1.src1!' $cfg{AUDIOSINK}",
110     "vis.wav", "wavparse ! tee silent=true 'tee1.src0!' queue leaky=1 ! { $cfg{VISUALIZER} ! colorspace ! $cfg{VIDEOSINK} } 'tee1.src1!' $cfg{AUDIOSINK}",
111   );
112 }              
113
114 if ($#ARGV == -1) {
115     print STDERR "Usage: gst-launch-ext filename[s]\n";
116     exit 1;
117 }
118
119 my $file;
120 while ($file = shift @ARGV) {
121     my $ext = extension ($file);
122     if ($ext eq 'm3u')
123     {
124         open (PLAYLIST, '<', $file);
125         my $file2;
126         while ($file2 = <PLAYLIST>) {
127             chomp $file2;
128             my $ext2 = extension ($file2);
129             playfile($file2, $ext2);
130         }
131         close PLAYLIST;
132     } else {
133         playfile($file, $ext);
134     }
135 }