Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using Gst;
- using Gst.BasePlugins;
- using Gst.CorePlugins;
- public class MetaData {
- private static PlayBin2 playbin;
- private static FakeSink videoSink, audioSink;
- private static Pad pad;
- private static Caps caps;
- private static TagList tagList;
- public static void Main (string [] args) {
- Application.Init ();
- if (args.Length < 1) {
- Console.WriteLine ("Please give filenames to read metadata from\n\n");
- return;
- }
- string filename = args[0];
- playbin = new PlayBin2("play");
- videoSink = new FakeSink("video");
- audioSink = new FakeSink("audio");
- playbin.VideoSink = videoSink;
- playbin.AudioSink = audioSink;
- playbin.Uri = "file://" + filename;
- State state, pending;
- StateChangeReturn stateReturn = playbin.SetState(State.Paused);
- if (stateReturn == StateChangeReturn.Async) {
- if (StateChangeReturn.Success != playbin.GetState (out state, out pending, Clock.Second * 5)) {
- Console.WriteLine ("State change failed for {0}. Aborting\n", filename);
- return;
- }
- } else if (stateReturn != StateChangeReturn.Success) {
- Console.WriteLine ("{0} - Could not read file ({1})\n", filename, stateReturn);
- return;
- }
- /*
- tagList = playbin.GetVideoTags(0);
- if (tagList != null) {
- Console.WriteLine ("TagList Empty?: {0}?", tagList.IsEmpty);
- Console.WriteLine ("Tag count: {0}?", tagList.Size);
- foreach(string tag in tagList.Tags) {
- Console.WriteLine ("Tag: {0}", tag);
- }
- tagList.Dispose();
- }
- */
- tagList = GetTagMessages(playbin);
- if (tagList != null) {
- Console.WriteLine ("Tag count: {0}", tagList.Size);
- foreach (string tag in tagList.Tags) {
- uint count = tagList.GetTagSize (tag);
- for (uint i = 0; i < count; i++) {
- Console.WriteLine ("{0}: {1}", tag.PadRight (20), tagList[tag, i].ToString());
- }
- }
- tagList.Dispose();
- }
- pad = playbin.GetVideoPad(0);
- if (pad == null) {
- Console.WriteLine ("I didn't get a pad?\n\n");
- return;
- }
- caps = pad.NegotiatedCaps;
- if (caps.IsFixed) {
- foreach(Structure structure in caps) {
- foreach(string fieldName in structure.Fields) {
- Console.WriteLine ("{0}: {1}", fieldName.PadRight (20), structure.GetValue(fieldName).Val.ToString());
- }
- }
- }
- stateReturn = playbin.SetState(State.Null);
- playbin.Dispose();
- }
- private static TagList GetTagMessages(Element playbin) {
- Bus bus = playbin.Bus;
- TagList tagList = null;
- bool done = false;
- while (!done) {
- Message message = bus.Pop ();
- if (message == null) {
- break;
- }
- if (message.Type == MessageType.Tag) {
- Pad pad;
- TagList newTags;
- message.ParseTag (out pad, out newTags);
- if (tagList != null) {
- tagList = tagList.Merge (newTags, TagMergeMode.KeepAll);
- newTags.Dispose ();
- } else {
- tagList = newTags;
- }
- }
- message.Dispose ();
- }
- bus.Dispose ();
- return tagList;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement