ASP.net FFMPEG视频转换接收错误:“错误号-2发生”

时间:2010-05-03 19:20:43

标签: asp.net ffmpeg flv video-encoding h.264

我正在尝试将FFMPEG集成到我的asp.net网站中。我要完成的过程是上传视频,检查是否是.avi,.mov或.wmv,然后使用x264将此视频转换为mp4,以便我的Flash播放器可以播放。

我正在使用http处理程序(ashx)文件来处理我的上传。这是我也在放置转换代码的地方。我不确定这是否是最好的地方,但我想知道我是否至少可以使它工作。

此外,我能够通过cmd行手动完成转换。当我从我执行的过程中输出标准错误时,错误-2出现。

这是我收到的错误:

FFmpeg版本SVN-r23001,版权所有(c)2000-2010 FFmpeg开发人员

建立于2010年5月1日06:06:15与gcc 4.4.2

配置: - enable-memalign-hack --cross-prefix = i686-mingw32- - cc = ccache-i686-mingw32-gcc --arch = i686 --target-os = mingw32 --enable-runtime -cpudetect --enable-avisynth --enable-gpl --enable-version3 --enable-bzlib --enable-libgsm --enable-libfaad --enable-pthreads --enable-libvorbis --enable-libtheora --enable -libspeex --enable-libmp3lame --enable-libopenjpeg --enable-libxvid --enable-libschroedinger --enable-libx264 --enable-libopencore_amrwb --enable-libopencore_amrnb

libavutil 50.15。 0 / 50.15。 0   libavcodec 52.66。 0 / 52.66。 0   libavformat 52.61。 0 / 52.61。 0   libavdevice 52. 2. 0 / 52. 2. 0   libswscale 0.10。 0 / 0.10。 0

532010_Robotica_720.wmv:发生错误编号-2

以下是以下代码:

<%@ WebHandler Language="VB" Class="upload" %>

进口系统 进口System.Web 进口System.IO 导入System.Diagnostics 进口System.Threading

公共类上传:实现IHttpHandler

Public currentTime As System.DateTime

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

    currentTime = System.DateTime.Now

    If (Not context.Request.Files("Filedata") Is Nothing) Then
        Dim file As HttpPostedFile : file = context.Request.Files("Filedata")

        Dim targetDirectory As String : targetDirectory = HttpContext.Current.Server.MapPath(context.Request("folder"))
        Dim targetFilePath As String : targetFilePath = Path.Combine(targetDirectory, currentTime.Month & currentTime.Day & currentTime.Year & "_" & file.FileName)

        Dim fileNameArray As String()
        fileNameArray = Split(file.FileName, ".")

        If (System.IO.File.Exists(targetFilePath)) Then
            System.IO.File.Delete(targetFilePath)
        End If

        file.SaveAs(targetFilePath)

        Select Case fileNameArray(UBound(fileNameArray))
                Case "avi", "mov", "wmv" 
                    Dim fileargs As String = 
                    fileargs = "-y -i " & currentTime.Month & currentTime.Day & 
                    currentTime.Year & "_" & file.FileName & " -ab 96k -vcodec libx264 
                    -vpre normal -level 41 "
                    fileargs += "-crf 25 -bufsize 20000k -maxrate 25000k -g 250 -r 20 
                    -s 900x506 -coder 1 -flags +loop "
                    fileargs += "-cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 
                    -subq 7 -me_range 16 -keyint_min 25 "
                    fileargs += "-sc_threshold 40 -i_qfactor 0.71 
                    -rc_eq 'blurCplx^(1-qComp)' -bf 16 -b_strategy 1 -bidir_refine 1 "
                    fileargs += "-refs 6 -deblockalpha 0 -deblockbeta 0 -f mp4 " &   
                    currentTime.Month & currentTime.Day & currentTime.Year & "_" & 
                    file.FileName & ".mp4"

                    Dim proc As New Diagnostics.Process()
                    proc.StartInfo.FileName "ffmpeg.exe"
                    proc.StartInfo.Arguments = fileargs
                    proc.StartInfo.UseShellExecute = False
                    proc.StartInfo.CreateNoWindow = True
                    proc.StartInfo.RedirectStandardOutput = True
                    proc.StartInfo.RedirectStandardError = True

                    AddHandler proc.OutputDataReceived, AddressOf SaveTextToFile

                    proc.Start()
                    SaveTextToFile2(proc.StandardError.ReadToEnd())
                    proc.WaitForExit()
                    proc.Close()
            End Select

            context.Response.Write("1")

    End If

End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
    Get
        Return False
    End Get
End Property

Private Shared Sub SaveTextToFile(ByVal sendingProcess As Object, ByVal strData As DataReceivedEventArgs)

    Dim FullPath As String = "text.txt"
    Dim Contents As String = ""

    Dim objReader As StreamWriter
    objReader = New StreamWriter(FullPath)

    If Not String.IsNullOrEmpty(strData.Data) Then
        objReader.Write(Environment.NewLine + strData.Data)
    End If

    objReader.Close()

End Sub

Private Sub SaveTextToFile2(ByVal strData As String)

    Dim FullPath As String = "texterror.txt"
    Dim Contents As String = ""

    Dim objReader As StreamWriter
    objReader = New StreamWriter(FullPath)

    objReader.Write(Environment.NewLine + strData)

    objReader.Close()

End Sub

结束班

1 个答案:

答案 0 :(得分:0)

问题与ffmpeg应用程序本身的权限有关。一旦我更新了权限,错误就消失了。