Results 1 to 14 of 14

Thread: VB.Net Stream/Port Image To FFmpgeg using Standard Input

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    340

    Question 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.

    Code:
    http://tiku.io/questions/3075356/convert-wma-stream-to-mp3-stream-with-c-sharp-and-ffmpeg
    can any one help me out, how to send image from picturebox/graphics object to ffmpeg one by one?

    thanks in advance

    best regards

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    340

    Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input

    Quote Originally Posted by passel View Post
    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, s
    wow! you also replied here..

    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

    best regards

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    340

    Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input

    Quote Originally Posted by passel View Post
    Hopefully that can give you some ideas to pull from for your code.
    thanks again for your cordial help.,

    sir, i have tried following example:
    Code:
    http://www.vbforums.com/showthread.php?727399-VB-NET-MPEG-4-Screen-recorder-Update-22-Nov-2014&p=4706111&viewfull=1#post4706111
    And this is my modified code:
    Code:
            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:
    Name:  Stream-Err1.png
Views: 1874
Size:  5.0 KB

    FYI that sample form the link also raise same error

    can you please help me out?

    thanks in advance....

    best regards

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    340

    Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input

    any help please?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    340

    Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input

    please any help?

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    340

    Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input

    hello?

  8. #8
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input

    Quote Originally Posted by Shohag_ifas View Post
    ...sir, i have tried following example:
    http://www.vbforums.com/showthread.p...=1#post4706111

    ...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.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    340

    Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input

    Quote Originally Posted by passel View Post
    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..

    Name:  Detail View.jpg
Views: 1146
Size:  40.1 KB

    once again thanks a lot for coming back

    best regards
    Attached Files Attached Files

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    340

    Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input

    also sir, when i mouse over the one basesteam it show following information, is that helpful?

    Name:  Message-1.jpg
Views: 1219
Size:  24.6 KB

    best regards

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    340

    Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input

    it seems both images get resized and hard to read that's why i have attached both images in a zip file if that helps....
    Attached Files Attached Files

  12. #12
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    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.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2009
    Posts
    340

    Re: VB.Net Stream/Port Image To FFmpgeg using Standard Input

    Quote Originally Posted by passel View Post
    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

    thanks again for your help..

    best regards

  14. #14
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width