Is it possible to calculate/estimate the storage space a certain duration of .mp4 video files will take up? I have the resolution (eg. 4000 X 3000), the format (H.264 or H.265), the audio format (AAC) and the sample rate (41 000 Hz).
The MPEG4 video codec allows for a large ranges (easily a dynamic range of 50 for "useful" quality) of compression ratios for the same raw video material. The same applies to audio compressors.
And of course, there's simply video material that is easy to compress, so using the same type of quantization, motion prediction and frame structure, some videos will compress way better than other.
In fact, in many cases, you ask your encoder to aim for a target average bitrate even, so that you don't have to estimate anything, but set the amount of bits per second. If you have a technical necessity to know the bitrate beforehand, that would be the way to go!
Yes it is possible but this shall not conflict with what Marcus have already said.
Available codecs provide its users a number of options, such as a fixed quality irrespective of size or fixed size (bitrate) irrespective of the resulting quality, governed by the Rate-Distortion Theory.
If you choose the second option, which is the choice for bandwidth constrained channels, then the resulting bitrate (hence the size) of the compressed file will be known before hand; it will be forced (by buffer overflow feedback) to stay within the limit. However, the process is not smooth and you may not get a bit perfect size, especially in real-time applications.
On the other hand, if you allow multiple passes of encoders assuming all the data is available, then it's more likely to come up with matched target size, by adjusting the quality of certain blocks untill the target size is achieved.