Ich versuche, FFMPEG in meine asp.net-Website zu integrieren. Der Prozess, den ich abzuschließen versuche, besteht darin, ein Video hochzuladen, zu prüfen, ob es .avi, .mov oder .wmv ist, und dieses Video dann mit x264 in ein mp4 zu konvertieren, damit mein Flash-Player es abspielen kann.
Ich verwende eine http-Handler-Datei (ashx), um meinen Upload zu verarbeiten. Dies ist, wo ich auch meine Konvertierung Code setzen. Ich bin nicht sicher, ob dies der beste Ort, um es zu setzen, aber ich wollte sehen, wenn ich zumindest bekommen konnte es funktioniert.
Außerdem konnte ich die Konvertierung manuell über die cmd-Zeile durchführen. Der Fehler -2 tritt auf, wenn ich den Standardfehler des von mir ausgeführten Prozesses ausgebe.
Ich erhalte diese Fehlermeldung:
FFmpeg Version SVN-r23001, Copyright (c) 2000-2010 der FFmpeg-Entwickler
erstellt am 1. Mai 2010 06:06:15 mit gcc 4.4.2
Konfiguration: --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 --einschalten-pthreads --einschalten-libvorbis --einschalten-libtheora --einschalten-libspeex --einschalten-libmp3lame --einschalten-libopenjpeg --einschalten-libxvid --einschalten-libschroedinger --einschalten-libx264 --einschalten-libopencore_amrwb --einschalten-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: Fehler Nummer -2 ist aufgetreten
Hier ist der nachstehende Code:
<%@ WebHandler Language="VB" Class="upload" %>
System der Einfuhren Einfuhren System.Web Importe System.IO Importe System.Diagnostics Importe System.Threading
Public Class upload : Implementiert 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
Klasse beenden