B4J Question MP3 to wav conversion problem using Jave2 FFMPeg Library

zed

Active Member
Licensed User
Hello,
I am trying to convert an mp3 file to a wav file using the Jave2 FFMPeg Library by @Stevel05.
Dependencies are ok but it doesn't work.

Possible to get help. THANKS

Here is the log

Waiting for debugger to connect...
Program started.
Encoding complete false
error Exception : argument type mismatch


and the code
B4J:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region
#AdditionalJar: jave/jave-core-3.3.1
#AdditionalJar: jave/jave-nativebin-win64-3.3.1
#AdditionalJar: jave/slf4j-api-2.0.0
#AdditionalJar: jave/slf4j-nop-2.0.0

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    
    Dim SourceFile As String = "D:\test.mp3"
    Dim TargetFile As String = "D:\test.wav"
        
    Dim AudioAttrs1 As AudioAttributes
    AudioAttrs1.Initialize
    AudioAttrs1.SetCodec("pcm_s16le")
    
    Dim MO1 As MultimediaObject
    MO1.Initialize
    MO1.Create(SourceFile,"")
    
    Dim EncAttrs1 As EncodingAttributes
    EncAttrs1.Initialize
    EncAttrs1.SetOutputFormat("wav")
    EncAttrs1.SetAudioAttributes(AudioAttrs1)
'       
    Dim Enc1 As Encoder
    Enc1.Initialize(Me,"Enc")
    Enc1.Encode3(MO1,TargetFile,"",EncAttrs1)
    
    Try
        Wait For Enc_Complete(EndedOK As Boolean, Error As String)
        Log("Encoding complete " & EndedOK)
        Log("error "& Error)
    Catch
        Log("Encoding failed " & LastException)
        
    End Try
End Sub

Private Sub Enc_Event(MethodName As String,Args() As Object)
    
    Select MethodName
        Case "message"
            Log("Message " & Args(0))
        Case "progress"
            Log("Progress " & Args(0))
        Case "sourceinfo"
            Log("Source Info " & Args(0))
    End Select
End Sub
 

Attachments

  • FFMpeg-Threaded-Test.zip
    2.4 KB · Views: 159

Daestrum

Expert
Licensed User
Longtime User
It's probably not the cause, but you define the encoder as Enc1, but wait for Enc_Complete also Enc_Event. Should they not be Enc1 ?
 
Upvote 0

zed

Active Member
Licensed User
Exact. Stupid mistake.:rolleyes:
I have no more log, but no output wav file.
That's another problem
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I would try putting a file in this line where you just have ""
B4X:
Enc1.Encode3(MO1,TargetFile,"",EncAttrs1)

The original java code was encode(srceFile, destFile, attributes)
maybe it just needs a filename or another file object there.
 
Upvote 0

zed

Active Member
Licensed User
This is the original code.
Enc1.Encode3(MO1,TargetFile,"",EncAttrs1)
I tried putting the folder and the file separately, but it doesn't change anything.
I also tried with other file formats and no output file.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Try running it in release mode. Anything that uses threads cannot be used in debug mode.
 
  • Like
Reactions: zed
Upvote 0
Solution
Top