问题描述
我试图尽可能多地具体化。我搜索了很多,为FFMPEG找到了一个好的.net包装器,最好的是
我使用VB.net非常糟糕,问题是我想在C#项目中使用这个库,但是我无法将我从VB.net找到的示例程序正确地转换为C#。
所以,我编辑了我的C#应用程序,所以它将输入视频文件路径写入一个临时的.txt文件,然后运行转换器在VB中)!
我的转换器的代码:
Imports系统
导入System.IO
公共类Form1
公共WithEvents MediaConverter作为新的FFLib.Encoder
私有子ConOut(ByVal prog As String ,ByVal tl As String)处理MediaConverter.Progress
OperationPrgrss.Value = prog
Application.DoEvents()
End Sub
Private Sub stat(ByVal status)处理MediaConverter.Status
StatusLbl.Text = status
Application.DoEvents()
End Sub
Private Sub Form1_Load(sender As Object,e As EventArgs)处理MyBase.Load
尝试
使用PathFinder作为新的StreamReader(_ temp.txt)
Dim SrcPath As String
SrcPath = PathFinder.ReadLine()
PathTxtBox.Text = SrcPath
结束使用
Catch ex As Exception
MessageBox.Show 无法读取文件:&环境新闻ex.Message)
结束尝试
End Sub
私有子Form1_Shown(发件人作为对象,作为EventArgs)处理MyBase.Shown
MediaGenerator。 RunWorkerAsync()
End Sub
Private Sub MediaGenerator_DoWork(sender As Object,e As ComponentModel.DoWorkEventArgs)处理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
结束类
我想要做的是转换视频文件[有时它是WEBM,FLV,MP4或3GP],
和上述代码成功,但问题是使用时:
MediaConverter.Video_Codec = MediaConverter.Vcodec_NONE
进度条不起作用,值为0!
&当我使用任何视频编解码器,它的工作原理完美[进度条],但创建的MP3文件将无法与任何媒体播放器,或在智能手机和电视等..
...
那么问题是什么?我该怎么解决呢?
我尝试了很多改变包装库源代码中的一些功能,但正如我之前提到的...我只是一个新手@ VB.net:\
获取FFMpeg进展的最简单的方法是解析其控制台输出。
我写了免费和易于使用的FFMpeg包装器有进度事件:
var conv = new NReco.VideoConverter.FFMpegConverter();
conv.ConvertProgress + =(o,args)=> {
Console.WriteLine(String.Format(Progress:{0} / {1} \r\\\
,args.Processed,args.TotalDuration);
};
conv.ConvertMedia(inputFile1,outFile,flv);
I'd try to become specific as much as I can .
I searched a lot to find a good .net wrapper for FFMPEG, the best was VB FFmpeg Wrapper
I'm so bad at using VB.net, and the problem was that I want to use this library in a C# project but I couldn't convert the example program I found from VB.net to C# correctly .
So, I've edited my C# application, so it writes input video file path to a temporary .txt file .. then run the "Converter" ( Which is written in VB ) !
The code of my "Converter" :
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
What I'm trying to do is converting a video file [ sometime it's WEBM, FLV, MP4 or 3GP ],and the above code does it successfully, but the problem is when using :
MediaConverter.Video_Codec = MediaConverter.Vcodec_NONE
the progress bar doesn't work, it's value remains 0 !& When I use any Video codec it works perfectly [ the progress bar ], but the created MP3 file won't work ever with any media player, or in Smartphone & Tv's .. etc ;
...
So, what's the problem ?! and how can I solve it ?I tried a lot to change some functions in the wrapper library source, but as I mentioned before ... I'm just a newbie @ VB.net :\
The simplest way to get progress of FFMpeg is parsing its console output.I've written free and easy-to-use FFMpeg wrapper Video Converter .NET that has progress event for that:
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");
这篇关于(C#/ VB FFMPEG Wrapper)如何解析视频到音频的进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!