AVAnimator icon indicating copy to clipboard operation
AVAnimator copied to clipboard

Reduce the size of "mvid" file

Open johnhu456 opened this issue 9 years ago • 5 comments

First of all thanks to AVAnimator such a good framework allows me to synthesize beautiful video. I used a video  with alpha chanel as a filter to cover an image, so users will always switch filter(video) to preview, But as a middleware generated file,mvid is too large, and some even reached 200MB. I have done zip compression, the size will be reduced to 1/10, but the speed in decompression is unstable, can not reach a  quick preview. Is there a better way to reduce the size of the "mvid" file?

johnhu456 avatar Jan 20 '17 03:01 johnhu456

There is a trade off, if the mvid is compressed then it takes longer to write and longer to read. But, there is already support for it built in. Take a look at the example named AVRender here http://www.modejong.com/AVAnimator/examples.html#AVRender , see how this class makes use of the define HAS_LIB_COMPRESSION_API. The resource loader classes support an optional BOOL named compressed, if this is set to TRUE and HAS_LIB_COMPRESSION_API for iOS 9 and newer then the MVID will be written as a compressed stream. This uses a lot less disk space but it uses more CPU and writing and reading the resource the first time.

mdejong avatar Jan 20 '17 03:01 mdejong

I am using AVAssetJoinAlphaResourceLoader to decompress a MP4 video to a "mvid" file , and the JoinAlphaResourceLoader does not have the "compressed" property. And I noticed that AVAssetJoinAlphaResourceLoader has 2 properties:

@property (nonatomic, retain) AVAsset2MvidResourceLoader *rgbLoader;
@property (nonatomic, retain) AVAsset2MvidResourceLoader *alphaLoader;

Sorry I did not find the place where these two properties specifically used in.

I tried to code like this :

            AVAssetJoinAlphaResourceLoader *resLoader = [AVAssetJoinAlphaResourceLoader aVAssetJoinAlphaResourceLoader];
            resLoader.movieRGBFilename = video.rgbVideoName;
            resLoader.movieAlphaFilename = video.alphaVideoName;
            resLoader.outPath = [AVFileUtil getTmpDirPath:[NSString stringWithFormat:@"%@",video.clipSource]];
            resLoader.alwaysGenerateAdler = TRUE;
            resLoader.serialLoading = TRUE;
#if defined(HAS_LIB_COMPRESSION_API)
            NSLog(@"compressed");
            resLoader.rgbLoader.compressed = YES;  
            resLoader.alphaLoader.compressed = YES; // I exposed them to the interface
#endif // HAS_LIB_COMPRESSION_API

But still don't work. Thanks again!

johnhu456 avatar Jan 20 '17 05:01 johnhu456

I have now updated the impl of AVAssetJoinAlphaResourceLoader to properly support a compressed flag. This results in about 10x smaller files. For example, the Explosion video in the kitty boom example goes from 186793 kB down to 20201 kB. (200 megs to 20 megs). Please give it a try and let me know is that is working for you. Also, if you would like to include AVAnimator in a commercial app then feel free to contact me about a license.

mdejong avatar Jan 25 '17 05:01 mdejong

TBD, include compression in AVAssetMixAlphaResourceLoader.

mdejong avatar Jan 25 '17 05:01 mdejong

I tried it. After compressed, the "mvid" file's size reduce to 22MB from 71MB. It do helped. At least the large size of "mvid" is no longer a big trouble. Thanks a lot.

johnhu456 avatar Jan 26 '17 08:01 johnhu456