Example #1
0
 public static VideoFormat buildVideoFormatFromProperty(String str) {
   VideoFormat rv = new VideoFormat();
   int currNameStart = 0;
   int currValueStart = -1;
   for (int i = 0; i < str.length(); i++) {
     char c = str.charAt(i);
     if (c == '\\') {
       // Escaped character, so skip the next one
       i++;
       continue;
     } else if (c == '=') {
       // We found the name=value delimeter, set the value start position
       currValueStart = i + 1;
     } else if ((c == ';' || i == str.length() - 1) && currValueStart != -1) {
       if (c != ';' && i == str.length() - 1) i++;
       // We're at the end of the name value pair, get their values!
       String name = str.substring(currNameStart, currValueStart - 1);
       String value = str.substring(currValueStart, i);
       currNameStart = i + 1;
       currValueStart = -1;
       if (value.length() > 0) {
         try {
           if ("f".equals(name)) rv.setFormatName(unescapeString(value));
           else if ("fps".equals(name)) rv.fps = Float.parseFloat(value);
           else if ("fpsd".equals(name)) rv.fpsDen = Integer.parseInt(value);
           else if ("fpsn".equals(name)) rv.fpsNum = Integer.parseInt(value);
           else if ("ar".equals(name)) rv.aspectRatio = Float.parseFloat(value);
           else if ("ard".equals(name)) rv.arDen = Integer.parseInt(value);
           else if ("arn".equals(name)) rv.arNum = Integer.parseInt(value);
           else if ("w".equals(name)) rv.width = Integer.parseInt(value);
           else if ("h".equals(name)) rv.height = Integer.parseInt(value);
           else if ("lace".equals(name) && "1".equals(value)) rv.interlaced = true;
           else if ("cs".equals(name)) rv.colorspace = unescapeString(value).intern();
           else if ("br".equals(name)) rv.bitrate = Integer.parseInt(value);
           else if ("vbr".equals(name)) rv.vbr = "1".equals(value);
           else if ("main".equals(name)) rv.primary = "yes".equalsIgnoreCase(value);
           else if ("index".equals(name)) rv.orderIndex = Integer.parseInt(value);
           else if ("tag".equals(name)) rv.id = value.intern();
           else if ("fpa".equals(name)) rv.framePack3D = value.intern();
         } catch (Exception e) {
           System.out.println("ERROR parsing video format info " + str + " of:" + e);
         }
       }
     }
   }
   return rv;
 }