ffmpeg-cli-wrapper icon indicating copy to clipboard operation
ffmpeg-cli-wrapper copied to clipboard

Format must be specified when using two-pass

Open 1995mars opened this issue 4 years ago • 1 comments

I want to reduce the quality of the mp3 files. but got an error: Format must be specified when using two-pass. Can You help me?

FFmpeg ffmpeg = new FFmpeg("D:\\ffmpeg\\bin\\ffmpeg.exe");
FFprobe ffprobe = new FFprobe("D:\\ffmpeg\\bin\\ffprobe.exe");
FFmpegProbeResult probeResult = ffprobe.probe("C:\\Users\\trant\\Desktop\\TestNextCloud\\input.mp3");\\
FFmpegBuilder builder = new FFmpegBuilder()

     .setInput(probeResult )     // Filename, or a FFmpegProbeResult
     .overrideOutputFiles(true) // Override the output if it exists
     .addOutput("output.mp3")   // Filename for the destination
     .setAudioChannels(1)         // Mono audio
     .setAudioSampleRate(48_000)  // at 48KHz
     .setAudioBitRate(65536)      // at 64 kbit/s
     .done();

FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
 // Run a one-pass encode
 executor.createJob(builder).run();

Version (if applicable):

  • OS: [e.g. Window]
  • Java Version [e.g. 8]

1995mars avatar Oct 15 '20 01:10 1995mars

This is two problems I always face

  • Target size, or video bitrate must be specified when using two-pass
  • Format must be specified when using two-pass

We're doing something wrong, but we don't know what. Why do I have to give a size or bitrate for the output can't it take the same as the input?

What does using two-pass mean? Which status are two-pass?

@bramp

suhakopan avatar May 09 '22 14:05 suhakopan

Two passes essentially run ffmpeg twice. The first pass is instrumented, and the output is discarded. The second pass is stored, but ffmpeg will use the data collected during the first pass, to make a file matching the requested target size while keeping a decent quality.

This works better than the single pass because if the input has a noisy scene (fast-moving, many things going on), it won't be able to deal with this unless the quality is dropped massively, which produces artefacts. In a two-pass scenario, FFmpeg will know in advance that such a scene is coming up and can already start reserving the bitrate for the very noisy scene.

Yes, it is theoretically possible to use the same bitrate or filesize as the input has. But then you could use cp input output.

TL;DR: Two pass is there to optimize for file size constraints and therefore needs to know what filesize to target.

Euklios avatar Mar 12 '24 17:03 Euklios