flutter_video_compress
Compressed video generates a new path, keep the source video or delete it. provide get video information or get thumbnail of the video file.
Before Android installation
If your program not enabled AndroidX
, you will need to add the following code to the last line of the android/build.gradle
file.
rootProject.allprojects {
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'androidx.core' && !details.requested.name.contains('androidx')) {
details.useVersion "1.0.1"
}
}
}
}
}
Before IOS installation
If your program not support swift, you need to add the following code in ios/Podfile
.detail
target 'Runner' do
use_frameworks! # <--- add this
...
end
# -----insert code start-----
pre_install do |installer|
installer.analysis_result.specifications.each do |s|
if s.name == 'Regift'
s.swift_version = '4.0'
# elsif s.name == 'other-Plugin'
# s.swift_version = '5.0'
# else
# s.swift_version = '4.0'
end
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
# -----insert code end-----
Methods
function | parameter | description | return |
---|---|---|---|
getThumbnail | String [path] , int [quality] (1-100), int [position] |
get thumbnail from [path] |
[Future<Uint8List>] |
getThumbnailWithFile | String [path] , int [quality] (1-100), int [position] |
get thumbnail file from [path] |
[Future<File>] |
convertVideoToGif | String [path] , int [startTime] (from 0 start), int [endTime] , int [duration] |
converts provided video to a gif | [Future<File>] |
getMediaInfo | String [path] |
get media information from [path] |
[Future<MediaInfo>] |
compressVideo | String [path] , VideoQuality [quality] , bool [deleteOrigin] , int [startTime] , int [duration] , bool [includeAudio] , bool [frameRate] |
compress video at [path] |
[Future<MediaInfo>] |
cancelCompression | [none] |
stop compressing the file that is currently being compressed. | [Future<void>] |
deleteAllCache | [none] |
Delete the cache, please do not put other things in the folder of this plugin, it will be cleared | [Future<bool>] |
Subscriptions
subscription | description | stream |
---|---|---|
compressProgress$ | Subscribe the conversion progress steam | double [progress] |
Usage
Installing
add flutter_video_compress as a dependency in your pubspec.yaml file.
dependencies:
flutter_video_compress: ^0.3.x
Creating instance.
final _flutterVideoCompress = FlutterVideoCompress();
Get thumbnail by video file
final uint8list = await _flutterVideoCompress.getThumbnail(
file.path,
quality: 50,
);
Get thumbnail file by video file
final thumbnailFile = await _flutterVideoCompress.getThumbnailWithFile(
file.path,
quality: 50,
);
Converts provided video to a gif.
final file = await _flutterVideoCompress.convertVideoToGif(
videoFile.path,
startTime: 0,
duration: 5,
);
print(file.path);
Get media information
Currently only supports video
final info = await _flutterVideoCompress.getMediaInfo(file.path);
print(info.toJson());
Compression Video
Compatible with ios in Android and web after compression
final info = await _flutterVideoCompress.compressVideo(
file.path,
deleteOrigin: true,
);
print(info.toJson());
Check Compressing state
_flutterVideoCompress.isCompressing
Stop compression
Android will print InterruptedException, but does not affect the use
await _flutterVideoCompress.cancelCompression()
delete all cache file
Delete all the files generated by this plugin, I think you ought to know what you are doing.
await _flutterVideoCompress.deleteAllCache()
Subscribe the conversion progress steam
class ... extends State<MyApp> {
Subscription _subscription;
@override
void initState() {
super.initState();
_subscription =
_flutterVideoCompress.compressProgress$.subscribe((progress) {
print('progress: $progress');
});
}
@override
void dispose() {
super.dispose();
_subscription.unsubscribe();
}
}
Notice
If you find that the size of the apk is significantly increased after importing the plugin, it may be due to the following reasons:
-
exclude
x86
related files (./assets
) -
This library does not use
ffprobe
, only usesffmpeg
, but the application still hasffprobe
, so it needs to be excluded (asssets/arm
orassets/x86
)
add this config in build.gradle
:
- Do not use
ignoreAssetsPattern "!x86"
in debug mode, will crash on the simulator
android {
...
// Reduce your application size with this configuration
aaptOptions {
ignoreAssetsPattern "!x86:!*ffprobe"
}
buildTypes {
...
}