Sometimes, theoretically all works... but there are times (most)... that all going at different direction... so i am lowering the bar of the local/streaming/media...
to show for example a video as jpeg frames...
Here is my code (until now) - but there are some problems... according this:
the SOI is a 2 byte 0xFF,0xD8 and the EOI is a 2byte of 0xFF,0xD9...
but when i am trying to extract those frame a jpeg - i am taking only 1Kb... to 2kb files... and a bad jpeg.. showing...
Ofcourse this not work as i wanted... sometimes i am getting the first 10 pixels of a top frame....
but most i got: this: WARNING: Corrupt JPEG data: premature end of data segment
ps: some will tell why not using javacv-bin (with some java inline - is someway easy)... but with ffmpeg.exe i feel that i have more control... and i am clear to end users for future use in my apps that this way of capturing/streaming/playing is a 3rd tool... not mine
to show for example a video as jpeg frames...
Here is my code (until now) - but there are some problems... according this:
JPEG File Interchange Format - Wikipedia
en.wikipedia.org
but when i am trying to extract those frame a jpeg - i am taking only 1Kb... to 2kb files... and a bad jpeg.. showing...
B4X:
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private Button1 As B4XView
Dim js As Shell
Private Button2 As Button
Dim check1for As B4XBytesBuilder
Dim check2for As B4XBytesBuilder
Private ImageView1 As ImageView
Dim SOI(2) As Byte
Dim EOI(2) As Byte
Dim chunk As B4XBytesBuilder
Dim s1 As Int=0
Dim s11 As Int=0
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
SOI(0)=0xFF
SOI(1)=0xD8
EOI(0)=0xFF
EOI(1)=0xD9
chunk.Initialize
End Sub
Sub Button1_Click
Dim par As List
par.Initialize
par.Add("-i")
par.Add("1.avi")
par.Add("-c:v")
par.Add("mjpeg")
par.Add("-f")
par.Add("mjpeg")
par.Add("-preset")
par.Add("ultrafast")
par.Add("-q")
par.Add("20")
par.Add("-r")
par.Add("15")
par.Add("-maxrate")
par.Add("2M")
par.add("-bufsize")
par.Add("2M")
par.Add("-") 'This creating a pipe..
arun("ffmpeg.exe",par)
End Sub
Sub Button2_click
js.KillProcess
End Sub
Sub arun(app As String,params As List)
js.Initialize("js", app, params)
js.WorkingDirectory=File.dirapp
js.RunWithOutputEvents(-1)
End Sub
Sub js_StdOut (Buffer() As Byte, Length As Int)
chunk.Append2(Buffer,0,Length)
'If s1>-1 Then
s1=chunk.IndexOf2(SOI,s11)
If s1>-1 Then s11=s1'+1024
'End If
Dim s2 As Int = 0
If s1>-1 Then
Dim s2 As Int=chunk.IndexOf2(EOI,s1)
If s2>s1 Then
Dim aa As InputStream
aa.InitializeFromBytesArray(chunk.ToArray,s1,(s2-s1)-2)
Dim bmp As Image
bmp.Initialize2(aa)
ImageView1.SetImage(bmp)
chunk.Clear 'this ofcourse may be remove a following frame... but not the only prob....
Sleep(0)
s1=0
s11=0
End If
End If
end sub
Ofcourse this not work as i wanted... sometimes i am getting the first 10 pixels of a top frame....
but most i got: this: WARNING: Corrupt JPEG data: premature end of data segment
ps: some will tell why not using javacv-bin (with some java inline - is someway easy)... but with ffmpeg.exe i feel that i have more control... and i am clear to end users for future use in my apps that this way of capturing/streaming/playing is a 3rd tool... not mine
Last edited: