PowerShell script with user preset?

Answered PowerShell script with user preset?

  • Sunday, June 27, 2010 5:53 AM
     
     

    Hey Everyone,

    I've recently been experimenting with Expression Encoder and the Command Line Power Shell module. Took me awhile but I got it compiled, only to find out that I cannot apply a custom User Profile (or at least not that I've been able to find out?)

    Sooo I did some research and found this post for Expression Encoder 3 ---> http://www.clarkezone.net/default.aspx?id=dfbc9580-258f-4970-9d03-a8ee2cae46d6

    Sooo I did the modifications and recompiled and then could specify the user preset, however, it wasn't actually applied and ended up just using the "default" setup.

    Anyone have any suggestions?

    Thanks in advance everyone!

    Iskondi

All Replies

  • Sunday, June 27, 2010 6:21 AM
    Moderator
     
     Answered
    To apply a preset via any SDK-based application (including the PowerShell sample), simply use "job.ApplyPreset(<filename>)" which will load your preset (if it's valid of course).
  • Sunday, June 27, 2010 5:17 PM
     
     

    Hey Eric,

    Thanks for such a prompt reply!!

    I rebuilt the module without the change I made and tried to apply the job.ApplyPreset option that you specified above, but I must be doing it wrong... I ran:

    Convert-Media -Input 'C:\Users\dlevinger\Videos\InputFile' 'job.ApplyPreset(C:\Path\to\Preset.xml)'

    Which gives me this error:

    Convert-Media : A positional parameter cannot be found that accepts argument 'job.ApplyPreset(C:\path\to\Preset.xml)

    '.

    At line:1 char:14

    + Convert-Media <<<<  -Input 'C:\Users\dlevinger\Videos\InputFile' 'job.ApplyPreset(C:\path\to\Preset.xml)'

        + CategoryInfo          : InvalidArgument: (:) [Convert-Media], ParameterBindingException

        + FullyQualifiedErrorId : PositionalParameterNotFound,EncoderCmdlet.ConvertMedia

     

    Thoughts? Or did I totally misunderstand how to use what you told me?

     

    If I run:

    Convert-Media -Input 'C:\Users\dlevinger\Videos\InputFile' -job.ApplyPreset(C:\Path\to\Preset.xml)

    Then it opens IE showing me my XML and says :

    Convert-Media : Parameter set cannot be resolved using the specified named parameters.

    At line:1 char:14

    + Convert-Media <<<<  -Input 'C:\Users\dlevinger\Videos\InputFile' -job.ApplyPreset(C:\Path\to\preset.xml)

        + CategoryInfo          : InvalidArgument: (:) [Convert-Media], ParameterBindingException

        + FullyQualifiedErrorId : AmbiguousParameterSet,EncoderCmdlet.ConvertMedia

     

     

    Thanks!

    Iskondi

  • Monday, June 28, 2010 4:01 AM
    Moderator
     
     Proposed Answer

    "ApplyPreset" is an API call from our SDK, no an option in our PowerShell sample. I mere was pointing the SDK call that you could add into our PowerShell sample to support custom presets.

    Please refer to the SDK documentation for more information.

  • Monday, June 28, 2010 4:22 AM
     
     

    Hmmm. ok Eric, I'll give a read through the SDK Documentation and see what I can turn up from there.

    When you say "...our PowerShell  sample..." I'm assuming that's referring to the whole ConvertMedia.cs file...

    I have a feeling that this will be over my head but I'll give the SDK a read and see if I can't figure out how I could add that into your sample.

    If anyone has any recommendations of where else I may be able to look, or what else I might be able to read to help me figure it out, I'd greatly appreciate it!

    Thanks!

    Iskondi

  • Monday, June 28, 2010 4:30 AM
    Moderator
     
     Answered

    Another way to answer your question would be to say that we don't ship with a command-line application, and we don't really have an SDK sample that supports custom presets. So you would need to create it yourself, either by modifying one of our samples (it doesn't need to be the PowerShell sample, you can start with "simple" if you'd like) or creating your own from scratch. Either way, importing a media file, applying a custom preset and encoding it should take about 10 lines of code (you could simply add an ApplyPreset() call in our Simple sample for example).

     

  • Monday, June 28, 2010 4:23 PM
     
      Has Code

    Hey Eric!

    Thanks so much for your assistance. Took me a little bit to figure it out, but I did exactly what you suggested and modified the "Simple" example!

    The code below correctly allows me to specify the input file, the user preset I want to use and the output directory! Exactly what I was looking for.

     

    using System;
    using Microsoft.Expression.Encoder;
    
    namespace Simple
    {
      class Program
      {
        static void Main(string[] args)
        {
          // Checks to see if there are the proper number of arguments
          if (args.Length != 3)
          {
            // Use the command-line arguments to build the list of media files to encode
            Console.WriteLine("Usage: Simple <MediaFile> <Preset> <Output>");
            return;
          }
    
          MediaItem mediaItem;
          try
          {
            // sets file name to media item
            mediaItem = new MediaItem(args[0]);
          }
          catch(InvalidMediaFileException exp)
          {
            // Media file was invalid and it returns an error msg
            Console.WriteLine(exp.ToString());
            return;
          }
    
          // verifies encoding of file
          Console.WriteLine("\nEncoding: {0}", args[0].ToString());
    
          // Create a job and the media item for the video we wish
          // to encode.
          Job job = new Job();
          job.MediaItems.Add(mediaItem);
    
          // Set up the progress callback function
          job.EncodeProgress
            += new EventHandler<EncodeProgressEventArgs>(OnProgress);
    
    			// Set the Preset
    			job.ApplyPreset(args[1]);
    			
          // Set the output directory and encode.
    			job.OutputDirectory = args[2];
    
          // encodes job
          job.Encode();
          job.Dispose();
        }
    
        static void OnProgress(object sender, EncodeProgressEventArgs e)
        {
          Console.Write("\b\b\b\b\b\b\b\b");
          Console.Write("{0:F2}%", e.Progress);
        }
      }
    }
    

     

    Sooo by running:

    Simple.exe C:\Path\To\Videos\File.mpg C:\Path\To\UserPreset.xml C:\OutputDirectory I get my shiney new wmv file with my preset applied in that directory :-) YAY!

    Thanks again!

    Iskondi

  • Monday, June 28, 2010 4:41 PM
    Moderator
     
     

    Glad you figured it out. Independently of that, I think you do have a good point that the PowerShell sample would benefit from getting custom preset functionality, I'll open a bug on it so we fix it in our next minor release.

    Thanks.

  • Monday, June 28, 2010 4:45 PM
     
     

    :-) That would be very cool!!

    Thanks again Eric,

    Iskondi

  • Friday, October 12, 2012 10:43 AM
     
     
    That would be cool.  Has this been done yet?
  • Friday, October 12, 2012 4:42 PM
    Moderator
     
      Has Code

    Looks like it was. From the sample:

            /// <summary>
            /// Parameter representing the full path or the name of a preset to be applied on the job
            /// </summary>
            [Parameter(ParameterSetName = "Objects", Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Path to an Expression Encoder preset file or preset name")]
            [ValidateNotNullOrEmpty]
            public string Preset
            {
                get;
                set;
            }
    And if it doesn't do exactly what you would like, it should be a trivial exercise to add that functionality to the sample.