تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[سؤال] حول استخدام ffmpeg مع progressbar
#2
PHP كود :
Imports System.Text.RegularExpressions

Public Class Form1

    Dim ffprobe 
As String "ffprobe.exe"   ' Path to ffprobe.exe
    Dim ffmpeg As String = "ffmpeg.exe"     ' 
Path to ffmpeg.exe

    Dim inputFile 
As String "input.mp4"   ' Path to input file
    Dim outputFile As String = "output.mp4" ' 
Path to output file

    Dim totalDurationSeconds 
As Double ' total duration seconds

    Private Sub ButtonStart_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonStart.Click
        If IO.File.Exists(outputFile) Then
            MsgBox(String.Format(" The file '
{0}' exists.", outputFile))
            Exit Sub
        End If

        ProgressBar1.Value = 0
        LabelProgress.Text = "0%"
        Dim processingThread As New System.Threading.Thread(AddressOf StartFFmpegProcessing)
        processingThread.Start()

        ' 
ButtonStart disable
        ButtonStart
.Enabled False
    End Sub

    Private Sub StartFFmpegProcessing
()
 
       ' Get total duration seconds
        GetTotalDurationSeconds(inputFile)

        ' 
ffmpeg Process
        Dim ffmpegProcess 
As New Process()
 
       Dim startInfo As New ProcessStartInfo()

 
       startInfo.FileName ffmpeg ' Path to ffmpeg.exe
        startInfo.Arguments = "-i """ & inputFile & """ -progress pipe:1 -vf scale=640:-1 """ & outputFile & """" ' 
Example argumentsincluding -progress pipe:for machine-readable output
        startInfo
.UseShellExecute False
        startInfo
.RedirectStandardOutput True
        startInfo
.CreateNoWindow True

        ffmpegProcess
.StartInfo startInfo
        ffmpegProcess
.EnableRaisingEvents True

        AddHandler ffmpegProcess
.OutputDataReceivedAddressOf FFmpegOutputHandler

        ffmpegProcess
.Start()
 
       ffmpegProcess.BeginOutputReadLine() ' Start asynchronous reading of output

        ' 
Wait for FFmpeg to exit (optionalcan be handled in a separate thread)
 
       ffmpegProcess.WaitForExit()

 
       ' Clean up event handler
        RemoveHandler ffmpegProcess.OutputDataReceived, AddressOf FFmpegOutputHandler

        ' 
ButtonStart enable
        ButtonStart
.Invoke(Sub() ButtonStart.Enabled True)

 
   End Sub

    Private Sub FFmpegOutputHandler
(ByVal sender As ObjectByVal e As DataReceivedEventArgs)
 
       If Not String.IsNullOrEmpty(e.DataThen
            
' Parse FFmpeg output to extract progress information
            ' 
For examplelook for "out_time_ms=" or "time=" to get current time
            
' Example: Assuming totalDurationSeconds is available (e.g., from a class-level variable)
            Dim currentTimeMatch As Match = Regex.Match(e.Data, "out_time_ms=(\d+)")
            If currentTimeMatch.Success Then
                Dim currentTimeMilliseconds As Long = Long.Parse(currentTimeMatch.Groups(1).Value)
                Dim currentTimeSeconds As Double = currentTimeMilliseconds / 1000.0

                If totalDurationSeconds > 0 Then
                    Dim progressPercentage As Integer = CInt((currentTimeSeconds / totalDurationSeconds) * 100)
                    If progressPercentage > 100 Then progressPercentage = 100
                    If progressPercentage < 0 Then progressPercentage = 0

                    ' 
Update ProgressBar on the UI thread
                    Me
.Invoke(Sub()
 
                                 ProgressBar1.Value progressPercentage
                                  LabelProgress
.Text progressPercentage.ToString() & "%"
 
                             End Sub)
 
               End If
 
           End If
 
       End If
 
   End Sub

    Private Sub GetTotalDurationSeconds
(ByVal inputFile As String)
 
       ' Get total duration seconds (from ffprobe)
        Dim proc As New Process()
        Dim startInfo As New ProcessStartInfo()
        startInfo.FileName = ffprobe ' 
Path to ffprobe.exe
        startInfo
.Arguments "-v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 """ inputFile """"
 
       startInfo.RedirectStandardInput True
        startInfo
.RedirectStandardOutput True
        startInfo
.CreateNoWindow True
        startInfo
.UseShellExecute False
        proc
.StartInfo startInfo
        proc
.Start()
 
       If Not IsNothing(procThen totalDurationSeconds Val(proc.StandardOutput.ReadToEnd) * 1000.0
        proc
.WaitForExit()
 
   End Sub

End 
Class 
الرد }}}
تم الشكر بواسطة: justforit


الردود في هذا الموضوع
حول استخدام ffmpeg مع progressbar - بواسطة justforit - 07-10-25, 06:49 PM
RE: حول استخدام ffmpeg مع progressbar - بواسطة Zuhare - 08-10-25, 12:47 PM

المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  كيف نضبط قيمة progressbar في حال العد العكسي justforit 2 165 01-11-25, 09:43 AM
آخر رد: justforit
  كيف الى استخدام webview2 من ملف dll justforit 2 201 28-10-25, 02:49 AM
آخر رد: justforit
  [VB.NET] استخدام كلمة برمجية كمتغير mmaalmesry 1 169 02-10-25, 08:55 AM
آخر رد: Taha Okla
  [VB.NET] مشكلة تظهر عند استخدام الملف manifest mmaalmesry 2 626 12-05-25, 12:15 AM
آخر رد: mmaalmesry
  [VB.NET] تحويل pdf الى صورة بدون استخدام الاكروبات بأستخدام adobe reader العادى فقط AhmedNagib 1 1,181 11-07-24, 01:16 PM
آخر رد: تركي الحلواني
  استخدام فونت جديد في البرنامج Emam emam 5 510 14-04-24, 01:29 PM
آخر رد: عبد العزيز البسكري
  [VB.NET] أرغب فى استخدام هذا الكود بالتحديد على الإصدار 10 AmeenRashed 3 520 19-01-24, 12:42 PM
آخر رد: Taha Okla
  [VB.NET] كيف اقوم بمنع المستخدم من استخدام الكيبورد وخصوصا مفتاح Print screen Ameenh 0 496 07-10-23, 10:45 PM
آخر رد: Ameenh
  طريقة استخدام حلقة For Each ASUS2020 5 939 11-04-23, 01:26 AM
آخر رد: ASUS2020
  [VB.NET] بطئ تحديث كونترول اثناء استخدام linq الماجيك مسعد 9 1,536 23-10-22, 02:39 PM
آخر رد: الماجيك مسعد

التنقل السريع :


يقوم بقرائة الموضوع: