B4J Question video player timing with saving the frame

peacemaker

Expert
Licensed User
Longtime User
HI, All

It's impossible to set the play position in the video processing by OpenCV v.3.4 - the errors are documented even in the higher versions.
So, question, what lib can help to make:

1. Video player with play\pause, seek bar, high speed playback
2. quality saving the frame of the selected time to a JPG-file (non-sceentshot)

?

Can MediaView help to do it ?
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Yes, working super:
B4X:
Dim vf As String = cboVideoFiles.Items.Get(f)   'video file name
Dim piece As Long = videotime2 - videotime1    'ticks
Dim freq As Float = split_qty / (piece/1000)
Dim output_file As String = File.Combine(output_folder, "output_" & DateTime.Now & "_" & DeviceID & "_%05d" & ".jpg")
Slice(TicksToTime(videotime1), File.Combine(ProjectFolder, vf), freq, output_file)

Sub Slice(from As String, video As String, freq As String, out As String)
    'ffmpeg -i input_file.mp4 -ss 00:03:45 -vframes 1 output.jpg
    Dim ff As String = File.Combine(ffmpeg_folder, "ffmpeg.exe")
    Dim Args As List
    Args.Initialize
    Args.Add("-ss")
    Args.Add(from)    'seconds
    Args.Add("-i")
    Args.Add(video)
    Args.Add("-r")
    Args.Add(NumberFormat2(freq, 1, 2, 2, False))
    Args.Add("-qscale:v")
    Args.Add("5")    '3=86%, 5=76% JPG quality
    Args.Add("-vframes")
    Args.Add((split_qty + 1).As(String))
    Args.Add(File.GetName(out))
             
             
    Dim sh As Shell
    sh.Initialize("ffmpeg", ff, Args)
    sh.WorkingDirectory = File.GetFileParent(out)
    sh.Run(-1)
    wait for ffmpeg_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
End Sub

Sub TicksToTime (t As Long) As String
    Dim hours As Int = t / 1000 / 60 / 60
    Dim mins As Int = ((t / 1000) - (hours * 60 * 60)) / 60
    Dim secs As Int = ((t / 1000) - (hours * 60 * 60) - (mins * 60))
    Dim msecs As Float = ((t / 1000) - (hours * 60 * 60) - (mins * 60) - secs) * 1000
    Dim res As String = NumberFormat2(hours, 2, 0, 0, False) & ":" & NumberFormat2(mins, 2, 0, 0, False) & ":" & NumberFormat2(secs, 2, 0, 0, False) 

    Return res
End Sub
 
Last edited:
Upvote 0
Top