Advertisement
Chiddix

Encoding

Apr 28th, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.95 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3.  
  4. /**
  5.  * Represents a single video encoding.
  6.  * @author Ryan Greene
  7.  *
  8.  */
  9. public enum Encoding {
  10.  
  11.     FLV_240p(5, "FLV", "240p", "Sorenson H.263", "N/A", 0.25, "MP3", 64),
  12.     FLV_270p(6, "FLV", "270p", "Sorenson H.263", "N/A", 0.8, "MP3", 64),
  13.     GP3_NA(13, "3GP", "N/A", "MPEG-4 Visual", "N/A", 0.5, "AAC", -1),
  14.     GP3_144p(17, "3GP", "144p", "MPEG-4 Visual", "Simple", 0.05, "AAC", 24),
  15.     MP4_360p(18, "MP4", "360p", "H.264", "Baseline", 0.5, "AAC", 96),
  16.     MP4_720p(22, "MP4", "720p", "H.264", "High", 2.45, "AAC", 192),
  17.     FLV_360p(34, "FLV", "360p", "H.264", "Main", 0.5, "AAC", 128),
  18.     FLV_480p(35, "FLV", "480p", "H.264", "Main", 0.4, "AAC", 128),
  19.     GP3_240p(36, "3GP", "240p", "MPEG-4 Visual", "Simple", 0.17, "AAC", 38),
  20.     MP4_1080p(37, "MP4", "1080p", "H.264", "High", 3.65, "AAC", 192),
  21.     MP4_3072p(38, "MP4", "3072p", "H.264", "High", 3.25, "AAC", 192),
  22.     WEBM_360p(43, "WebM", "360p", "VP8", "N/A", 0.5, "Vorbis", 128),
  23.     WEBM_480p(44, "WebM", "480p", "VP8", "N/A", 1.0, "Vorbis", 128),
  24.     WEBM_720p(45, "WebM", "720p", "VP8", "N/A", 2.0, "Vorbis", 192),
  25.     WEBM_1080p(46, "FLV", "1080p", "VP8", "N/A", -1, "Vorbis", 192),
  26.     MP4_360p_3D(82, "MP4", "360p", "H.264", "3D", 0.5, "AC", 96),
  27.     MP4_240p_3D(83, "MP4", "240p", "H.264", "3D", 0.5, "AC", 96),
  28.     MP4_720p_3D(84, "MP4", "720p", "H.264", "3D", 2.45, "AAC", 152),
  29.     MP4_520p_3D(85, "MP4", "520p", "H.264", "3D", 2.45, "AAC", 152),
  30.     WEBM_360p_3D_128kbs(100, "360p", "240p", "3D", "N/A", -1, "Vorbis", 128),
  31.     WEBM_360p_3D_192kbs(101, "360p", "240p", "3D", "N/A", -1, "Vorbis", 192),
  32.     WEBM_720p_3D(102, "WebM", "720p", "VP8", "3D", -1, "Vorbis", 192),
  33.     FLV_720p(120, "FLV", "720p", "AVC", "Main@L3.1", 2, "AAC", 128);
  34.  
  35.     /**
  36.      * The itag value.
  37.      */
  38.     private final int itagValue;
  39.    
  40.     /**
  41.      * The default container.
  42.      */
  43.     private final String defaultContainer;
  44.    
  45.     /**
  46.      * The video resolution.
  47.      */
  48.     private final String videoResolution;
  49.    
  50.     /**
  51.      * The video encoding.
  52.      */
  53.     private final String videoEncoding;
  54.    
  55.     /**
  56.      * The video profile.
  57.      */
  58.     private final String videoProfile;
  59.    
  60.     /**
  61.      * The video bitrate (MBit/s).
  62.      */
  63.     private final double videoBitrate;
  64.    
  65.     /**
  66.      * The audio encoding.
  67.      */
  68.     private final String audioEncoding;
  69.    
  70.     /**
  71.      * The audio bitrate (kbit/s).
  72.      */
  73.     private final int audioBitrate;
  74.    
  75.     /**
  76.      * A map of itag values to encodings.
  77.      */
  78.     private static Map<Integer, Encoding> encodings = new HashMap<Integer, Encoding>();
  79.  
  80.     /**
  81.      * Gets a encoding by a itag value.
  82.      *
  83.      * @param itagValue
  84.      *            The itag value.
  85.      * @return The encoding, or <code>null</code> if the itag value is not an encoding.
  86.      */
  87.     public static Encoding forItagValue(int itagValue) {
  88.         return encodings.get(itagValue);
  89.     }
  90.  
  91.     /**
  92.      * Populates the encodings map.
  93.      */
  94.     static {
  95.         for (Encoding encoding : Encoding.values()) {
  96.             encodings.put(encoding.itagValue, encoding);
  97.         }
  98.     }
  99.    
  100.     /**
  101.      * Constructs the encoding.
  102.      * @param itagValue The itag value.
  103.      * @param defaultContainer The default container.
  104.      * @param videoResolution The video resolution.
  105.      * @param videoEncoding The video encoding.
  106.      * @param videoProfile The video profile.
  107.      * @param videoBitrate The video bitrate (MBit/s).
  108.      * @param audioEncoding The audio encoding.
  109.      * @param audioBitrate The audio bitrate (kbit/s).
  110.      */
  111.     private Encoding(int itagValue, String defaultContainer, String videoResolution, String videoEncoding,
  112.             String videoProfile, double videoBitrate, String audioEncoding, int audioBitrate) {
  113.         this.itagValue = itagValue;
  114.         this.defaultContainer = defaultContainer;
  115.         this.videoResolution = videoResolution;
  116.         this.videoEncoding = videoEncoding;
  117.         this.videoProfile = videoProfile;
  118.         this.videoBitrate = videoBitrate;
  119.         this.audioEncoding = audioEncoding;
  120.         this.audioBitrate = audioBitrate;
  121.     }
  122.  
  123.     /**
  124.      * Gets the itag value.
  125.      * @return The itag value.
  126.      */
  127.     public int getItagValue() {
  128.         return itagValue;
  129.     }
  130.  
  131.     /**
  132.      * Gets the default container.
  133.      * @return The default container.
  134.      */
  135.     public String getDefaultContainer() {
  136.         return defaultContainer;
  137.     }
  138.  
  139.     /**
  140.      * Gets the video resolution.
  141.      * @return The video resolution.
  142.      */
  143.     public String getVideoResolution() {
  144.         return videoResolution;
  145.     }
  146.  
  147.     /**
  148.      * Gets the video encoding.
  149.      * @return The video encoding.
  150.      */
  151.     public String getVideoEncoding() {
  152.         return videoEncoding;
  153.     }
  154.  
  155.     /**
  156.      * Gets the video profile.
  157.      * @return The video profile.
  158.      */
  159.     public String getVideoProfile() {
  160.         return videoProfile;
  161.     }
  162.  
  163.     /**
  164.      * Gets the video bitrate (MBit/s).
  165.      * @return The video bitrate (MBit/s).
  166.      */
  167.     public double getVideoBitrate() {
  168.         return videoBitrate;
  169.     }
  170.  
  171.     /**
  172.      * Gets the audio encoding.
  173.      * @return The audio encoding.
  174.      */
  175.     public String getAudioEncoding() {
  176.         return audioEncoding;
  177.     }
  178.  
  179.     /**
  180.      * Gets the audio bitrate (kbit/s).
  181.      * @return The audio bitrate (kbit/s).
  182.      */
  183.     public int getAudioBitrate() {
  184.         return audioBitrate;
  185.     }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement