published: bash to-limit.sh clip.mp4 25 out.mp4 command as run: bash ../to-limit.sh clip.mp4 25 out.mp4 exit=0 edge: main case, 76 s clip at 25 MB | video bitrate 2425 kbps, output 24384068 bytes published: wc -c < out.mp4 command as run: wc -c < out.mp4 exit=0 edge: byte count of the result | 24384068 published: ffprobe -v error -show_entries format=duration -of csv=p=0 out.mp4 command as run: ffprobe -v error -show_entries format=duration -of csv=p=0 out.mp4 exit=0 edge: duration of the result in seconds | 75.960000 test-only (not on the page): bash to-limit.sh clip.mp4 20 out20.mp4 command as run: bash ../to-limit.sh clip.mp4 20 out20.mp4 exit=0 edge: main case at 20 MB | video bitrate 1915 kbps, output 19556591 bytes test-only (not on the page): bash to-limit.sh clip.mp4 20 out720.mp4 720 command as run: bash ../to-limit.sh clip.mp4 20 out720.mp4 720 exit=0 edge: 20 MB with the optional 720 px height | video bitrate 1915 kbps, output 19482640 bytes test-only (not on the page): bash to-limit.sh missing.mp4 25 command as run: bash ../to-limit.sh missing.mp4 25 o1.mp4 exit=1 edge: missing file | input missing or empty: missing.mp4 test-only (not on the page): bash to-limit.sh empty.mp4 25 command as run: bash ../to-limit.sh empty.mp4 25 o2.mp4 exit=1 edge: empty file | input missing or empty: empty.mp4 test-only (not on the page): bash to-limit.sh clip.mp4 abc command as run: bash ../to-limit.sh clip.mp4 abc o3.mp4 exit=1 edge: limit not a number | limit must be a number of MB, for example 25 test-only (not on the page): bash to-limit.sh clip.mp4 0.2 command as run: bash ../to-limit.sh clip.mp4 0.2 o4.mp4 exit=1 edge: limit too small for the length | limit too small for 75.960000 s: video bitrate would be -107 kbps test-only (not on the page): bash to-limit.sh non-ASCII name command as run: bash ../to-limit.sh 'клип ü.mp4' 20 'вых ü.mp4'; wc -c < 'вых ü.mp4' exit=0 edge: non-ASCII file names, 19 s clip at 20 MB | video bitrate 8006 kbps, output 19361943 bytes 19361943 test-only (not on the page): bash crlf.sh (script saved with Windows line breaks) command as run: bash crlf.sh clip.mp4 25 o5.mp4 exit=2 edge: script saved with Windows line breaks | crlf.sh: line 4: set: pipefail : invalid option name test-only (not on the page): dos2unix equivalent then run command as run: sed 's/\r$//' crlf.sh > fixed.sh; bash fixed.sh ../out/source-19s.mp4 20 o6.mp4 exit=0 edge: Windows line breaks removed, runs again | video bitrate 8006 kbps, output 19361943 bytes test-only (not on the page): bash to-limit.sh small.mp4 25 (1,423,206-byte 720p clip, already under the limit; before the guard the output was 13,323,357 bytes) command as run: bash ../to-limit.sh small.mp4 25 o1.mp4 exit=0 edge: file already under the limit | the file is already under 25 MB: send the original, re-encoding would only enlarge it (no output file written) test-only (not on the page): bash to-limit.sh nodur.webm 5 (container without duration, ffprobe prints N/A) command as run: bash ../to-limit.sh nodur.webm 5 o2.mp4 exit=1 edge: no duration in the file | no duration in the file: remux it first, for example ffmpeg -i in.webm -c copy fixed.mkv test-only (not on the page): bash to-limit.sh noaudio.mp4 20 (19 s clip, audio track removed with -an -c:v copy) command as run: bash ../to-limit.sh noaudio.mp4 20 o3.mp4 exit=0 edge: clip without an audio track, 20 MB | video bitrate 8006 kbps, output 19056105 bytes (video-only) not handled (checked, not on the page as a feature): audio-only mp3 at limit 5 gives exit 234 with ffmpeg's "Output file does not contain any stream"; output name equal to input gives exit 234, ffmpeg "Output same.mp4 same as Input", input untouched; limit "1.2.3" is read as 1.2.