Last updated:
0 purchases
flutter video compress
flutter_video_compress #
Generate a new path by compressed video, Choose to keep the source video or delete it by a parameter. Get video thumbnail from a video path and provide video information. Easy to deal with compressed video. Considering reduce application size is not using FFmpeg in IOS.
languages #
English 简体中文 日本語
Usage #
Installing
add flutter_video_compress as a dependency in your pubspec.yaml file.
dependencies:
flutter_video_compress: ^0.3.x
copied to clipboard
Create an instance
final _flutterVideoCompress = FlutterVideoCompress();
copied to clipboard
Get thumbnail from video path
final uint8list = await _flutterVideoCompress.getThumbnail(
file.path,
quality: 50, // default(100)
position: -1 // default(-1)
);
copied to clipboard
Get thumbnail file from video path
final thumbnailFile = await _flutterVideoCompress.getThumbnailWithFile(
file.path,
quality: 50, // default(100)
position: -1 // default(-1)
);
copied to clipboard
Convert video to a gif
final file = await _flutterVideoCompress.convertVideoToGif(
videoFile.path,
startTime: 0, // default(0)
duration: 5, // default(-1)
// endTime: -1 // default(-1)
);
debugPrint(file.path);
copied to clipboard
Get media information
only support video now.
final info = await _flutterVideoCompress.getMediaInfo(file.path);
debugPrint(info.toJson().toString());
copied to clipboard
Compression Video
Compatible with IOS, Android and Web after compression.
final info = await _flutterVideoCompress.compressVideo(
file.path,
quality: VideoQuality.DefaultQuality, // default(VideoQuality.DefaultQuality)
deleteOrigin: false, // default(false)
);
debugPrint(info.toJson().toString());
copied to clipboard
Check Compressing state
_flutterVideoCompress.isCompressing
copied to clipboard
Stop compression
Will print InterruptedException in android, but not affect to use.
await _flutterVideoCompress.cancelCompression()
copied to clipboard
delete all cache files
Delete all files generated by this will delete all files located at 'flutter_video_compress', you shoule ought to know what are you doing.
await _flutterVideoCompress.deleteAllCache()
copied to clipboard
Subscribe the compression progress steam
class ... extends State<MyApp> {
Subscription _subscription;
@override
void initState() {
super.initState();
_subscription =
_flutterVideoCompress.compressProgress$.subscribe((progress) {
debugPrint('progress: $progress');
});
}
@override
void dispose() {
super.dispose();
_subscription.unsubscribe();
}
}
copied to clipboard
Methods #
Functions
Parameters
Description
Returns
getThumbnail
String path[video path], int quality(1-100)[thumbnail quality], int position[Get a thumbnail from video position]
get thumbnail from video path
Future<Uint8List>
getThumbnailWithFile
String path[video path], int quality(1-100)[thumbnail quality], int position[Get a thumbnail from video position]
get thumbnail file from video path
Future<File>
convertVideoToGif
String path[video path], int startTime(from 0 start)[convert video to gif start time], int endTime[convert video to gif end time], int duration[convert video to gif duration from start time]
convert video to gif from video path
Future<File>
getMediaInfo
String path[video path]
get media information from video path
Future<MediaInfo>
compressVideo
String path[video path], VideoQuality quality[compressed video quality], bool deleteOrigin[delete the origin video], int startTime[compression video start time], int duration[compression video duration from start time], bool includeAudio[is include audio in compressed video], int frameRate[compressed video frame rate]
compression video at origin video path
Future<MediaInfo>
cancelCompression
none
cancel compressing
Future<void>
deleteAllCache
none
Delete all files generated by 'flutter_video_compress' will delete all files located at 'flutter_video_compress'
Future<bool>
Subscriptions #
Subscriptions
Description
Stream
compressProgress$
Subscribe the compression progress steam
double progress
Notice #
If your application is significantly larger after using the plugin, you can reduce the application size in the following way:
exclude x86 related files (./assets)
This library not use ffprobe, only used ffmpeg, but the application still has ffprobe, so you will need to exclude (asssets/arm or assets/x86)
add this config in build.gradle:
Don't use ignoreAssetsPattern "!x86" in debug mode, will crash on the simulator
android {
...
// Reduce your application size with this configuration
aaptOptions {
ignoreAssetsPattern "!x86:!*ffprobe"
}
buildTypes {
...
}
copied to clipboard
look detail
If your application is 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"
}
}
}
}
}
copied to clipboard
If your application not support swift, you need to add the following code in ios/Podfile.
target 'Runner' do
use_frameworks! # <--- add this
...
end
copied to clipboard
look detail
If your application never used a swift plugin before, maybe you would meet the error, you need to add the following code in ios/Podfile.
The 'Pods-Runner' target has transitive dependencies that include static binaries
pre_install do |installer|
# workaround for https://github.com/CocoaPods/CocoaPods/issues/3289
Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
end
copied to clipboard
look detail
if show error of Regift
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
copied to clipboard
TODO #
❌ Refactoring ios code to objective-c
Contribute #
Contributions are always welcome!
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.