<p>The <code>fs</code> parameter will stop the encode once it hits its value. So, if the output hits the <code>10MB</code> mark while encoding the 15th second, then that's the duration of your output file.</p>

<p>If you want to make sure that the entire file is encoded but it doesn't cross the set target size, then use the bitrate method. To accommodate the muxing overhead and other data within the target size, set your video bitrate slightly lower by, say, 1-2%</p>

CC BY-SA 3.0
2015-12-27T12:31:26.687Z
2015-12-27T12:31:26.687Z
Gyan
<p>I want to encode a video, that has a length of 60 seconds, to a <strong>target or maximum size of 10 MB</strong>.</p>

<p>There are two approaches I know of. One is explained in the FFMPEG-Wiki, and the other one I found in the documentation. Unfortunately, I haven't found an explanation on when to use what method.</p>

<p>Is any of those methods recommended? If not, what are the upsides/downsides of each method?</p>

<p>1) Calculate and set Bitrate to match the length of the video as explained in the <a href="https://trac.ffmpeg.org/wiki/Encode/H.264#Two-PassExample" rel="noreferrer">ffmpeg-wiki</a></p>

<blockquote>
  <p>(10 MB * 8192 [converts MB to kilobits]) / 60 seconds = ~1365 kbits/s total bitrate
  1365k - 128k (desired audio bitrate) = 1237k video bitrate</p>
</blockquote>

<pre><code>ffmpeg -y -i input -c:v copy -preset medium -b:v 1237k -pass 1 -c:a copy -b:a 128k -f mp4 /dev/null &amp;&amp; \
ffmpeg -i input -c:v libx264 -preset medium -b:v 1237k -pass 2 -c:a libfdk_aac -b:a 128k output.mp4
</code></pre>

<p>2) Use the <code>-fs</code> <a href="https://ffmpeg.org/ffmpeg.html#Main-options" rel="noreferrer">parameter</a> and let ffmpeg figure it out.</p>

<pre><code>ffmpeg -i input -c:v copy -c:a copy -preset medium -crf 23 -fs 10485760 output.mp4
</code></pre>

CC BY-SA 3.0
2015-12-27T12:35:47.210Z
In your 1st example, the first step should also use `libx264` as `c:v`. In the `fs` example, you aren't transcoding the video, since `-c:v copy` is used. So, the `preset` and `crf` also don't have any effect.
Gyan
CC BY-SA 4.0
2019-03-20T23:59:57.067Z
This was helpful for me: https://stackoverflow.com/a/34547102/470749
Ryan
<ffmpeg>
How to limit file size with ffmpeg?
Daniel
# How to limit file size with ffmpeg?

(Asked by: username_0 on 2015-12-27)

I want to encode a video, that has a length of 60 seconds, to a target or maximum size of 10 MB.
There are two approaches I know of. One is explained in the FFMPEG-Wiki, and the other one I found in the documentation. Unfortunately, I haven't found an explanation on when to use what method.
Is any of those methods recommended? If not, what are the upsides/downsides of each method?
1) Calculate and set Bitrate to match the length of the video as explained in the ffmpeg-wiki

(10 MB * 8192 [converts MB to kilobits]) / 60 seconds = ~1365 kbits/s total bitrate
  1365k - 128k (desired audio bitrate) = 1237k video bitrate

ffmpeg -y -i input -c:v copy -preset medium -b:v 1237k -pass 1 -c:a copy -b:a 128k -f mp4 /dev/null && \
ffmpeg -i input -c:v libx264 -preset medium -b:v 1237k -pass 2 -c:a libfdk_aac -b:a 128k output.mp4

2) Use the -fs parameter and let ffmpeg figure it out.
ffmpeg -i input -c:v copy -c:a copy -preset medium -crf 23 -fs 10485760 output.mp4

**Tags:** ffmpeg

> **Comments:**
> **username_1**: In your 1st example, the first step should also use `libx264` as `c:v`. In the `fs` example, you aren't transcoding the video, since `-c:v copy` is used. So, the `preset` and `crf` also don't have any effect.  
> **username_2**: This was helpful for me: https://stackoverflow.com/a/34547102/470749  

---

## 1 answers

### Answer by username_1 on 2015-12-27. Score: 16 | Accepted answer

The `fs` parameter will stop the encode once it hits its value. So, if the output hits the `10MB` mark while encoding the 15th second, then that's the duration of your output file.

If you want to make sure that the entire file is encoded but it doesn't cross the set target size, then use the bitrate method. To accommodate the muxing overhead and other data within the target size, set your video bitrate slightly lower by, say, 1-2%


---

