0

I'm trying to encode the video in the same quality in the same format, but the output file is several times larger than the input file. Whyis it happens? I want to fix the encoding errors, but I can not do it without losing quality or increasing the file size. How to encode mp4 video without losing quality and increasing the size in Linux terminal?

I want to use the video to show online on my site. I'm using the call to ffmpeg below

ffmpeg input.mp4 -c:v libx264 -preset placebo -crf 0 -c:a aac -movflags faststart output.mp4

P.S. I will add here an example of errors. Even if I get here, I want to understand why ffmpeg increases my files. I encounter this regularly. This is the main question.

[h264 @ 0x56524c25dea0] Invalid NAL unit 0, skipping.
[h264 @ 0x56524c25dea0] error while decoding MB 32 2, bytestream -7
[h264 @ 0x56524c216260] Invalid NAL unit 0, skipping.
[h264 @ 0x56524c216260] error while decoding MB 46 16, bytestream -5
[h264 @ 0x56524c25dea0] Invalid NAL unit 8, skipping.
[h264 @ 0x56524c25dea0] error while decoding MB 36 1, bytestream -13
[aac @ 0x56524c1e6ea0] Number of bands (57) exceeds limit (44).
Error while decoding stream #0:1: Invalid data found when processing input
[aac @ 0x56524c1e6ea0] channel element 3.10 is not allocated
Error while decoding stream #0:1: Invalid data found when processing input
...
[aac @ 0x56524c1e6ea0] Number of bands (48) exceeds limit (44).
Error while decoding stream #0:1: Invalid data found when processing input
[aac @ 0x56524c1e6ea0] Error decoding AAC frame header.
Error while decoding stream #0:1: Error number -50531338 occurred
[aac @ 0x56524c1e6ea0] Input buffer exhausted before END element found
Error while decoding stream #0:1: Invalid data found when processing input
[aac @ 0x56524c1e6ea0] decode_pce: Input buffer exhausted before END element found
Error while decoding stream #0:1: Invalid data found when processing input
[null @ 0x56524c1e7d20] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 12351488 >= 12350464
[null @ 0x56524c1e7d20] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 12351488 >= 12351488
  • 1
    What are the "encoding errors" you're trying to fix? If size is most important, why not just leave it as-is, or lower the quality or shrink it? – Xen2050 Apr 20 '18 at 11:05
  • I added it. Then I have 2 questions: 1. Why ffmpeg increases file size for all cases with same quality? 2. How i can fix errors in my case? When I encode a file from one format to another, I get a side effect in the form of loss of quality or increase in size. I can accept this fact. But! If I encode a file in the same format in its original quality, why its size increases. What is this trick? ffmpeg says, here is the same file, but larger, since you do not have anything to occupy the hard drive. This not normal! – karpo518 Apr 20 '18 at 11:41
  • Don't add your actual question in comments to your question. If you change format it's expected that something changes as you likely need to reencode a file. Check the properties of both files to check whenever they're actually the same. – Seth Apr 20 '18 at 13:01
2

Why is the re-encoded video several times larger than the input file?

You are enforcing the encoder to use a lossless video quality setting with -crf 0. This causes your output video to be much larger than the input (assuming your input video is encoded with a lossy setting).

The lossless setting limits the compression capability of the encoder a lot. In simple terms: the high compression performance achieved by most video codecs such as x264 is through lossy video encoding, which tries to preserve "perceptual" quality while getting rid of perceptually insignificant data.

How to encode mp4 video without losing quality and increasing the file size?

Because of how lossy encoding works, it is literally impossible to re-encode a previously lossy-encoded video without any loss in quality unless you are using a lossless setting, which as you have encountered increases file size.

Rather, you could try experimenting with different -crf values to see what kind of quality/file size you get on your output video. With lossy encoding, it's always going to be a trade off between quality and file size. You can read up on encoding bitrate control here.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.