VB.Net Stream/Port Image To FFmpgeg using Standard Input
Greetings,
hope all active member of this community are fine.
in my project i need to convert several image to video file.
Currently i have to first save the images to PC then use ffmpeg to read that images from the pc and convert it to movie.
But rather than save image to pc, i want to send image directly to ffmepg using StandardInput call. Ffmped does support that. but i don't know how to use that.
i have search internet a lot and all i found is getting output/response from ffmpeg using standarderror as ffmepg write to standerror instead of standardouput.
below link something similar to what i look for that that code don't work and also that use mp3 file instead of image/graphics.
Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input
I don't have time to play with it, but I would check out Peter Porter's thread http://www.vbforums.com/showthread.p...ghlight=ffmpeg
There are several versions of his code, by various people in the thread, so be sure to check out some of the later versions.
That code is capturing the screen and feeding the images to ffmpeg through standard input to output to a mpeg4 file.
In your case, you wouldn't need most of that since you are creating the images yourself.
I would look primarily at the following subs in Form1.vb (in at least some of the versions), Sub Record_Click and Sub BackgroundWorker1_DoWork.
The Record_Click sub sets up the process and args for ffmpeg with redirected standard input and output and then kicks of the BacgroundWorker1, which does the work of generating the images and sending them to the StandardInput.BaseStream in DoWork.
Hopefully that can give you some ideas to pull from for your code.
thanks a lot. wow! you also very good at searching.. because i have search for few days but nothing found similar. though i didn't check that yet. let me check
however thanks for your time
bye for now
take care
may Allah bless you
have a nice day
bye bye
Dim objBitmap As System.Drawing.Bitmap
Dim objFProcess As System.Diagnostics.Process
Dim objStream As System.IO.BinaryWriter
Dim strFiles() As String
Dim strEachFile As String
Dim intFile As Integer
Dim intFrame As Integer
Dim intFLoop As Integer
objFProcess = New System.Diagnostics.Process
objFProcess.StartInfo.FileName = "c:\ffmpeg.exe"
objFProcess.StartInfo.Arguments = "-r 1 -f image2pipe -i pipe:.bmp -pix_fmt yuv420p -crf 35.0 -vcodec libx264 -an -coder 1 -rc_lookahead 50 -threads 0 D:\test.mp4"
objFProcess.StartInfo.UseShellExecute = False
objFProcess.StartInfo.RedirectStandardInput = True
objFProcess.StartInfo.RedirectStandardOutput = True
objFProcess.StartInfo.RedirectStandardError = True
'objFProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
'objFProcess.StartInfo.CreateNoWindow = True
objFProcess.Start()
objStream = New System.IO.BinaryWriter(objFProcess.StandardInput.BaseStream)
strFiles = My.Computer.Clipboard.GetText().Split({System.Environment.NewLine}, StringSplitOptions.None)
intFrame = 0
intFile = 0
For Each strEachFile In strFiles
'MessageBox.Show(strEachFile)
intFile = intFile + 1
objBitmap = New System.Drawing.Bitmap(strEachFile)
For intFLoop = 0 To 24
intFrame = intFrame + 1
cmd1.Text = intFile.ToString & "-" & intFrame.ToString
My.Application.DoEvents()
objBitmap.Save(objStream.BaseStream, System.Drawing.Imaging.ImageFormat.Bmp) Rem this line give me below (attached) error :(
Next
objBitmap.Dispose()
Next
System.Threading.Thread.Sleep(3000)
objStream.Close()
MessageBox.Show("Done!")
'objFProcess.Kill()
And Here is the error:
FYI that sample form the link also raise same error
...FYI that sample form the link also raise same error
can you please help me out?
...
I don't suppose I can help. I've been busy this week so haven't tried anything until now. I just tried the example from the link you noted (only changed the CaptureDir string initialization), and it ran fine on my machine, capturing and creating an mpeg file. I could play it back using ffplay.
Since you're getting a GDI+ error, I assumed the error might have to do with objBitmap not having a valid bitmap, but if you get the same error with the example, then perhaps there is some hardware graphics issue or permissions issue (can't access the standard streams, perhaps).
Since the example code works fine for me, I don't know that there is a lot I can offer if it doesn't work for you.
The example would have been the baseline to build from, and if that doesn't work, then there is not a valid base to modify.
Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input
Originally Posted by passel
then perhaps there is some hardware graphics issue or permissions issue (can't access the standard streams, perhaps).
Since the example code works fine for me, I don't know that there is a lot I can offer if it doesn't work for you.
The example would have been the baseline to build from, and if that doesn't work, then there is not a valid base to modify.
thanks for coming back again for helping me out
however sir?
1? hardware graphics issue
ans: sir, if i change the save parameter to save to local file like "D:\test.bmp" it works just fine. Then do you still think it hardware issue?
2?permissions issue
ans: this is my developing pc not user pc. I am the admin and i have full access ever where
3.?can't access the standard streams
ans: that could be the issue but i have use same code as he did? i do need to do anything like open the stream or something else?
also sir, i have attached the stack trace of that report please see if that is helpful to you by any way..
Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input
No, doesn't help me. Of course it looks like that is your code, not the code from the example that is showing the exception.
If you run the example code, Video Capture Experiment 8 (after changing CaptureDir to a valid directory) and you get the same GDI+ error, then I have no idea. As I said, the example runs fine without modification on my machine, and if it doesn't on your machine then we can't blame the problem on changes you made implementing the code. It has to be a problem with something else, like a missing codec, or some other reason outside the code itself that is a problem.
Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input
Originally Posted by passel
No, doesn't help me. Of course it looks like that is your code, not the code from the example that is showing the exception.
If you run the example code, Video Capture Experiment 8 (after changing CaptureDir to a valid directory) and you get the same GDI+ error, then I have no idea. As I said, the example runs fine without modification on my machine, and if it doesn't on your machine then we can't blame the problem on changes you made implementing the code. It has to be a problem with something else, like a missing codec, or some other reason outside the code itself that is a problem.
oh!.. then how to find the issue? sir?
however.. i just tried to change the System.Drawing.Imaging.ImageFormat.bmp to System.Drawing.Imaging.ImageFormat.Jpeg. Then it just don't shows the error but it (ffmpeg) also don't create the output file and also nothing on the command line window
Do you think it could be the GDI+ library on my computer? and also for your information my OS is windows XP SP3 and vs is 2010 ultimate sp1
Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input
I have no idea. But if you change System.Drawing.Image.ImageFormat.bmp to jpeg, might you also have to change something in the ffmpeg line. I don't work with ffmpeg, but this bit "pipe:.bmp" seems like it might not apply to a jpeg stream. I don't know.