diff --git a/lib/vm_sdk/impl/auto_edit_helper.dart b/lib/vm_sdk/impl/auto_edit_helper.dart index 7ee1bca..f4b6003 100644 --- a/lib/vm_sdk/impl/auto_edit_helper.dart +++ b/lib/vm_sdk/impl/auto_edit_helper.dart @@ -583,14 +583,14 @@ Future generateAllEditedData( // TO DO : Load from Template Data final List originXfadeTransitionList = ResourceManager.getInstance().getAllXFadeTransitions(speed: speed); - final List - originOverlayTransitionList = ResourceManager.getInstance().getAllOverlayTransitions(speed: speed); + // final List + // originOverlayTransitionList = ResourceManager.getInstance().getAllOverlayTransitions(speed: speed); final List curXfadeTransitionList = []; - final List curRecommendedOverlayTransitionList = [], curOtherOverlayTransitionList = []; + // final List curRecommendedOverlayTransitionList = [], curOtherOverlayTransitionList = []; curXfadeTransitionList.addAll(originXfadeTransitionList); - curRecommendedOverlayTransitionList.addAll(originOverlayTransitionList.where((element) => element.isRecommend).toList()); - curOtherOverlayTransitionList.addAll(originOverlayTransitionList.where((element) => !element.isRecommend).toList()); + // curRecommendedOverlayTransitionList.addAll(originOverlayTransitionList.where((element) => element.isRecommend).toList()); + // curOtherOverlayTransitionList.addAll(originOverlayTransitionList.where((element) => !element.isRecommend).toList()); int lastTransitionInsertedIndex = 0; int clipCount = 3 + (Random()).nextInt(2); @@ -617,9 +617,10 @@ Future generateAllEditedData( } if (isPassedBoundary) { - currentTransitionType = (Random()).nextDouble() >= 0.3 - ? ETransitionType.xfade - : ETransitionType.overlay; + // currentTransitionType = (Random()).nextDouble() >= 0.3 + // ? ETransitionType.xfade + // : ETransitionType.overlay; + currentTransitionType = ETransitionType.xfade; } // else { continue; @@ -649,35 +650,35 @@ Future generateAllEditedData( curXfadeTransitionList.addAll(originXfadeTransitionList); } } // - else if (currentTransitionType == ETransitionType.overlay) { - List curOverlayTransitionList; - if (Random().nextDouble() >= 0.4 && curRecommendedOverlayTransitionList.isNotEmpty) { - curOverlayTransitionList = curRecommendedOverlayTransitionList; - } - else { - if (curRecommendedOverlayTransitionList.isEmpty && curOtherOverlayTransitionList.isEmpty) { - curRecommendedOverlayTransitionList.addAll(originOverlayTransitionList.where((element) => element.isRecommend).toList()); - curOtherOverlayTransitionList.addAll(originOverlayTransitionList.where((element) => !element.isRecommend).toList()); - } - curOverlayTransitionList = curOtherOverlayTransitionList; - } - - int randIdx = (Random()).nextInt(curOverlayTransitionList.length) % - curOverlayTransitionList.length; - editedMedia.transition = curOverlayTransitionList[randIdx]; + // else if (currentTransitionType == ETransitionType.overlay) { + // List curOverlayTransitionList; + // if (Random().nextDouble() >= 0.4 && curRecommendedOverlayTransitionList.isNotEmpty) { + // curOverlayTransitionList = curRecommendedOverlayTransitionList; + // } + // else { + // if (curRecommendedOverlayTransitionList.isEmpty && curOtherOverlayTransitionList.isEmpty) { + // curRecommendedOverlayTransitionList.addAll(originOverlayTransitionList.where((element) => element.isRecommend).toList()); + // curOtherOverlayTransitionList.addAll(originOverlayTransitionList.where((element) => !element.isRecommend).toList()); + // } + // curOverlayTransitionList = curOtherOverlayTransitionList; + // } - if (editedMedia.transition != null) { - final OverlayTransitionData overlayTransitionData = - editedMedia.transition as OverlayTransitionData; - if (overlayTransitionData.fileMap[ratio]!.duration >= - editedMedia.duration) { - editedMedia.transition = null; - continue; - } - } + // int randIdx = (Random()).nextInt(curOverlayTransitionList.length) % + // curOverlayTransitionList.length; + // editedMedia.transition = curOverlayTransitionList[randIdx]; + + // if (editedMedia.transition != null) { + // final OverlayTransitionData overlayTransitionData = + // editedMedia.transition as OverlayTransitionData; + // if (overlayTransitionData.fileMap[ratio]!.duration >= + // editedMedia.duration) { + // editedMedia.transition = null; + // continue; + // } + // } - curOverlayTransitionList.removeAt(randIdx); - } + // curOverlayTransitionList.removeAt(randIdx); + // } lastTransitionInsertedIndex = i; clipCount = 3 + (Random()).nextInt(2); @@ -691,119 +692,119 @@ Future generateAllEditedData( // TO DO : Load from Template Data - final Map> originFrameMap = ResourceManager.getInstance().getFrameDataMap(speed: speed), - curRecommendedFrameMap = {}, curOtherFrameMap = {}; - final Map> originStickerMap = ResourceManager.getInstance().getStickerDataMap(speed: speed), - curStickerMap = {}; + // final Map> originFrameMap = ResourceManager.getInstance().getFrameDataMap(speed: speed), + // curRecommendedFrameMap = {}, curOtherFrameMap = {}; + // final Map> originStickerMap = ResourceManager.getInstance().getStickerDataMap(speed: speed), + // curStickerMap = {}; - for (final key in originFrameMap.keys) { - curRecommendedFrameMap[key] = []; - curOtherFrameMap[key] = []; + // for (final key in originFrameMap.keys) { + // curRecommendedFrameMap[key] = []; + // curOtherFrameMap[key] = []; - curRecommendedFrameMap[key]!.addAll(originFrameMap[key]!.where((frame) => frame.isRecommend).toList()); - curOtherFrameMap[key]!.addAll(originFrameMap[key]!.where((frame) => !frame.isRecommend).toList()); - } - - for (final key in originStickerMap.keys) { - curStickerMap[key] = []; - curStickerMap[key]!.addAll(originStickerMap[key]!); - } - - int lastFrameInsertedIndex = 0; - clipCount = 2 + (Random()).nextInt(1); - - // EXCEPT FIRST MEDIA - for (int i = 1; i < allEditedData.editedMediaList.length; i++) { - final EditedMedia editedMedia = allEditedData.editedMediaList[i]; - - if (editedMedia.duration < 2.5) { - continue; - } - - final int diff = i - lastFrameInsertedIndex; - - EMediaLabel mediaLabel = editedMedia.mediaLabel; - switch (mediaLabel) { - case EMediaLabel.background: - case EMediaLabel.action: - { - if (diff >= clipCount) { - mediaLabel = EMediaLabel.background; - if (!originFrameMap.containsKey(mediaLabel)) continue; + // curRecommendedFrameMap[key]!.addAll(originFrameMap[key]!.where((frame) => frame.isRecommend).toList()); + // curOtherFrameMap[key]!.addAll(originFrameMap[key]!.where((frame) => !frame.isRecommend).toList()); + // } - List curFrameList; - if (Random().nextDouble() >= 0.4 && curRecommendedFrameMap[mediaLabel]!.isNotEmpty) { - curFrameList = curRecommendedFrameMap[mediaLabel]!; - } - else { - if (curRecommendedFrameMap[mediaLabel]!.isEmpty && curOtherFrameMap[mediaLabel]!.isEmpty) { - curRecommendedFrameMap[mediaLabel]!.addAll(originFrameMap[mediaLabel]!.where((frame) => frame.isRecommend).toList()); - curOtherFrameMap[mediaLabel]!.addAll(originFrameMap[mediaLabel]!.where((frame) => !frame.isRecommend).toList()); - } - curFrameList = curOtherFrameMap[mediaLabel]!; - } + // for (final key in originStickerMap.keys) { + // curStickerMap[key] = []; + // curStickerMap[key]!.addAll(originStickerMap[key]!); + // } - int randIdx = - (Random()).nextInt(curFrameList.length) % curFrameList.length; - editedMedia.frame = curFrameList[randIdx]; - curFrameList.removeAt(randIdx); + // int lastFrameInsertedIndex = 0; + // clipCount = 2 + (Random()).nextInt(1); - lastFrameInsertedIndex = i; - clipCount = 4 + (Random()).nextInt(1); - } - } - break; + // // EXCEPT FIRST MEDIA + // for (int i = 1; i < allEditedData.editedMediaList.length; i++) { + // final EditedMedia editedMedia = allEditedData.editedMediaList[i]; - case EMediaLabel.person: - case EMediaLabel.food: - case EMediaLabel.animal: - // { - // // 80% 확률로 스티커 삽입 - // if ((Random()).nextDouble() >= 0.8) continue; - // if (!curStickerMap.containsKey(mediaLabel)) continue; - - // List curStickerList = curStickerMap[mediaLabel]!; - // int randIdx = - // (Random()).nextInt(curStickerList.length) % curStickerList.length; - - // final StickerData? stickerData = curStickerList[randIdx]; - - // if (stickerData != null) { - // final EditedStickerData editedStickerData = - // EditedStickerData(stickerData); - - // final double stickerWidth = - // editedStickerData.fileinfo!.width * editedStickerData.scale; - // final double stickerHeight = - // editedStickerData.fileinfo!.height * editedStickerData.scale; - - // final double radian = Random().nextDouble() * pi * 2; - // final double distance = - // (videoWidth > videoHeight ? videoHeight / 4 : videoWidth / 4); - - // editedStickerData.x = (videoWidth / 2) + - // (cos(radian) * distance) - - // (stickerWidth / 2); - // editedStickerData.y = (videoHeight / 2) + - // (sin(radian) * distance) - - // (stickerHeight / 2); - - // editedMedia.stickers.add(editedStickerData); - - // curStickerList.removeAt(randIdx); - // if (curStickerList.isEmpty) { - // curStickerList.addAll(originStickerMap[mediaLabel]!); - // } - // } - // } - break; + // if (editedMedia.duration < 2.5) { + // continue; + // } - case EMediaLabel.object: - default: - mediaLabel = EMediaLabel.none; - continue; - } - } + // final int diff = i - lastFrameInsertedIndex; + + // EMediaLabel mediaLabel = editedMedia.mediaLabel; + // switch (mediaLabel) { + // case EMediaLabel.background: + // case EMediaLabel.action: + // { + // if (diff >= clipCount) { + // mediaLabel = EMediaLabel.background; + // if (!originFrameMap.containsKey(mediaLabel)) continue; + + // List curFrameList; + // if (Random().nextDouble() >= 0.4 && curRecommendedFrameMap[mediaLabel]!.isNotEmpty) { + // curFrameList = curRecommendedFrameMap[mediaLabel]!; + // } + // else { + // if (curRecommendedFrameMap[mediaLabel]!.isEmpty && curOtherFrameMap[mediaLabel]!.isEmpty) { + // curRecommendedFrameMap[mediaLabel]!.addAll(originFrameMap[mediaLabel]!.where((frame) => frame.isRecommend).toList()); + // curOtherFrameMap[mediaLabel]!.addAll(originFrameMap[mediaLabel]!.where((frame) => !frame.isRecommend).toList()); + // } + // curFrameList = curOtherFrameMap[mediaLabel]!; + // } + + // int randIdx = + // (Random()).nextInt(curFrameList.length) % curFrameList.length; + // editedMedia.frame = curFrameList[randIdx]; + // curFrameList.removeAt(randIdx); + + // lastFrameInsertedIndex = i; + // clipCount = 4 + (Random()).nextInt(1); + // } + // } + // break; + + // case EMediaLabel.person: + // case EMediaLabel.food: + // case EMediaLabel.animal: + // // { + // // // 80% 확률로 스티커 삽입 + // // if ((Random()).nextDouble() >= 0.8) continue; + // // if (!curStickerMap.containsKey(mediaLabel)) continue; + + // // List curStickerList = curStickerMap[mediaLabel]!; + // // int randIdx = + // // (Random()).nextInt(curStickerList.length) % curStickerList.length; + + // // final StickerData? stickerData = curStickerList[randIdx]; + + // // if (stickerData != null) { + // // final EditedStickerData editedStickerData = + // // EditedStickerData(stickerData); + + // // final double stickerWidth = + // // editedStickerData.fileinfo!.width * editedStickerData.scale; + // // final double stickerHeight = + // // editedStickerData.fileinfo!.height * editedStickerData.scale; + + // // final double radian = Random().nextDouble() * pi * 2; + // // final double distance = + // // (videoWidth > videoHeight ? videoHeight / 4 : videoWidth / 4); + + // // editedStickerData.x = (videoWidth / 2) + + // // (cos(radian) * distance) - + // // (stickerWidth / 2); + // // editedStickerData.y = (videoHeight / 2) + + // // (sin(radian) * distance) - + // // (stickerHeight / 2); + + // // editedMedia.stickers.add(editedStickerData); + + // // curStickerList.removeAt(randIdx); + // // if (curStickerList.isEmpty) { + // // curStickerList.addAll(originStickerMap[mediaLabel]!); + // // } + // // } + // // } + // break; + + // case EMediaLabel.object: + // default: + // mediaLabel = EMediaLabel.none; + // continue; + // } + // } print("--------------------------------------"); print("--------------------------------------"); diff --git a/lib/vm_sdk/impl/ffmpeg_helper.dart b/lib/vm_sdk/impl/ffmpeg_helper.dart index e0be259..ff5df09 100644 --- a/lib/vm_sdk/impl/ffmpeg_helper.dart +++ b/lib/vm_sdk/impl/ffmpeg_helper.dart @@ -56,7 +56,7 @@ Future clipRender( int clipIdx, TransitionData? prevTransition, TransitionData? nextTransition, - Function(Statistics)? ffmpegCallback, { isAutoEdit = false }) async { + Function(Statistics)? ffmpegCallback, { isOnlyOneClip = false }) async { final MediaData mediaData = await scaleImageMedia(editedMedia.mediaData); final FrameData? frame = editedMedia.frame; final List stickerList = editedMedia.stickers; @@ -233,8 +233,8 @@ Future clipRender( ]); String overlayTimeFilter = ""; - if (isAutoEdit) { - overlayTimeFilter = "enable='between(t\\,0,${min(5, editedMedia.duration)})':"; + if (isOnlyOneClip) { + // overlayTimeFilter = "enable='between(t\\,0,${min(5, editedMedia.duration)})':"; } filterStrings.add( @@ -278,7 +278,7 @@ Future clipRender( ]); String overlayTimeFilter = ""; - if (isAutoEdit) { + if (isOnlyOneClip) { overlayTimeFilter = "enable='between(t\\,0,${min(5, editedMedia.duration)})':"; } diff --git a/lib/vm_sdk/vm_sdk.dart b/lib/vm_sdk/vm_sdk.dart index 007e269..ba19a0d 100644 --- a/lib/vm_sdk/vm_sdk.dart +++ b/lib/vm_sdk/vm_sdk.dart @@ -464,7 +464,7 @@ class VMSDKWidget extends StatelessWidget { prevTransition, nextTransition, (statistics) => _currentRenderedFrameInCallback = - statistics.getVideoFrameNumber(), isAutoEdit: isAutoEdit); + statistics.getVideoFrameNumber(), isOnlyOneClip: editedMediaList.length == 1); _currentRenderedFrameInCallback = 0; @@ -518,7 +518,7 @@ class VMSDKWidget extends StatelessWidget { } } - if (totalDuration >= 10) { + if (isAutoEdit && editedMediaList.length > 1 && totalDuration >= 10) { double curDuration = 0; List fadeOutClips = []; for (int i = xfadeAppliedList.length - 1; i >= 0; i--) {