07-10-25, 06:49 PM
وجدت الشرح التالي من قوقل عبر ذكائهم الاصطناعي لكن توقفت عند نقطة لم افهمها وهي calculatedPercentage
وهذا الكود كملا:
و شكرا مسبقا
وهذا الكود كملا:
PHP كود :
Integrating an FFmpeg progress bar into a VB.NET application involves running FFmpeg as a separate process and then parsing its output to update a ProgressBar control in your VB.NET form.
1. Set up the FFmpeg Process:
Use System.Diagnostics.Process to start FFmpeg.
Redirect the standard output of the FFmpeg process to capture its progress information.
Imports System.Diagnostics
Imports System.IO
Public Class Form1
Private Sub ButtonStartFFmpeg_Click(sender As Object, e As EventArgs) Handles ButtonStartFFmpeg.Click
Dim ffmpegProcess As New Process()
ffmpegProcess.StartInfo.FileName = "ffmpeg.exe" ' Or full path to ffmpeg.exe
ffmpegProcess.StartInfo.Arguments = "-i input.mp4 -vf scale=640:-1 output.mp4" ' Your FFmpeg command
ffmpegProcess.StartInfo.UseShellExecute = False
ffmpegProcess.StartInfo.RedirectStandardOutput = True
ffmpegProcess.StartInfo.CreateNoWindow = True ' Hide the FFmpeg console window
AddHandler ffmpegProcess.OutputDataReceived, AddressOf FFmpegOutputHandler
ffmpegProcess.Start()
ffmpegProcess.BeginOutputReadLine() ' Start asynchronous reading of output
' Optional: Wait for the process to exit
' ffmpegProcess.WaitForExit()
End Sub
2. Parse FFmpeg Output for Progress:
FFmpeg outputs progress information, including out_time_us (output time in microseconds) or frame (frame number).
You'll need to parse this output to extract the relevant values.
To calculate percentage, you'll also need the total duration or total frames of the input file, which can be obtained using ffprobe beforehand.
Private Sub FFmpegOutputHandler(sender As Object, e As DataReceivedEventArgs)
If Not String.IsNullOrEmpty(e.Data) Then
' Example: Parsing for "frame=" or "out_time_us="
If e.Data.Contains("frame=") Then
Dim frameMatch As Match = Regex.Match(e.Data, "frame=\s*(\d+)")
If frameMatch.Success Then
Dim currentFrame As Integer = Integer.Parse(frameMatch.Groups(1).Value)
' Calculate percentage based on currentFrame and total frames (from ffprobe)
' Update ProgressBar1.Value on the UI thread
Me.Invoke(Sub() ProgressBar1.Value = calculatedPercentage)
End If
ElseIf e.Data.Contains("out_time_us=") Then
Dim timeMatch As Match = Regex.Match(e.Data, "out_time_us=(\d+)")
If timeMatch.Success Then
Dim outTimeUs As Long = Long.Parse(timeMatch.Groups(1).Value)
' Calculate percentage based on outTimeUs and total duration (from ffprobe)
' Update ProgressBar1.Value on the UI thread
Me.Invoke(Sub() ProgressBar1.Value = calculatedPercentage)
End If
End If
End If
End Sub
3. Update the Progress Bar:
The ProgressBar control's Value property should be updated within the FFmpegOutputHandler.
Since FFmpegOutputHandler runs on a separate thread, you must use Me.Invoke to update UI elements on the main UI thread.
Set the ProgressBar's Minimum and Maximum properties (e.g., 0 and 100 for percentage).
Considerations:
Error Handling: Implement error handling for the FFmpeg process (e.g., Exited event, checking ExitCode).
Total Duration/Frames: Use ffprobe to get the total duration or total frames of the input video before running FFmpeg for accurate percentage calculation.
Regular Expressions: Use System.Text.RegularExpressions to efficiently parse the FFmpeg output.
UI Responsiveness: Performing these operations asynchronously ensures your UI remains responsive during the FFmpeg process.
اللهم إني أعوذ بك من غلبة الدين وغلبة العدو، اللهم إني أعوذ بك من جهد البلاء ومن درك الشقاء ومن سوء القضاء ومن شماتة الأعداء
اللهم اغفر لي خطيئتي وجهلي، وإسرافي في أمري وما أنت أعلم به مني، اللهم اغفر لي ما قدمت وما أخرت، وما أسررت وما أعلنت وما أنت أعلم به مني، أنت المقدم وأنت المؤخر وأنت على كل شيء قدير
اللهم اغفر لي خطيئتي وجهلي، وإسرافي في أمري وما أنت أعلم به مني، اللهم اغفر لي ما قدمت وما أخرت، وما أسررت وما أعلنت وما أنت أعلم به مني، أنت المقدم وأنت المؤخر وأنت على كل شيء قدير

