gnome-record-screen / GNOME-Record-Screen / src / VideoEncoderImplementations.cs

/**
 * VideoEncoderImplementations.cs
 * 
 * This module implements the various encoder classes.
 *
 * :copyright: 2008 mitsuhiko.
 * :license: BSD
 */

using Gnome.RecordScreen.UI;


namespace Gnome.RecordScreen.Implementations {
			
	/**
	 * Encodes videos with the H.264 encoder into an AVI container.
	 */
	class H264VideoEncoder : VideoEncoder {
		
		public H264VideoEncoder ()
			: base ("H.264", "x264enc", VideoContainer.Avi)
		{}
		
		public override Gdk.Rectangle OptimizeRectangle (Gdk.Rectangle rectangle)
		{
			int width = rectangle.Width;
			int height = rectangle.Height;
			
			if (width % 16 != 0)
				width = 16 * (width / 16 + 1);
			if (height % 16 != 0)
				height = 16 * (height / 16 + 1);
			
			if (height != rectangle.Height || width != rectangle.Width)
				rectangle = new Gdk.Rectangle (rectangle.X, rectangle.Y,
				                               width, height);
			
			return rectangle;
		}
		
		public override ConfigurationPane CreateConfigurationPane ()
		{
			return new H264ConfigurationPane ();
		}
		
		public override string GetEncoderArguments (ConfigurationPane pane)
		{
			H264ConfigurationPane hpane = pane as H264ConfigurationPane;
			if (hpane == null)
				return null;
			return "bitrate=" + hpane.BitRate;
		}
	}
	
	/**
	 * Encodes videos using the Theora encoder.
	 */
	class TheoraVideoEncoder : VideoEncoder {
			
		public TheoraVideoEncoder ()
			: base ("Theora", "theoraenc", VideoContainer.Ogg)
		{}
		
		public override ConfigurationPane CreateConfigurationPane ()
		{
			return new TheoraConfigurationPane ();
		}
		
		public override string GetEncoderArguments (ConfigurationPane pane)
		{
			TheoraConfigurationPane tpane = pane as TheoraConfigurationPane;
			if (tpane == null)
				return null;
			return "quality=" + tpane.VideoQuality;
		}
	}
	
	/**
	 * Encodes videos using the MPEG encoder.
	 */
	class MpegVideoEncoder : VideoEncoder {
					
		public MpegVideoEncoder ()
			: base ("MPEG", "mpeg2enc", VideoContainer.Avi)
		{}
		
		public override ConfigurationPane CreateConfigurationPane ()
		{
			return new MpegConfigurationPane ();
		}
		
		public override string GetEncoderArguments (ConfigurationPane pane)
		{
			MpegConfigurationPane mpane = pane as MpegConfigurationPane;
			if (mpane == null)
				return null;
			return "format=" + mpane.Format + " bitrate=" + mpane.BitRate;
		}
	}
	
	/**
	 * Encodes videos into multiple PNG files.
	 */
	class PngVideoEncoder : VideoEncoder {
		
		public PngVideoEncoder ()
			: base ("PNG", "pngenc", VideoContainer.Png)
		{}
		
		public override string GetEncoderArguments (ConfigurationPane pane)
		{
			return "snapshot=false";
		}
	}
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.