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

[help]Video compression can not get compression progress 【flutter_video_compress: ^0.3.7+8】 #104

Open
lswd opened this issue May 2, 2021 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@lswd
Copy link

lswd commented May 2, 2021

Description

Video compression can not get compression progress

微信截图_20210502234246

Platform

Android

Code Example (if has)

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_video_compress/flutter_video_compress.dart';
import 'package:image_pickers/image_pickers.dart';

class TestVideoPage extends StatefulWidget {

@OverRide
_TestVideoPageState createState() => _TestVideoPageState();
}

class _TestVideoPageState extends State {

final _flutterVideoCompress = FlutterVideoCompress();
Subscription _subscription;

Image _thumbnailFileImage;
Image _gifFileImage;

MediaInfo _originalVideoInfo = MediaInfo(path: '');
MediaInfo _compressedVideoInfo = MediaInfo(path: '');
String _taskName;
double _progressState = 0;

final _loadingStreamCtrl = StreamController.broadcast();

@OverRide
void initState() {
// TODO: implement initState
super.initState();
_subscription =
_flutterVideoCompress.compressProgress$.subscribe((progress) {
debugPrint("progress----" + progress.toString());
setState(() {
_progressState = progress;
});
});
}

@OverRide
void dispose() {
super.dispose();
_subscription.unsubscribe();
_loadingStreamCtrl.close();
}

Future runFlutterVideoCompressMethods(String videoFile) async {
_loadingStreamCtrl.sink.add(true);

var _startDateTime = DateTime.now();
print('[Compressing Video] start');
_taskName = '[Compressing Video]';
final compressedVideoInfo = await _flutterVideoCompress.compressVideo(
  videoFile,
  quality: VideoQuality.DefaultQuality,
  deleteOrigin: false,
);
_taskName = null;
print(
    '[Compressing Video] done! ${DateTime
        .now()
        .difference(_startDateTime)
        .inSeconds}s');

_startDateTime = DateTime.now();

print('[Getting Thumbnail File] start');
final thumbnailFile = await _flutterVideoCompress
    .getThumbnailWithFile(videoFile, quality: 50);
print(
    '[Getting Thumbnail File] done! ${DateTime
        .now()
        .difference(_startDateTime)
        .inSeconds}s');

_startDateTime = DateTime.now();
print('[Getting Gif File] start');
_taskName = '[Getting Gif File]';
final gifFile = await _flutterVideoCompress
    .convertVideoToGif(videoFile, startTime: 0, duration: 5);
print(
    '[Getting Gif File] done! ${DateTime
        .now()
        .difference(_startDateTime)
        .inSeconds}s');
_taskName = null;

final videoInfo = await _flutterVideoCompress.getMediaInfo(videoFile);

setState(() {
  _thumbnailFileImage = Image.file(thumbnailFile);
  _gifFileImage = Image.file(gifFile);
  _originalVideoInfo = videoInfo;
  _compressedVideoInfo = compressedVideoInfo;
});
_loadingStreamCtrl.sink.add(false);

}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: OutlinedButton(
onPressed: () async {
List _listVideoPaths = await ImagePickers.pickerPaths(
galleryMode: GalleryMode.video,
selectCount: 1,
);
runFlutterVideoCompressMethods(_listVideoPaths[0].path);
},
child: Text("选择视频"),
),
),
);
}
}

Expected solution

Expect description of the solution

@lswd lswd added the help wanted Extra attention is needed label May 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant