在Upload HTML5 vid服务器端实现转换

本文关键字:实现 转换 服务器端 vid Upload HTML5 | 更新日期: 2023-09-27 17:58:56

我想在上传时从wmv转换为mp4、webm和ogv。有没有一种方法可以实现miro视频转换器或类似于codebehind的东西?

我使用的是ACT的AsyncUpload

aspx页面

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
<script type="text/javascript">
    function uploadError(sender, args) {
        if (document.getElementById('<%=lblStatus.ClientID%>').innerText.indexOf('must be a video') == -1)
            document.getElementById('<%=lblStatus.ClientID%>').innerText = "Upload error!", "<span style='color:red;'>" + args.get_errorMessage() + "</span>";
    }
    function StartUpload(sender, args) {
        document.getElementById('<%=lblStatus.ClientID%>').innerText = 'Uploading';
    }
    function UploadComplete(sender, args) {
        var filename = args.get_fileName();
        var contentType = args.get_contentType();
        if (contentType.indexOf('video') == -1) {
            document.getElementById('<%=lblStatus.ClientID%>').innerText = "Uploaded file must be a video!", "<span style='color:red;'>" + args.get_errorMessage() + "</span>";
            document.getElementById('<%=AsyncFileUpload1.ClientID%>').text.style.backgroundColor = "Red";
        }
        else {
            var text = "" + filename + "'n" + "Size: " + parseInt((args.get_length()) / 1048576) + " MB" + " (" + args.get_length()+") bytes";
            document.getElementById('<%=lblStatus.ClientID%>').innerText = text;
        }
    }
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
<h1>Add Movies to storage</h1>
        <p>File upload<p>
        <br />
            <asp:AsyncFileUpload ID="AsyncFileUpload1" Width="400px" runat="server" OnClientUploadError="uploadError"
            OnClientUploadStarted="StartUpload" OnClientUploadComplete="UploadComplete" CompleteBackColor="Lime"
            UploaderStyle="Modern" ErrorBackColor="Red" ClientIDMode="AutoID" ThrobberID="Throbber"
            UploadingBackColor="#66CCFF" OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />
        <asp:Label class="lastoppimg" ID="Throbber" runat="server" CssClass="style1">
        <img src="../Movies/LoadingImg.gif" style="left:auto; right:auto; height:32px; width:32px;" alt="loading" />   
        </asp:Label>
        <br />
        <asp:Button class="lastoppk" ID="Button1" runat="server" Text="Start Upload" OnClick="Button3_Click" />
        <asp:Label ID="lblStatus" runat="server" Style="font-family: Arial; font-size: small;"></asp:Label>
    </div>
</div>

编码隐藏

    protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    if (AsyncFileUpload1.HasFile)
    {
        string strPath = MapPath("~/Test/") + Path.GetFileName(e.filename);
        AsyncFileUpload1.SaveAs(strPath);
    }
}

在Upload HTML5 vid服务器端实现转换

Miro实际上使用FFMpeg进行代码转换
你可以自己使用FFMpeg,也可以更容易地使用。你可以通过使用MediaHandlerPro组件从.NET使用它。(他们还有一个免费版本)