bramp / ffmpeg-cli-wrapper

Java wrapper around the FFmpeg command line tool
BSD 2-Clause "Simplified" License
1.67k stars 412 forks source link

Invalid data found when processing input [mp3float @ 0000000002e68940] Header missing #175

Open sarvesh opened 6 years ago

sarvesh commented 6 years ago

Hi All, Thanks for the great snippet. I really liked it. This is exactly what am looking for. But however am facing the issues with conversion from .wav to .mp3 Please find below the code snippet am using to convert

To Reproduce

public class Test {

    public  static void main(String[] args) throws Exception {

        FFmpeg ffmpeg = new FFmpeg("C:\\ffmpeg-20180824-d0b48a9-win64-static\\bin\\ffmpeg.exe");
        FFprobe ffprobe = new FFprobe("C:\\ffmpeg-20180824-d0b48a9-win64-static\\bin\\ffprobe.exe");
        FFmpegProbeResult in = ffprobe.probe("C:\\atmospace_jungle.wav"); //The audio file size 912KB. So i want the generated mp3 file should be half the size. Therefore the size is defined as size=500000(500KB)
        long size = 500000L;
        FFmpegBuilder builder = new FFmpegBuilder().setInput(in).setFormat("mp3").addOutput("audio.mp3").setTargetSize(size)
                .setAudioCodec("aac")
                .setAudioChannels(1)
                .setAudioSampleRate(48000)
                .setAudioBitRate(32768)
                .setStrict(FFmpegBuilder.Strict.EXPERIMENTAL)
                .done();
        FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
        executor.createJob(builder).run();
    }
}

Expected behavior A clear and concise description of what you expected to happen.

Version (if applicable):

Additional context Add any other context about the problem here.

bramp commented 6 years ago

The setInput(in).setFormat("mp3") line is forcing the input to be read as MP3. Move the setFormat after the addOutput.

Also you must likely don't need the setAudioCodec("aac") line, that would be seeing a different audio codec (and not using MP3).

sarvesh commented 6 years ago

I made the changes as suggested. But now ffProbe is failing with the below exception

image

And the sample code

 FFmpeg ffmpeg = new FFmpeg("C:\\Users\\snallami\\Downloads\\ffmpeg-20180824-d0b48a9-win64-static\\bin\\ffmpeg.exe");
        FFprobe ffprobe = new FFprobe("C:\\Users\\snallami\\Downloads\\ffmpeg-20180824-d0b48a9-win64-static\\bin\\ffprobe.exe");
        FFmpegProbeResult in = ffprobe.probe("C:\\atmospace_jungle.wav"); //The audio file size 912KB. So i want the generated mp3 file should be half the size. Therefore the size is defined as size=500000(500KB)
        long size = 500000L;
        FFmpegBuilder builder = new FFmpegBuilder().setInput(in).addOutput("audio.mp3").setFormat("mp3").setTargetSize(size)
                .setAudioChannels(1)
                .setAudioSampleRate(48000)
                .setAudioBitRate(32768)
                .setStrict(FFmpegBuilder.Strict.EXPERIMENTAL)
                .done();
        FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
        executor.createJob(builder).run();