Expression Encoder 4 from asp.net page

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
LVL 1
mlg101Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Do you have a Silverlight web application?  If so, what version?  If not, I believe that you will need one.
0
mlg101Author Commented:
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
mlg101Author Commented:
You should look at the vb file I included, you may know how to call those functions from aspx page??
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Bob LearnedCommented:
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
mlg101Author Commented:
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
Bob LearnedCommented:
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
mlg101Author Commented:
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
Bob LearnedCommented:
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
mlg101Author Commented:
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
Bob LearnedCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bob LearnedCommented:
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
Bob LearnedCommented:
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
mlg101Author Commented:
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
Bob LearnedCommented:
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
mlg101Author Commented:
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
mlg101Author Commented:
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
Bob LearnedCommented:
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
mlg101Author Commented:
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
Bob LearnedCommented:
I can't see any problem with that code.  Are you saying that you are still getting the exception?
0
mlg101Author Commented:
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
Bob LearnedCommented:
What is the value for FileUpload1.PostedFile.FileName?
0
mlg101Author Commented:
vlc-record-2012-02-06-10h04m43s-VIDEO_TS - DVD source title2.avi-.avi
0
Bob LearnedCommented:
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
mlg101Author Commented:
yes, that will save the file in a folder called "uploads" on my server...
0
mlg101Author Commented:
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
Bob LearnedCommented:
You need a full physical path, so use Server.MapPath(fileName).
0
mlg101Author Commented:
Could you give me an example using what I have above? I'm not sure the wording.
0
Bob LearnedCommented:
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
mlg101Author Commented:
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
Bob LearnedCommented:
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
mlg101Author Commented:
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
Bob LearnedCommented:
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
mlg101Author Commented:
There is no error, I click button2 and it just refreshes the page but does not do the encode function like it should.
0
Bob LearnedCommented:
Are you able to trace the code?  Can you place a break point, and make sure that the job.Encode method is called?
0
mlg101Author Commented:
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
mlg101Author Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.