我会努力尽可能地具体化。
我搜索了很多为FFMPEG找到一个好的.net包装器,最好的是VB FFmpeg Wrapper
我使用VB.net非常糟糕,问题是我想在C#项目中使用这个库但是我无法将我从VB.net找到的示例程序正确转换为C#。
所以,我编辑了我的C#应用程序,因此它将输入视频文件路径写入临时的.txt文件..然后运行“转换器”(用VB编写)!
我的“转换器”的代码:
Imports System
Imports System.IO
Public Class Form1
Public WithEvents MediaConverter As New FFLib.Encoder
Private Sub ConOut(ByVal prog As String, ByVal tl As String) Handles MediaConverter.Progress
OperationPrgrss.Value = prog
Application.DoEvents()
End Sub
Private Sub stat(ByVal status) Handles MediaConverter.Status
StatusLbl.Text = status
Application.DoEvents()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Using PathFinder As New StreamReader("_temp.txt")
Dim SrcPath As String
SrcPath = PathFinder.ReadLine()
PathTxtBox.Text = SrcPath
End Using
Catch ex As Exception
MessageBox.Show("The file couldn't be read : " & Environment.NewLine & ex.Message)
End Try
End Sub
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
MediaGenerator.RunWorkerAsync()
End Sub
Private Sub MediaGenerator_DoWork(sender As Object, e As ComponentModel.DoWorkEventArgs) Handles MediaGenerator.DoWork
MediaConverter.OverWrite = False
MediaConverter.SourceFile = PathTxtBox.Text
MediaConverter.Format = MediaConverter.Format_MP3
MediaConverter.AudioCodec = MediaConverter.AudioCodec_mp3
MediaConverter.Video_Codec = MediaConverter.Vcodec_NONE
MediaConverter.Threads = 0
MediaConverter.OverWrite = True
Dim OutputFldr As String = AppDomain.CurrentDomain.BaseDirectory & "MP3Files\\"
MediaConverter.OutputPath = OutputFldr
MediaConverter.AnalyzeFile()
MediaConverter.Encode()
End Sub
End Class
我要做的是转换视频文件[有时是WEBM,FLV,MP4或3GP], 并且上面的代码成功完成了,但问题是在使用时:
MediaConverter.Video_Codec = MediaConverter.Vcodec_NONE
进度条不起作用,它的值仍为0! &安培;当我使用任何视频编解码器时,它完美地工作[进度条],但创建的MP3文件将不能用于任何媒体播放器,或智能手机&电视......等;
...
那么,问题是什么?!我该如何解决? 我尝试了很多改变包装库源代码中的一些函数,但正如我之前提到的......我只是一个新手@ VB.net:\
答案 0 :(得分:1)
获得FFMpeg进展的最简单方法是解析其控制台输出。 我已经编写了免费且易于使用的FFMpeg包装器Video Converter .NET,它具有进度事件:
var conv = new NReco.VideoConverter.FFMpegConverter();
conv.ConvertProgress += (o, args) => {
Console.WriteLine( String.Format("Progress: {0} / {1}\r\n", args.Processed, args.TotalDuration );
};
conv.ConvertMedia(inputFile1, outFile, "flv");