diff --git a/lib/test.dart b/lib/test.dart index 44ccf6e..2990368 100644 --- a/lib/test.dart +++ b/lib/test.dart @@ -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")); diff --git a/lib/vm_sdk/impl/ffmpeg_helper.dart b/lib/vm_sdk/impl/ffmpeg_helper.dart index 411da5d..e0be259 100644 --- a/lib/vm_sdk/impl/ffmpeg_helper.dart +++ b/lib/vm_sdk/impl/ffmpeg_helper.dart @@ -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; @@ -28,7 +19,6 @@ double _scaleFactor = 2 / 3.0; double _minDurationFactor = 1 / _framerate; const int _fadeDuration = 3; -List _imageScaleType = []; class RenderedData { String absolutePath; double duration; @@ -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,"; @@ -105,30 +83,10 @@ Future 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 { @@ -168,24 +126,6 @@ Future 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()); @@ -199,122 +139,6 @@ Future 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 // /////////////// @@ -997,8 +821,6 @@ Future 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()); diff --git a/lib/vm_sdk/impl/ffmpeg_manager.dart b/lib/vm_sdk/impl/ffmpeg_manager.dart index ad128a2..cdde7c4 100644 --- a/lib/vm_sdk/impl/ffmpeg_manager.dart +++ b/lib/vm_sdk/impl/ffmpeg_manager.dart @@ -9,27 +9,26 @@ class FFMpegManager { FFmpegKit ffmpegIns = FFmpegKit(); FFmpegKitConfig ffmpegConfig = FFmpegKitConfig(); - String log = ""; - - Future execute( + Future execute( List 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 cancel() async { diff --git a/lib/vm_sdk/vm_sdk.dart b/lib/vm_sdk/vm_sdk.dart index 1af4467..007e269 100644 --- a/lib/vm_sdk/vm_sdk.dart +++ b/lib/vm_sdk/vm_sdk.dart @@ -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(); diff --git a/pubspec.yaml b/pubspec.yaml index 0c891a0..8c16836 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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/