Advertisement
Forage

Untitled

Aug 29th, 2011
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. using Gst;
  5. using Gst.BasePlugins;
  6. using Gst.CorePlugins;
  7.  
  8. public class MetaData {
  9.     private static PlayBin2 playbin;
  10.     private static FakeSink videoSink, audioSink;
  11.     private static Pad pad;
  12.     private static Caps caps;
  13.     private static TagList tagList;
  14.  
  15.     public static void Main (string [] args) {
  16.         Application.Init ();
  17.        
  18.         if (args.Length < 1) {
  19.             Console.WriteLine ("Please give filenames to read metadata from\n\n");
  20.             return;
  21.         }
  22.        
  23.         string filename = args[0];
  24.            
  25.         playbin = new PlayBin2("play");
  26.         videoSink = new FakeSink("video");
  27.         audioSink = new FakeSink("audio");
  28.            
  29.         playbin.VideoSink = videoSink;
  30.         playbin.AudioSink = audioSink;
  31.    
  32.         playbin.Uri = "file://" + filename;
  33.        
  34.         State state, pending;
  35.         StateChangeReturn stateReturn = playbin.SetState(State.Paused);
  36.  
  37.         if (stateReturn == StateChangeReturn.Async) {
  38.             if (StateChangeReturn.Success != playbin.GetState (out state, out pending, Clock.Second * 5)) {
  39.                 Console.WriteLine ("State change failed for {0}. Aborting\n", filename);
  40.                 return;
  41.             }
  42.         } else if (stateReturn != StateChangeReturn.Success) {
  43.             Console.WriteLine ("{0} - Could not read file ({1})\n", filename, stateReturn);
  44.             return;
  45.         }
  46.  
  47. /*         
  48.         tagList = playbin.GetVideoTags(0);
  49.        
  50.         if (tagList != null) {
  51.             Console.WriteLine ("TagList Empty?: {0}?", tagList.IsEmpty);
  52.             Console.WriteLine ("Tag count: {0}?", tagList.Size);
  53.             foreach(string tag in tagList.Tags) {
  54.                 Console.WriteLine ("Tag: {0}", tag);
  55.             }
  56.            
  57.             tagList.Dispose();
  58.         }
  59. */
  60.  
  61.        
  62.         tagList = GetTagMessages(playbin);
  63.        
  64.         if (tagList != null) {
  65.             Console.WriteLine ("Tag count: {0}", tagList.Size);
  66.            
  67.             foreach (string tag in tagList.Tags) {
  68.                 uint count = tagList.GetTagSize (tag);
  69.                
  70.                 for (uint i = 0; i < count; i++) {
  71.                     Console.WriteLine ("{0}: {1}", tag.PadRight (20), tagList[tag, i].ToString());
  72.                 }
  73.             }
  74.            
  75.             tagList.Dispose();
  76.         }
  77.    
  78.         pad = playbin.GetVideoPad(0);
  79.        
  80.         if (pad == null) {
  81.             Console.WriteLine ("I didn't get a pad?\n\n");
  82.             return;
  83.         }
  84.        
  85.         caps = pad.NegotiatedCaps;
  86.  
  87.         if (caps.IsFixed) {
  88.             foreach(Structure structure in caps) {
  89.                 foreach(string fieldName in structure.Fields) {
  90.                     Console.WriteLine ("{0}: {1}", fieldName.PadRight (20), structure.GetValue(fieldName).Val.ToString());             
  91.                 }
  92.             }
  93.         }
  94.        
  95.         stateReturn = playbin.SetState(State.Null);
  96.         playbin.Dispose();
  97.     }
  98.    
  99.     private static TagList GetTagMessages(Element playbin) {
  100.         Bus bus = playbin.Bus;
  101.         TagList tagList = null;
  102.         bool done = false;
  103.        
  104.         while (!done) {
  105.             Message message = bus.Pop ();
  106.            
  107.             if (message == null) {
  108.                 break;
  109.             }
  110.            
  111.             if (message.Type == MessageType.Tag) {
  112.                 Pad pad;
  113.                 TagList newTags;
  114.                
  115.                 message.ParseTag (out pad, out newTags);
  116.                
  117.                 if (tagList != null) {
  118.                     tagList = tagList.Merge (newTags, TagMergeMode.KeepAll);
  119.                     newTags.Dispose ();
  120.                 } else {
  121.                     tagList = newTags;
  122.                 }
  123.             }
  124.            
  125.             message.Dispose ();
  126.         }
  127.        
  128.         bus.Dispose ();
  129.         return tagList;
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement