Search code examples
ffmpegandroid-ffmpeg

Cannot convert .ogg file to .mp3 or other file formats


I am trying to convert ogg audio file to mp3 or other audio file formats that can be played in ios devices But ogg files are not being converted into other formats like mp3 and caf. I am testing the conversion in android device.

This is my ffmpeg command arguments:

Command: "ffmpeg -y -i $inputFilePath -c:a copy $outputFilePath"
Both input and output filenames were surrounded with quotations

 [-y, -i, /data/user/0/com.musicapp/files/composer_audios/testtt ogg file.ogg, -c:a, copy, /storage/emulated/0/Android/data/com.musicapp/files/ball.mp3]

When I try to convert into mp3 . this error is thrown:

 FFmpeg exited with rc: 1
 [mp3 @ 0x73f7b36a00] Invalid audio stream. Exactly one MP3 audio stream is required.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

When I try to convert into .caf file this error is thrown:


FFmpeg exited with rc: 1
 [caf @ 0x73f7b36a00] unsupported codec
 Could not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input

But if I try to convert mp3 file to formats like caf, mkv, mp4, no error is thrown.


Solution

  • Remove the -c:a copy option.

    About that option, the ffmpeg documentation says:

    a special value copy (output only) to indicate that the stream is not to be re-encoded.

    You are disabling encoding and suggesting ffmpeg to treat a vorbis stream as an mp3 stream.

    In your case you want to encode your input stream as a different output stream.