iowatcher: iowatcher: support png2theora for videos

ffmpeg is not available on all distributions, so include Theora
as an option, via png2theora, if the output movie filename ends
in .ogg or .ogv

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
diff --git a/iowatcher/README b/iowatcher/README
index 09dd91d..f91fb6c 100644
--- a/iowatcher/README
+++ b/iowatcher/README
@@ -16,8 +16,8 @@
 
 Building:
 
-	Type make and make install.  We need ffmpeg and librsvg to make
-	movies, otherwise there are no dependencies.
+	Type make and make install.  We need ffmpeg or png2theora, and
+	librsvg to make movies, otherwise there are no dependencies.
 
 The basic options:
 
@@ -35,9 +35,12 @@
 	-l Sets a label in the graph for a trace file.  The labels are added in
 	   the same order the trace files are added.
 
-	-m Create a movie.  This defaults to the mp4 file format, and you
-	   should also use -o filename.mp4.  You can use any other filename,
-	   but the end result will be an mp4.
+	-m Create a movie.  The file format depends on the extension used in the
+	   -o filename.* option.  If you specify an .ogv or .ogg extension, the
+	   result will be Ogg Theora video, if png2theora is available.
+	   If you use an .mp4 extension, the result will be an mp4 video if
+	   ffmpeg is avilable.  You can use any other extension, but the end
+	   result will be an mp4.
 
 	   You can use --movie=spindle or --movie=rect, which changes the
 	   style of the IO mapping.
diff --git a/iowatcher/main.c b/iowatcher/main.c
index 1f2f278..44cbb81 100644
--- a/iowatcher/main.c
+++ b/iowatcher/main.c
@@ -870,12 +870,31 @@
 
 static void mencode_movie(char *movie_dir)
 {
-	fprintf(stderr, "Creating movie %s\n", movie_dir);
+	fprintf(stderr, "Creating movie %s with ffmpeg\n", movie_dir);
 	snprintf(line, line_len, "ffmpeg -r 20 -y -i %s/%%10d-%s.svg.png -b:v 250k "
 		 "-vcodec libx264 %s", movie_dir, output_filename, output_filename);
 	system(line);
 }
 
+static void tencode_movie(char *movie_dir)
+{
+	fprintf(stderr, "Creating movie %s with png2theora\n", movie_dir);
+	snprintf(line, line_len, "png2theora -o %s %s/%%010d-%s.svg.png",
+			output_filename, movie_dir, output_filename);
+	system(line);
+}
+
+static void encode_movie(char *movie_dir)
+{
+	char *last_dot = strrchr(output_filename, '.');
+
+	if (last_dot &&
+	    (!strncmp(last_dot, ".ogg", 4) || !strncmp(last_dot, ".ogv", 4))) {
+		tencode_movie(movie_dir);
+	} else
+		mencode_movie(movie_dir);
+}
+
 static void cleanup_movie(char *movie_dir)
 {
 	fprintf(stderr, "Removing movie dir %s\n", movie_dir);
@@ -1002,7 +1021,7 @@
 		free_all_plot_history(&movie_history);
 	}
 	convert_movie_files(movie_dir);
-	mencode_movie(movie_dir);
+	encode_movie(movie_dir);
 	cleanup_movie(movie_dir);
 	free(movie_dir);
 }