0

Is there any best practice to keep the size of the transcoded output file under a specific size?

I need to keep it under <100 MB but somehow I end up with big output files. The problem is that my (test) video file is 600kb while the generated output.wav 4MB. It is quite far away from what I expected.

var proc = new ffmpeg({
        source: file,
        nolog: false
    });
    proc.addInputOption('-acodec libopus');

    format = "wav";

    proc.addOptions([
        '-f ' + format,
        '-ab 192000',
        '-ar 16000',
        '-vn'
    ]);

This is how I gave the parameters to ffmpeg library. What parameters should I change here to reduce the size and keep the max. quality?

shamaleyte
  • 1,882
  • 3
  • 21
  • 38
  • 1
    Why are you outputting to a WAV file? This will use raw PCM audio, which is uncompressed, which is why you're getting such large output files. If you do not want to re-encode (i.e. not lose quality), couldn't you just copy the audio stream as-is and write that to a separate `.opus` file? – slhck Jul 03 '17 at 18:29
  • 1
    Further, I would really suggest you try to try these commands first on the command-line – then it'd be obvious what ffmpeg is doing, which codecs it's selecting, what the actual bitrate is, etc. Only when you're sure what the correct command is, translate it to fluent-ffmpeg. You will get better help asking about ffmpeg command-line questions than some libraries implementing it. (Unless the problem is about the library itself, obviously.) – slhck Jul 03 '17 at 18:38
  • @slchk, I am limited to have specific extensions; flac, wav, audio/webm audio/webm;codecs=opus, audio/webm;codecs=vorbis . I tried other output formats but the result is big anyways, as much as the wav file. ffmpeg -acodec libopus -i 2.webm -vn output1x.flac What else I should specify here to end up with a small file? – shamaleyte Jul 03 '17 at 18:49

1 Answers1

1

Using WAV as output format makes ffmpeg choose uncompressed PCM audio, where bitrate settings have no effect. You may want to read this post: What is a Codec (e.g. DivX?), and how does it differ from a File Format (e.g. MPG)?

If you were using the command line, you'd just have to copy the audio stream to an output file without touching the bitstream (-c:a copy):

ffmpeg -i input.webm -vn -c:a copy output.opus

In fluent-ffmpeg, I guess this is the way to go:

ffmpeg('input.webm')
  .addInputOption('-acodec libopus')
  .noVideo()
  .audioCodec('copy')
  .output('output.opus')

You can also webm as output format by writing to output.webm.

slhck
  • 36,575
  • 28
  • 148
  • 201
  • @slchk, thanks again for the reply. But the generated opus file always starts from 4rd or 5th seconds when I play it. It seems like that the first seconds are lost. Any idea why it happens? Please check this new question I created for this problem. https://stackoverflow.com/questions/45063388/transcode-to-opus-by-fluent-ffmpeg-or-ffmpeg-from-command-line – shamaleyte Jul 12 '17 at 16:43