Skip to content

Commit

Permalink
Merge branch 'release/1.0.35'
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeUSeob committed Jun 22, 2023
2 parents 8896ec5 + f9d9511 commit ed39c37
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 189 deletions.
2 changes: 1 addition & 1 deletion lib/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestWidget extends StatelessWidget {
await _vmsdkWidget.initialize();
}

String testSetName = "oriented";
String testSetName = "set1_1080p";

final filelist = json.decode(
await rootBundle.loadString("assets/_test/mediajson-joined/$testSetName.json"));
Expand Down
184 changes: 3 additions & 181 deletions lib/vm_sdk/impl/ffmpeg_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ import '../types/types.dart';
import 'global_helper.dart';
import 'ffmpeg_manager.dart';

enum EImageScaleType {
zoomIn,
zoomOut,
leftToRight,
rightToLeft,
topToBottom,
bottomToTop
}

Resolution _resolution = Resolution(0, 0);
int _scaledVideoWidth = 0;
int _scaledVideoHeight = 0;
Expand All @@ -28,7 +19,6 @@ double _scaleFactor = 2 / 3.0;
double _minDurationFactor = 1 / _framerate;
const int _fadeDuration = 3;

List<EImageScaleType> _imageScaleType = [];
class RenderedData {
String absolutePath;
double duration;
Expand All @@ -38,18 +28,6 @@ class RenderedData {

final FFMpegManager _ffmpegManager = FFMpegManager();

EImageScaleType _getRandomImageScaleType() {
if (_imageScaleType.isEmpty) {
_imageScaleType.addAll(EImageScaleType.values);
}

int randIdx = (Random()).nextInt(_imageScaleType.length) % _imageScaleType.length;
EImageScaleType picked = _imageScaleType[randIdx];

_imageScaleType.removeAt(randIdx);
return picked;
}

String _getTransposeFilter(int orientation) {
// switch (orientation) {
// case 90: return "transpose=1,";
Expand Down Expand Up @@ -105,30 +83,10 @@ Future<RenderedData> clipRender(
// INPUT IMAGE & VIDEO //
/////////////////////////
if (mediaData.type == EMediaType.image) {
final String preProcessedPath = "$appDirPath/preprocessed_$clipIdx.mp4";

await _ffmpegManager.execute([
"-framerate",
"1",
"-loop",
"1",
"-t",
"1",
"-i",
mediaData.scaledPath ?? mediaData.absolutePath,
"-vf",
"scale=${_getEvenNumber(mediaData.width)}:${_getEvenNumber(mediaData.height)}",
"-c:v",
"libx264",
"-pix_fmt",
"yuv420p",
"-r",
"1",
preProcessedPath,
"-y"
], null);
inputArguments
.addAll(["-framerate", "$_framerate", "-loop", "1"]);
inputArguments.addAll(["-t", "$duration", "-i", mediaData.scaledPath ?? mediaData.absolutePath]);

inputArguments.addAll(["-stream_loop", duration.floor().toString(), "-i", preProcessedPath]);
audioOutputMapVariable = "1:a";
} //
else {
Expand Down Expand Up @@ -168,24 +126,6 @@ Future<RenderedData> clipRender(
]);
inputFileCount++;

// int scaledWidth = (mediaData.width * editedMedia.zoomX).floor();
// int scaledHeight = (mediaData.height * editedMedia.zoomY).floor();

// if (scaledWidth < _resolution.width) {
// scaledHeight = ((scaledHeight) * (_resolution.width / scaledWidth)).floor();
// scaledWidth = _resolution.width;
// }
// if (scaledHeight < _resolution.height) {
// scaledWidth = ((scaledWidth) * (_resolution.height / scaledHeight)).floor();
// scaledHeight = _resolution.height;
// }

// scaledWidth = _getEvenNumber(scaledWidth);
// scaledHeight = _getEvenNumber(scaledHeight);

// filterStrings.add(
// "[0:v]fps=$_framerate,$trimFilter${_getTransposeFilter(mediaData.orientation)}scale=$scaledWidth:$scaledHeight,crop=${_resolution.width}:${_resolution.height}:${editedMedia.translateX}:${editedMedia.translateY},setdar=dar=${_resolution.width / _resolution.height}[vid];");

int cropLeft = max(0, (mediaData.width * editedMedia.cropLeft).floor());
int cropRight = min(mediaData.width, (mediaData.width * editedMedia.cropRight).floor());
int cropTop = max(0, (mediaData.height * editedMedia.cropTop).floor());
Expand All @@ -199,122 +139,6 @@ Future<RenderedData> clipRender(
videoOutputMapVariable = "[vid]";
inputFileCount++;

///////////////////////////
// IMAGE SCALE ANIMATION //
///////////////////////////
if (mediaData.type == EMediaType.image && Random().nextDouble() <= 0.3) {
int animationSpeed = 48;
double animationScaleFactor = 3;

final int videoWidth = _resolution.width;
final int videoHeight = _resolution.height;

String startScaleWidth = "",
startScaleHeight = "",
cropPosX = "",
cropPosY = "";
int scaleAddVal = 0, cropZoomVal = 0;

final EImageScaleType type = _getRandomImageScaleType();

switch (type) {
case EImageScaleType.zoomIn:
{
scaleAddVal = (editedMedia.duration * animationSpeed).floor();
cropZoomVal = (editedMedia.duration * (animationSpeed / 2)).floor();

startScaleWidth = "-1";
startScaleHeight = "${(videoHeight * animationScaleFactor).floor()}+($scaleAddVal*t)";
cropPosX = "($cropZoomVal*t)";
cropPosY = "($cropZoomVal*t)";
}
break;

case EImageScaleType.zoomOut:
{
scaleAddVal = (editedMedia.duration * animationSpeed).floor();
cropZoomVal = (editedMedia.duration * (animationSpeed / 2)).floor();

startScaleWidth = "-1";
startScaleHeight =
"${(videoHeight * animationScaleFactor + scaleAddVal * editedMedia.duration).floor()}-($scaleAddVal*t)";
cropPosX =
"(${(cropZoomVal * editedMedia.duration).floor()}-$cropZoomVal*t)";
cropPosY =
"(${(cropZoomVal * editedMedia.duration).floor()}-$cropZoomVal*t)";
}
break;

case EImageScaleType.leftToRight:
{
animationSpeed = (animationSpeed / 2).floor();
animationScaleFactor /= 2;

cropZoomVal = animationSpeed * 2;

startScaleWidth = "-1";
startScaleHeight =
"${(videoHeight * animationScaleFactor + (cropZoomVal * 2 * editedMedia.duration)).floor()}";
cropPosX = "($cropZoomVal*t)";
cropPosY = "${((cropZoomVal / 2) * editedMedia.duration).floor()}";
}
break;

case EImageScaleType.rightToLeft:
{
animationSpeed = (animationSpeed / 2).floor();
animationScaleFactor /= 2;

cropZoomVal = animationSpeed * 2;

startScaleWidth = "-1";
startScaleHeight =
"${(videoHeight * animationScaleFactor + (cropZoomVal * 2 * editedMedia.duration)).floor()}";
cropPosX =
"(${(cropZoomVal * editedMedia.duration).floor()}-$cropZoomVal*t)";
cropPosY = "${((cropZoomVal / 2) * editedMedia.duration).floor()}";
}
break;

case EImageScaleType.topToBottom:
{
animationSpeed = (animationSpeed / 2).floor();
animationScaleFactor /= 2;

cropZoomVal = animationSpeed * 2;

startScaleWidth = "-1";
startScaleHeight =
"${(videoHeight * animationScaleFactor + (cropZoomVal * 2 * editedMedia.duration)).floor()}";
cropPosX = "${((cropZoomVal / 2) * editedMedia.duration).floor()}";
cropPosY = "($cropZoomVal*t)";
}
break;

case EImageScaleType.bottomToTop:
default:
{
animationSpeed = (animationSpeed / 2).floor();
animationScaleFactor /= 2;

cropZoomVal = animationSpeed * 2;

startScaleWidth = "-1";
startScaleHeight =
"${(videoHeight * animationScaleFactor + (cropZoomVal * 2 * editedMedia.duration)).floor()}";
cropPosX = "${((cropZoomVal / 2) * editedMedia.duration).floor()}";
cropPosY =
"(${(cropZoomVal * editedMedia.duration).floor()}-$cropZoomVal*t)";
}
break;
}

filterStrings.add(
"${videoOutputMapVariable}scale=$startScaleWidth:$startScaleHeight:eval=frame,crop=${(videoWidth * animationScaleFactor).floor()}:${(videoHeight * animationScaleFactor).floor()}:$cropPosX:$cropPosY,scale=$videoWidth:$videoHeight[applied_animation];");

videoOutputMapVariable = "[applied_animation]";
}

///////////////
// ADD FRAME //
///////////////
Expand Down Expand Up @@ -997,8 +821,6 @@ Future<String?> extractThumbnail(EditedMedia editedMedia) async {
if (mediaData.type == EMediaType.video) {
inputArguments.addAll(["-ss", editedMedia.startTime.toString()]);
}
// filterStrings.add(
// "${_getTransposeFilter(mediaData.orientation)}scale=${(mediaData.width * editedMedia.zoomX).floor()}:${(mediaData.height * editedMedia.zoomY).floor()},crop=${_resolution.width}:${_resolution.height}:${editedMedia.translateX}:${editedMedia.translateY},scale=${(_scaledVideoWidth / 2).floor()}:${(_scaledVideoHeight / 2).floor()},setdar=dar=${_scaledVideoWidth / _scaledVideoHeight}");

int cropLeft = max(0, (mediaData.width * editedMedia.cropLeft).floor());
int cropRight = min(mediaData.width, (mediaData.width * editedMedia.cropRight).floor());
Expand Down
9 changes: 4 additions & 5 deletions lib/vm_sdk/impl/ffmpeg_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,26 @@ class FFMpegManager {
FFmpegKit ffmpegIns = FFmpegKit();
FFmpegKitConfig ffmpegConfig = FFmpegKitConfig();

String log = "";

Future<void> execute(
Future<FFmpegSession> execute(
List<String> args, Function(Statistics)? callback) async {

if (callback != null) {
FFmpegKitConfig.enableStatisticsCallback((statistics) => callback(statistics));
}

log = "";
FFmpegKitConfig.enableLogCallback((log) {
this.log += log.getMessage();
print(log.getMessage());
});

final FFmpegSession session = await FFmpegKit.executeWithArguments(args);
final ReturnCode? returnCode = await session.getReturnCode();

final log = await session.getAllLogsAsString();
if (returnCode == null || !returnCode.isValueSuccess()) {
throw Exception("FFMPEG EXECUTE FAILED!\nLOG : $log");
}

return session;
}

Future<void> cancel() async {
Expand Down
8 changes: 7 additions & 1 deletion lib/vm_sdk/vm_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,13 @@ class VMSDKWidget extends StatelessWidget {
final RenderedData mergedClip = await mergeAllClips(xfadeAppliedList);
final RenderedData resultClip = await applyMusics(mergedClip, regeneratedMusicList);

print(DateTime.now().difference(now).inSeconds);
print("elapsed time for rendering : ${DateTime.now().difference(now).inMilliseconds / 1000}s");

File resultFile = File(resultClip.absolutePath);
if (await resultFile.exists()) {
double fileSizeInMegaBytes = ((await resultFile.length()) * 1.0) / 1024 / 1024;
print("resultFile : ${(fileSizeInMegaBytes * 100).floor() / 100}MB");
}

if (_currentTimer != null) {
_currentTimer!.cancel();
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ flutter:
# - assets/_mlkittest/set02/
# - assets/_mlkittest/subin/
# - assets/_test/set1/
# - assets/_test/set1_1080p/
# - assets/_test/monaco1/
# - assets/_test/monaco2/
# - assets/_test/monaco2_scaled/
# - assets/_test/monaco2_1080p/
# - assets/_test/asdasd/
# - assets/_test/oriented/
# - assets/_test/mediajson-joined/
Expand Down

0 comments on commit ed39c37

Please sign in to comment.