Results 1 to 6 of 6

Thread: MP3 ripping from video with ffmpeg

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    64

    MP3 ripping from video with ffmpeg

    Yo everyone.
    Its been a while since I posted here as i've moved away from VB for the last few months. Anyway, seen as the support is so good here, I was wondering if anybody here could help me with a small issue i'm having with ripping MP3 files out of a MP4 video using ffmpeg.

    Here's my code so far, but for some reason it doesn't want to work for me
    Code:
    Imports System.IO
    
    Public Class Form1
        Dim process As New Process
    
    
    
        Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    
            With process.StartInfo
                .FileName = "ffmpeg.exe"
                .Arguments = "ffmpeg.exe -i " & CurDir() & "/test.mp4" & " -ab 128k " & CurDir() & "/test.mp3"
                ' Must be set to false in order to redirect output
                .UseShellExecute = False
                ' ffmpeg uses StandardError instead of StandardOutput
                .RedirectStandardError = True
                ' Uncomment this when code is working to hide the DOS window
                '.CreateNoWindow = True
            End With
            process.Start()
            Dim outputReader As StreamReader = process.StandardError
            Dim output As String
    
            While Not process.HasExited
                output = outputReader.ReadLine()
                BackgroundWorker1.ReportProgress(0, output)
                Threading.Thread.Sleep(500)
            End While
    
        End Sub
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            ' Enable the ability to stop ffmpeg
            BackgroundWorker1.WorkerSupportsCancellation = True
            ' Lets you get ffmpeg output info
            BackgroundWorker1.WorkerReportsProgress = True
            ' Start the background worker. This method prevents form from locking
            BackgroundWorker1.RunWorkerAsync()
        End Sub
    
        Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
            ' Show the output in a RichTextbox
            Dim output As String = e.UserState.ToString
            RichTextBox1.Text &= output & Environment.NewLine
            RichTextBox1.SelectionStart = RichTextBox1.Text.Length
    
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            'cancel
            process.Kill()
        End Sub
    
        
    End Class
    If I open up a command prompt and type:

    Code:
    ffmpeg.exe -i  test.mp4 -ab 128k test.mp3
    The conversion works fine.

    Quite confused with this one, and spent hours trying to get it to work.
    Any help would be greatly appreciated.
    If anyone would like me to upload the whole project, including "ffmpeg.exe", i'll gladly do that (The upload will be about 30mb though).
    Thanks all

  2. #2
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Re: MP3 ripping from video with ffmpeg

    You might want to look at FFMpeg wrapper, here;
    http://vbffmpegwrapper.codeplex.com/

    If i recall right when i looked round the source code for it there was the ability to encode video to audio/rip audio.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    64

    Re: MP3 ripping from video with ffmpeg

    Hey DragonRose, thanks for the reply
    I've created a new test project and referenced FFlib.dll, however i get warnings and errors:

    Code:
    Warning	1	Resolved file has a bad image, no metadata, or is otherwise inaccessible. Could not load file or assembly 'C:\Users\JJMPSP\Desktop\Desktop\dll\EncoderSample\EncoderSample\bin\Debug\FFLib.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
    Code:
    Warning	2	The referenced component 'FFLib' could not be found.
    Code:
    Error	3	Type 'FFLib.Encoder' is not defined.	C:\Users\JJMPSP\AppData\Local\Temporary Projects\encoder sample\Form1.vb	3	39	encoder sample
    Hmm
    Any ideas ?

    Edit: I'm using Visual Studio 2008 if that makes any difference.

  4. #4
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Re: MP3 ripping from video with ffmpeg

    You need to copy the 'resource' folder from the source code to the projects thread aswell, and the code given on the main page is completely wrong. I posted the correct code as a function a while back in the disscusions section there, check it out;

    http://vbffmpegwrapper.codeplex.com/discussions/225285

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    64

    Re: MP3 ripping from video with ffmpeg

    Thanks for the fast reply. (+rep)
    I just tried using your code and adding the resources, I still get the same errors and warnings though
    I've also tried re-building the project multiple times, but still having problems





    Last edited by JJMPSP; Mar 22nd, 2011 at 10:12 AM.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    64

    Re: MP3 ripping from video with ffmpeg

    Update:
    I've finally got my original code working
    By looking into the way ffmpeg works a bit more, I found out that I needed double quotes on filenames.

    Here's the completed code if anyone would like it:

    Code:
    Imports System.IO
    
    Public Class Form1
        Dim process As New Process
    
    
    
        Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    
            With process.StartInfo
                .FileName = CurDir() & "\ffmpeg.exe"
                .Arguments = "-i ""C:\Users\JJMPSP's Desktop\Documents\Visual Studio 2008\Projects\ffmpeg GUI\ffmpeg GUI\bin\Debug\test song.mp4"" -acodec libmp3lame -ab 128k -ac 2 -ar 44100 ""C:\Users\JJMPSP's Desktop\Desktop\song test.mp3"""
                ' Must be set to false in order to redirect output
                .UseShellExecute = False
                ' ffmpeg uses StandardError instead of StandardOutput
                .RedirectStandardError = True
                ' Uncomment this when code is working to hide the DOS window
                .CreateNoWindow = True
            End With
            process.Start()
            Dim outputReader As StreamReader = process.StandardError
            Dim output As String
    
            While Not process.HasExited
                output = outputReader.ReadLine()
                BackgroundWorker1.ReportProgress(0, output)
                Threading.Thread.Sleep(500)
            End While
    
        End Sub
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            ' Enable the ability to stop ffmpeg
            BackgroundWorker1.WorkerSupportsCancellation = True
            ' Lets you get ffmpeg output info
            BackgroundWorker1.WorkerReportsProgress = True
            ' Start the background worker. This method prevents form from locking
            BackgroundWorker1.RunWorkerAsync()
        End Sub
    
        Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
            ' Show the output in a RichTextbox
            Dim output As String = e.UserState.ToString
            RichTextBox1.Text &= output & Environment.NewLine
            RichTextBox1.SelectionStart = RichTextBox1.Text.Length
    
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            'cancel
            process.Kill()
        End Sub
    
        
    End Class
    Thanks DragonRose for your input on this thread anyway, I have +rep'd you for your efforts

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