Solved

Expression Encoder 4 from asp.net page

Posted on 2012-03-19
36
522 Views
Last Modified: 2012-03-24
I am trying Microsoft Expression Encoder 4. I have it installed on my server and would like to have user go to a aspx page choose video file and upload it to server where it encodes the file. I can find no documentation for using express encoder programmically from code behind.

there are sdk examples included, but I can't seem to get the functions called from my default.aspx page, where I have a textbox and a button. On button click I would like to encode the video inputted in the textbox. So in code behind, I have Protected Sub Button1_Click... where I need to call the function. I will attach the vb function page., which I need to be able to call these functions from codebehind of default page.

thanks
WPFEncoder.vb
0
Comment
Question by:mlg101
  • 19
  • 17
36 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Do you have a Silverlight web application?  If so, what version?  If not, I believe that you will need one.
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
I use visual web developer express 2010 to develop all my web applications. I don't think there is a specific Silverlight web app to develop inside of.
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
You should look at the vb file I included, you may know how to call those functions from aspx page??
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
While I haven't used Expression Encoder 4, I see that is part of the Expression Blend Suite.  I also see that the encoder SDK is installed with the application.  I don't have any of that installed, but I am always interested in learning new technology, and how it might help me in the future.  I am willing to help you find your way, and learn something new at the same time.

What have you tried so far?  Which SDK examples did you try to use?
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
Thanks for the response. I tried the Simple and one other I can't remember the name. I will check when I get back home. But I think I just don't understand what sdk is exactly if that's what I need to use or not
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
I am installing Expression Blend 4 Ultimate studio in my Oracle VirtualBox VM, so I can see what the suggested course of action would be.
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
Do I need expression blend too? I only have the trial version on expression encoder 4. I'm trying to host a video sharing site similar to how YouTube works. But users have to be able to upload their videos and they convert on my server using encoder.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
No, I don't think that you need Expression Blend, but as it is part of my MSDN subscription, Expression Encoder 4 gets installed with that.
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
Ok, to answer your question, I am trying to use the SDK "WPFEncode" in the SamplesVB folder. Thats the one I think I would need to use.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
Comment Utility
Let's collect some relevant resources:

Overview of the Expression Encoder SDK
http://msdn.microsoft.com/en-us/library/gg602440(v=expression.40).aspx

Getting started
http://msdn.microsoft.com/en-us/library/cc761462(v=expression.40).aspx

Reference assemblies:
Microsoft.Expression.Encoder
Microsoft.Expression.Encoder.Api2
Microsoft.Expression.Encoder.Types
Microsoft.Expression.Encoder.Utilities
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Simple C# example:

using Microsoft.Expression.Encoder;

static void Main(string[] args)
{
    MediaItem mediaItem = new MediaItem(@"C:\videoInput\video.wmv");

    //Creates job and media item for the video to be encoded
    Job job = new Job();
    job.MediaItems.Add(mediaItem);

    //Sets output directory
    job.OutputDirectory = @"C:\videoOutput";

    //Sets up progress callback function
    job.EncodeProgress += new EventHandler<EncodeProgressEventArgs>(OnProgress);

    //Encodes
    Console.WriteLine("Encoding…");
    job.Encode();
    Console.WriteLine("Finished encoding.");
    job.Dispose();
}

static void OnProgress(object sender, EncodeProgressEventArgs e)
{
    Console.Write("\b\b\b\b\b\b\b");
    Console.Write("{0:F2}%", e.Progress);
}

Open in new window

0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 500 total points
Comment Utility
VB.NET translation:

Imports Microsoft.Expression.Encoder

Namespace Encoder

	Public Class EncoderExample

		Private Shared Sub Main(args As String())
			Dim mediaItem As New MediaItem("C:\videoInput\video.wmv")

			'Creates job and media item for the video to be encoded
			Dim job As New Job()
			job.MediaItems.Add(mediaItem)

			'Sets output directory
			job.OutputDirectory = "C:\videoOutput"

			'Sets up progress callback function
			job.EncodeProgress += New EventHandler(Of EncodeProgressEventArgs)(OnProgress)

			'Encodes
			Console.WriteLine("Encoding…")
			job.Encode()
			Console.WriteLine("Finished encoding.")
			job.Dispose()
		End Sub

		Private Shared Sub OnProgress(sender As Object, e As EncodeProgressEventArgs)
			Console.Write(vbBack & vbBack & vbBack & vbBack & vbBack & vbBack & vbBack)
			Console.Write("{0:F2}%", e.Progress)
		End Sub

	End Class

End Namespace

Open in new window

0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
Thank you for the work you've put into this. I have a question before I start though: What is the difference between a project and a website? Visual studio lets you build a project or a website...
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
It sounds like you are talking about the difference between the Web Site model and the Web Application model.  With 2003, there was only the Web Application model.  When 2005 first came out, there was only the Web Site model at first.  People complained, and they added the Web Application model back in.  

I always prefer the control that a Web Application project gives you, versus the Web Site model, because with the Web Site model everything in the folder is part of a single web site.  You cannot have multiple web sites in the same folder.  With a solution and multiple web projects, you can have multiple web sites in one folder.
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
Ok, I started a new 'project'. copied and pasted the vb code (above) on the class1.vb page, referenced the 4 dlls, then clicked on 'build'. I got errors. that I'm attaching in a .jpg.

 Im confused also on  how to implement this into a webpage, where user enters file into a textbox or fileupload control, does that make sense?
error1.png
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
I got the "project" to work using the example sdk from the encoder for WPFEncode. It made a program that users can install on their computers. I need ot to work on a web browser, so not sure how this translates to web browser functionality...
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
When transitioning from WPF to ASP.NET, you need to be able to pull out the relevant pieces.  Take a step back, and look at the steps in the project.  Try to find the code that will do the work for you, separating the user interface (UI) stuff from the encoding stuff.

I haven't had much time lately to get my VM fully functional, so I have Expression Ultimate installed, but I need to download and install the Visual Studio .NET Ultimate, and that is a 2 GB download.
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
Ok, maybe you can help me from here. I am using the below code just to have a simple example. On debugging this, it says Media item is "nothing" so i need to get the fileupload file to represent mediaitem. please take a look at my page...

<%@ Page Language="VB" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="Microsoft.Expression.Encoder" %>
<%@ Import Namespace="Microsoft.Win32" %>
<%@ Import Namespace="Microsoft.Win32" %>
<%@ Import Namespace="System.IO" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    
   
    Protected Sub Button1_Click(sender As Object, e As System.EventArgs)
        
        ' Create the media item.
        Dim mediaItem As MediaItem
        Try
            mediaItem = New MediaItem(FileUpload1.PostedFile.FileName)
        Catch exp As InvalidMediaFileException
            'IndicateEncodingIsFinished(exp.Message)
            Return
        End Try
       

        ' Create the job, add the media item and encode.
        Using job As New Job()
            job.MediaItems.Add(MediaItem)
            job.OutputDirectory = "C:\output"

            'AddHandler job.EncodeProgress, AddressOf OnProgress

            job.Encode()
        End Using
        
        'IndicateEncodingIsFinished("Finished")
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    
    </div>
    <asp:FileUpload ID="FileUpload1" runat="server" />
    </form>
</body>
</html>

Open in new window

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
I can't see any problem with that code.  Are you saying that you are still getting the exception?
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
yes, i've written it a dozen different ways and get exeption "file not found".

I know the file is there, but attaching it to the MediaItem says "file not found".
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
What is the value for FileUpload1.PostedFile.FileName?
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
vlc-record-2012-02-06-10h04m43s-VIDEO_TS - DVD source title2.avi-.avi
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Here is what you need to do with the FileUpload control:

FileUpload Control Doesn’t Give Full Path….HELP!!!!
http://weblogs.asp.net/ashicmahtab/archive/2009/05/20/fileupload-control-doesn-t-give-full-path-help.aspx

fileUpload1.SaveAs(Server.MapPath(“~/uploads/”) & System.IO.Path.GetFilename(fileUpload1.FileName))

Open in new window

0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
yes, that will save the file in a folder called "uploads" on my server...
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
Ok, i changed it a bit. made 2 different stages. button1 to upload video file. button 2 to recall the name of the file and point the mediaItem to it. So far, it will upload the video to the folder "OVideos" and input file name in SQL DAtabase, but I still get the exception that "file not found" when it comes to the mediaItem.

Take a look at this line of code: mediaItem = New MediaItem("OVideo/" & strOrigFile.ToString)

Im not sure if that will work...well obviously it doesn't work

my entire page of code below:


<%@ Page Language="VB" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="Microsoft.Expression.Encoder" %>
<%@ Import Namespace="Microsoft.Win32" %>
<%@ Import Namespace="Microsoft.Win32" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="system.io" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    Dim strOrigFile As String
    
    'Button 1 will save the actual video file to a folder called "OVideos" on the server 
    'and also input the filename in the SQLServer Database as a reference to the video file.
    Protected Sub Button1_Click(sender As Object, e As System.EventArgs)
        
        Try
            ' Get the HttpFileCollection

            Dim hfc As HttpFileCollection = Request.Files
            
            For i As Integer = 0 To hfc.Count - 1

                Dim hpf As HttpPostedFile = hfc(i)
                                
                If hpf.ContentLength > 0 Then

                    hpf.SaveAs(Server.MapPath("~/OVideos/") & "\" & Path.GetFileName(hpf.FileName))

                End If

            Next i

        Catch ex As Exception

            ' Handle your exception here

        End Try

        Dim fileName As String = FileUpload1.FileName
        Dim fileName2 As String = FileUpload1.PostedFile.FileName
        
        Dim strConn As String = "Data Source=mydatasource"
        Dim MySQL As String = "INSERT INTO Videos (OriginalFile, FLVFile) Values (@OriginalFile, @FlVFile)"
        Dim Conn As New SqlConnection(strConn)
        Dim Cmd As New SqlCommand(MySQL, Conn)
        Cmd.Parameters.Add(New SqlParameter("@OriginalFile", fileName.ToString()))
        Cmd.Parameters.Add(New SqlParameter("@FLVFile", fileName2.ToString()))
        Conn.Open()
        Cmd.ExecuteNonQuery()
    End Sub
    
    'Button2 will recall the name of the saved file and tell mediaitem where the video is
    Protected Sub Button2_Click(sender As Object, e As System.EventArgs)
        
        Dim strConn As String = "Data Source=mydatasource"
        Dim MySQL As String = "Select * From Videos Where ID = 9"
        Dim Conn As New SqlConnection(strConn)
        Dim objDR As SqlDataReader
        Dim Cmd As New SqlCommand(MySQL, Conn)
        Conn.Open()
        objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
        While objDR.Read()
            strOrigFile = objDR("OriginalFile").ToString()
        End While
        Conn.Close()
        
        ' Create the media item.
        Dim mediaItem As MediaItem
        Try
            
            mediaItem = New MediaItem("OVideo/" & strOrigFile.ToString)
        Catch exp As InvalidMediaFileException
            'IndicateEncodingIsFinished(exp.Message)
            Return
        End Try
       

        ' Create the job, add the media item and encode.
        Using job As New Job()
            job.MediaItems.Add(mediaItem)
            job.OutputDirectory = "c:\output"

            'AddHandler job.EncodeProgress, AddressOf OnProgress

            job.Encode()
            
           
            
        End Using
         
        'IndicateEncodingIsFinished("Finished")
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button 1" />
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button 2" />
        <asp:label ID="msgs" runat="server"></asp:label>
    </div>
    
    </form>
</body>
</html>

Open in new window

0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
You need a full physical path, so use Server.MapPath(fileName).
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
Could you give me an example using what I have above? I'm not sure the wording.
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 500 total points
Comment Utility
Something like this:

Dim fileName As String = Server.MapPath("OVideo/" & strOrigFile)
mediaItem = New MediaItem(fileName)

Open in new window


You can put a breakpoint, while debugging, on the 2nd line, and examine the "fileName" variable in the Immediate, Auto, or Watch debug windows.
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
This is weird, because on debug, "filename" now has full path to video, but mediaItem still says "file not found"

On a side note...when it says Server.MapPath, is that meaning the server? or does that mean the client computer? because I will have the video stored on my server, not the users computer.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Server.MapPath converts a virtual path on the server to a full path.  This is what you need, since the file is uploaded to the server.

Do you have a full stack trace for the exception?  Can I see it please?
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
I do not and don't know how to get full stack trace? Can you maybe recreate it with the same aspx page as I have above and reference the encoder dlls? Or tell me how to get full stack trace. I know it's a lot of work but thank you.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
If you are using Internet Explorer, and running the web application from Visual Studio, you can turn off Show Friendly Error Messages

Disabling HTTP Friendly Error Messages in Internet Explorer
http://technet.microsoft.com/en-us/library/cc778248(v=ws.10).aspx

Also, you can add a Global.asax, and add some code to the Application_Error event.

How to: Handle Application-Level Errors
http://msdn.microsoft.com/en-us/library/24395wz3.aspx

Dim ex As Exception = Server.GetLastError()
Dim fullStackTrace As String = ex.ToString()

Open in new window

0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
There is no error, I click button2 and it just refreshes the page but does not do the encode function like it should.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Are you able to trace the code?  Can you place a break point, and make sure that the job.Encode method is called?
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
I finally got this to work on my local server, but it does not work on my remote server. I can't debug on the remote server like I did on the local to find out what is happening.

You solved the problem on the remote server by the Server.MapPath("OVideos/" & strOrigFile). The problem after that was I had "OVideo" instead of the filename "OVideos" just was missing an s at the end.

I will accept that as answer and then post a link to my new question if you don't mind helping me figure out why it does not work on the remote machine.

thank you!
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
Here is a link to my next question if you will.. thank you

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_27647333.html
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now