Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the size of "mvid" file #22

Open
johnhu456 opened this issue Jan 20, 2017 · 5 comments
Open

Reduce the size of "mvid" file #22

johnhu456 opened this issue Jan 20, 2017 · 5 comments

Comments

@johnhu456
Copy link

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?

@mdejong
Copy link
Owner

mdejong commented Jan 20, 2017

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.

@johnhu456
Copy link
Author

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!

@mdejong
Copy link
Owner

mdejong commented Jan 25, 2017

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
Copy link
Owner

mdejong commented Jan 25, 2017

TBD, include compression in AVAssetMixAlphaResourceLoader.

@johnhu456
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants