Q: File is over too much over/under target

A: Videos are very different, as is using a different speed preset.
Bitrate calculation is not perfect, but it will redo audio at 2kbps increments up to 20 times or when it matches target, whichever comes first.
If it's still not enough, use the override target.
Like let's say you end up with a 3.75MB file and you wanted a 4MB file, set the target override to something like maybe 4.4
I know the difference is .25 so you'd want to try that, but that is after it has already tried to overcompensate by changing audio bitrate, ideal scenario you do that as little as possible. Just make sure it doesn't go the other way too much either.
Keep in mind that if you alter any of the ffmpeg commands, the bitrate calculation might behave differently, like -cpu-used 0 vs 4 can have wildly different end result in filesize.


Q: Difference between 8 and 10 bit?

A: 10 bit has slighty higher quality at the same bitrate, however ancient devices aswell as phones struggle to play it in browser.


Q: It is so slow, how can I speed it up?

A: You've got 2 choices.
1: Make a copy of the entire setup to run multiple tasks at once.
2: Edit the python files and change -cpu-used 0 to something like 2.
Though keep in mind that changing the encode speed means you will get less quality for the same bitrate.


Q: Can I push more out of it?

A: If you want to get the absolute most out of it, nothing beats completely manual work, redoing it over and over.
However, you could technically set "-quality good" to "-quality best" (Make sure to edit it in both first and second pass).
But I would highly suggest against setting quality to best, it provides maybe a 0.1% increase in quality while making it take 10 times longer to encode.


Q: It does nothing.

A: Do you have python installed and added to PATH? And is python up to date? (I have only verified 3.10)
Do you have videos in the same folder as the python script?
Do you have ffmpeg and ffprobe in the same folder too?
Did you correctly enter the values when you ran the script?
Do not write for example 4MB when asked for target file size, write only 4.


Q: How do I trim the video?

A: Use LosslessCut
https://github.com/mifi/lossless-cut/releases
Unless you want more accurate cuts, then you can use the "Trim (Drag file onto me).py" script.
Either tell it at what timestamp you want to cut at for example 00:01:50 or 00:01:50.55
You can also tell it in seconds, for example 110 or 110.55
Though keep it mind that seconds is in relation to the cut start, so for example if you have cut start at 00:02:00 and cut end at 00:04:00 you'll have a 2 minute video, as you will if you have both cut start and end be 120 seconds, or if cut start is 00:02:00 and cut end is 120 seconds.
Keep in mind that using ffmpeg is not lossless, but I have set the CRF to 5 which is quite high to avoid as much possible detail loss as you can while still having reasonable filesize. Feel free to set to 0 if you have the space for it (Edit the script).
Try to use LosslessCut first (NO SMARTCUT, don't ever use that garbage), and if the accuracy it gives isn't enough, use my trim script. Simply drag and drop a file on it to use it.



Tips:
1: When downscaling, you can type for example -1:720 instead of 1280:720
-1 means it'll keep the same aspect ratio.
It can also go the other way like 1280:-1
It's really great if you can't remember resolutions so you can just do -1:720 -1:1080 -1:360 and such.

2: If you don't care that much about accuracy to getting close to a 3.99MB file, you can edit "lower_tolerance_mb=0.01" to whatever tolerance you want. Regardless it should not exceed 3.99MB (unless bitrate calculation is wonky (read top of this text file)).
If you also want it to try less to get within that tolerance, you could change how big of an increment it tries to change with to get within tolerance by editing BOTH values "current_audio_bitrate_kbps -= 2" and "current_audio_bitrate_kbps += 2"