Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
1st January 2011, 16:15 | #1 | Link |
Registered User
Join Date: Oct 2002
Location: France
Posts: 2,309
|
How compute m2ts result files size ?
If i have the following :
A raw h264 video file of size V1. 2 audio files of sizes A1 and A2. Does someone know the formula wich will give me, with an accuracy of around 1MB for files of around 5GB, the size of the resulting m2ts muxed file ? (Blu-Ray authoring). If others parameters like bitrate/frame are to be used, notify me. Thanks. |
1st January 2011, 17:32 | #3 | Link |
Registered User
Join Date: Oct 2001
Location: Germany
Posts: 7,259
|
here's what I use in Hybrid atm:
Code:
qint64 CalculationService::m2tsVideoOverhead(const qint64 completeVideo, const int frameCount, \ const bool audioHandling) { qint64 videoOverhead = 0; qint64 videoSize = completeVideo; //videoOverhead+generalOverhead+rawVideo if (!audioHandling) { videoOverhead = frameCount*263 + 9412; } videoSize -= videoOverhead; int packageSize = 192; int packageFill = 184; //of 192 sendMessage(MYDEBUG, "packageFill", packageFill); qint64 packageCount = videoSize/packageSize+1; qint64 packageOverhead = packageCount*(packageSize-packageFill); videoOverhead += packageOverhead; return videoOverhead; } qint64 CalculationService::m2tsAudioOverhead(const bool videohandling, const int frameCount, const double framerate, const QString format, const qint64 rawsize) { int blocksize = 80; if (format == "ac3" || format.contains("true") || format == "dts" || format == "dts-hd" || format == "pcm") { blocksize = 907; } qint64 audioOverhead = qint64((2*blocksize)/180.0 * 8.0 + 17.0 +0.5) * ((qint64)(rawsize*1.0/(blocksize*1.0)+0.5)); if (videohandling) { double length = frameCount/framerate; double audiobitrate = rawsize/length; audioOverhead += frameCount*(262+(audiobitrate/184+1)) + 9412; } return audioOverhead; } Last edited by Selur; 1st January 2011 at 17:35. |
2nd January 2011, 11:42 | #4 | Link |
Registered User
Join Date: Oct 2002
Location: France
Posts: 2,309
|
Thanks for answers. I have no idea of how calculate them, it's why i'm asking.
I need it for using in oposite way : Knowing the size (or bitrate) of my audio and knowing my final avaible size, i need to know how exactly (or as precise as possible) how much data will be avaible for my raw video (=> what bitrate i can use). @Selar : What unit is the result size ? Last edited by jpsdr; 2nd January 2011 at 11:54. |
2nd January 2011, 12:50 | #5 | Link | ||
Registered User
Join Date: Oct 2001
Location: Germany
Posts: 7,259
|
Quote:
Quote:
sx264 and Hybrid both do it -> sx264 source code is unorganized, but iirc the X264Model::setBitrateForSizemethodis the method that does exactly what you want with the methods i quoted,.. Cu Selur |
||
16th January 2011, 16:41 | #6 | Link |
Registered User
Join Date: Oct 2002
Location: France
Posts: 2,309
|
I'm having trouble...
Note : 1k=1e3 1M=1e6 b=bit B=Byte. I have a video of 145037 frames at 23.976fps. Video bitrate is 5922kb, audio bitrate is 448kb (AC3). According the formulas, result file should be around 5122MB, with audio header around 119MB and video header around 187MB. Problem is that my result m2ts file with Scenarist is around 5111MB, so, 11MB smaller than expected ! Edit : Maybe i'm doing something wrong, but i don't see what... Last edited by jpsdr; 16th January 2011 at 20:25. |
16th January 2011, 20:23 | #8 | Link |
Registered User
Join Date: Oct 2002
Location: France
Posts: 2,309
|
Nice tool.
Unfortunately, not fitted to my needs, as i often have severals m2ts files in my result Blu-Ray. Would have been perfect if i have only one m2ts file in result, but it's not always the case. @selur About the code you've provided, if there is several audio stream, do i need to add all the overhead audio of each stream, or is there something different again ? Last edited by jpsdr; 16th January 2011 at 20:30. |
16th January 2011, 20:39 | #9 | Link | |
Registered User
Join Date: Oct 2001
Location: Germany
Posts: 7,259
|
@poisondeathray: afaik AVCHDCalculator is a. closed source and b. doesn't allow custom target size.
But it would be interesting to know which formulas were used. Quote:
Sorry, should have posted that I know that the calculation isn't the best (most accurate) and everyone is welcome to post a tweak and correct it, it's the best I came up with the data I had. And at least I never encountered a problem with it predicting the file size to low or being really far of. (11MB on 5022MB doesn't seem that bad, to me since it's mainly educated guessing ) With multiaudio the formula will be more off. (assuming to large audio overhead) Since I personally normally don't encounter multi audio I never spend much time collecting statistical data and thinking about what happens when multi audio is present. (I was totally happy when I found a way to calculate single audio&video ) Cu Selur Last edited by Selur; 16th January 2011 at 20:43. |
|
21st January 2011, 00:33 | #11 | Link |
Registered User
Join Date: Oct 2002
Location: France
Posts: 2,309
|
I've made some test, and have following results :
Video is 147084 frames at 23.976fps encoded at 5923.32kb. Audio is AC3 at 448kb. Total overhead is 278286018 bytes. Audio is AC3 at 192kb. Total overhead is 290556610 bytes. Video is 119098 frames at 23.976fps encoded at 5921.61kb. Audio is AC3 at 448kb. Total overhead is 225322715 bytes. Audio is AC3 at 192kb. Total overhaed is 235254491 bytes. When audio bitrate goes low, overhead grows. Actualy, if bitrate audio b is in kilobit (1000 bits), for AC3 audio, one part of the calcul of audio overhead is : (2000*(C-b)/256)*time, time is duration is seconds. C would be 640 will not surprise me ! Actualy, for my specific cases, with my video bitrate : (2000*(640-audiobitrate)/256)*time + 1830*frames gives a good overhead estimation. If some are interesting to search using this as a base search... |
21st January 2011, 08:45 | #12 | Link | |||
Registered User
Join Date: Oct 2001
Location: Germany
Posts: 7,259
|
Quote:
1. raw video size (byte) 2. video frame count 3. raw audio size (byte) 4. average audio bitrate (bit/s) 5. length of video (assuming audio&video length is the same), video frame rate 6. size of video only muxed inside m2ts container (byte) 7. size of audio only muxed inside m2ts container (byte) 8. size of video&audio muxed together inside m2ts container (byte) this would allow to use them as control values for later tests. Quote:
1. since the package size of m2ts is 192 it would kind of make sense to see it appear somewhere in the formula 2. some value that is assumed as average package fill would make sense 3. calculation video overhead by only looking at the frame count is definitly a dead end even if video bitrate is 1/5 of the current value, video overhead stays the same,.. video only overhead example: video frame count: 109645 frames video frame rate: 23.976 frames/second video length: frame count/frame rate = 4573.115 seconds raw video size: 8.472.672 Bytes video inside m2ts: 37.502.976 Bytes -> video overhead: 29.030.304 Bytes (2000*(640-audiobitrate)/256)*time + 1830*frames would be way of: (2000*(640-0)/256)*4573.115 + 1830*109645 = 5000*4573.115 + 1830*109645 = 22865575 + 1830*109645 = 22.865.575 + 200.650.350 = 223.515.925 I know you are probably aware that the video overhead formula wasn't good. I just wanted to show an extreme example,.. The main point is that a formula to calculate the overhead should not contain constants that fall from the heavens. Sadly I lost nearly all my muxing data collection a year ago in a hdd crash, only thing I found was some data about a single video-only source I reencoded with different bitrates: Quote:
Cu Selur Ps.: aiming for a formula that only works if the target size is i.e. 10GB, DVD9, DVD5 or something like that is a thing that would probably be easier, but will probably not result in a all around working formula Last edited by Selur; 21st January 2011 at 08:48. |
|||
21st January 2011, 10:36 | #13 | Link |
Registered User
Join Date: Oct 2002
Location: France
Posts: 2,309
|
As i said, it's for one AC3 audio track, so, in AC3 case, bitrate is not more than 640kb i think, and my actual formula is for now only with the video bitrate i've used.
I'll add later the others files size informations. I'm currently doing a 10000kb video to try to have video track at different bitrate, to identify video parameter. I'll also do some tests with 640kb AC3 audio track. I'm not interested in audio or video only, because they may have different way of doing things, and Scenarist will probably not allow me a track without video stream. |
21st January 2011, 18:16 | #14 | Link |
Registered User
Join Date: Oct 2002
Location: France
Posts: 2,309
|
Video1 : 147084 frames @23.976fps raw h264 encoded (x264) at 5923.32kb. .264 file size : 4542170174 bytes.
Video2 : 119098 frames @23.976fps raw h264 encoded (x264) at 5921.61kb. .264 file size : 3676859941 bytes. Audio 1.1 (for video 1) : AC3 encoded at 448kb. AC3 file size : 343538944 bytes. Audio 1.2 (for video 1) : AC3 encoded at 192kb. AC3 file size : 147230976 bytes. Audio 2.1 (for video 2) : AC3 encoded at 448kb. AC3 file size : 278170368 bytes. Audio 2.2 (for video 2) : AC3 encoded at 192kb. AC3 file size : 119215872 bytes. M2TS files : (1) : Video1 + audio1.1 => 5163995136 bytes. (1.1) : Video1 + 2xaudio1.1 => 5532076032 bytes. (2) : Video2 + audio2.1 => 4180353024 bytes. (2.1) : Video2 + 2xaudio2.1 => 4478392320 bytes. (3) : Video1 + audio1.2 => 4979957760 bytes. (3.1) : Video1 + 2xaudio1.2 => 5163995136 bytes. (4) : Video2 + audio 2.2 => 4031330304 bytes. (4.1) : Video2 + 2xaudio2.2 => 4180353024 bytes. Last edited by jpsdr; 22nd January 2011 at 17:43. |
22nd January 2011, 09:31 | #15 | Link |
Registered User
Join Date: Oct 2002
Location: France
Posts: 2,309
|
Video3 : Video1 encoded at 9971,98kb. .264 file size : 7646802893 bytes.
Video4 : Video2 encoded at 9998,64kb. .264 file size : 6208381775 bytes. Audio 1.3 (for video1) : AC3 encoded at 640kb. AC3 file size : 490769920 bytes. Audio 2.3 (for video2) : AC3 encoded at 640kb. AC3 file size : 397386240 bytes. M2TS files : (5) : Video3 + audio 1.1 => 8403603456 bytes. (6) : Video4 + audio 2.1 => 6821910528 bytes. (7) : Video1 + audio 1.3 => 5348038656 bytes. (8) : Video2 + audio 2.3 => 4329375744 bytes. Now, i think there is globaly enough relevant data to create a good estimation of video/audio overhead in case of AC3 audio file. Last edited by jpsdr; 22nd January 2011 at 17:44. |
22nd January 2011, 17:42 | #16 | Link |
Registered User
Join Date: Oct 2002
Location: France
Posts: 2,309
|
For now, i think, for video + audio :
Video overhead is rawvideosize/23 (or rawvideosize/23 + constant). For at least 448kb and 192kb, audio overhead is : "something"-rawaudiosize/16. Still not found what this "something" is for audio. For 192kb and 448kb, a working formula is (1000*(2134-bitrate)/128)*time, but it's only considering if the "something" is directly linked to the time. |
22nd January 2011, 20:38 | #17 | Link |
Registered User
Join Date: Oct 2002
Location: France
Posts: 2,309
|
According the data, i have for now the following formulas :
Video overhead = rawvideosize/23 Audio : AC3 192kb & 448kb : K=696*frames (or K=29*fps*frames, i don't know, only tested with 23.976fps video) Audio overhead = K-rawaudiosize/16. I don't know for which bitrate value formula switch. AC3 640kb : Audio overhead=800*frames. Last edited by jpsdr; 22nd January 2011 at 20:40. |
22nd January 2011, 20:58 | #18 | Link |
Registered User
Join Date: Oct 2001
Location: Germany
Posts: 7,259
|
may be also worth a try:
Code:
qint64 CalculationService::m2tsVideoOverhead(const qint64 completeVideo, const int frameCount, \ const bool audioHandling) { qint64 videoOverhead = 0; qint64 videoSize = completeVideo; //videoOverhead+generalOverhead+rawVideo if (!audioHandling) { videoOverhead = frameCount*263 + 9412; } videoSize -= videoOverhead; int packageSize = 192; int packageFill = 185; //of 192 sendMessage(MYDEBUG, "packageFill", packageFill); qint64 packageCount = videoSize/packageFill; qint64 packageOverhead = packageCount*(packageSize-packageFill); videoOverhead += packageOverhead; return videoOverhead; } qint64 CalculationService::m2tsAudioOverhead(const bool videohandling, const int frameCount, const double framerate, const QString format, const qint64 rawsize) { int blocksize = 80; if (format == "ac3" || format.contains("true") || format == "dts" || format == "dts-hd" || format == "pcm") { blocksize = 907; } double packageSize = 192.0; double packageFill = 182.0; qint64 audioOverhead = qint64((2*blocksize)/packageFill * 8.0 + 17.0 +0.5) \ * ((qint64)(rawsize*1.0/(blocksize*1.0)+0.5)); if (videohandling) { double length = frameCount/framerate; double audiobitrate = rawsize/length; audioOverhead += frameCount*(packagesize+(audiobitrate/packageFill+1)) + 9412; } return audioOverhead; } |
23rd January 2011, 08:28 | #19 | Link |
Registered User
Join Date: Oct 2002
Location: France
Posts: 2,309
|
I've allready try your formulas you give in the post #3, error is too big for me... Has i said, your formulas give around 11MB over a stream with subtitles ! Wich indeed result of around 30MB too much for a stream (subtitles was around 20MB), resulting in 360MB error for 12 streams (my need). Way too much out of the league for me, i'm looking for error <1MB (by stream) !
|
Thread Tools | Search this Thread |
Display Modes | |
|
|