( C# / VB FFMPEG Wrapper ) How can I parse progres

2019-07-29 18:25发布

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 :\

1条回答
够拽才男人
2楼-- · 2019-07-29 19:15

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");
查看更多
登录 后发表回答