Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ group 'me.anharu.video_editor'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.5.10'
repositories {
google()
jcenter()
Expand Down Expand Up @@ -41,5 +41,5 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.github.MasayukiSuda:Mp4Composer-android:v0.3.9'
implementation 'com.github.MasayukiSuda:Mp4Composer-android:v0.4.1'
}
43 changes: 43 additions & 0 deletions android/src/main/kotlin/me/anharu/video_editor/SpeedChanger.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package me.anharu.video_editor


import android.app.Activity
import com.daasuu.mp4compose.composer.Mp4Composer
import io.flutter.plugin.common.MethodChannel.Result

class SpeedChanger(inputVideo: String, outputVideo: String, val result: Result, val activity: Activity) {
var composer: Mp4Composer = Mp4Composer(inputVideo, outputVideo)

fun speed(speed:Float) {
composer.timeScale(10F)
.listener(object : Mp4Composer.Listener {
override fun onProgress(progress: Double) {

}

override fun onCurrentWrittenVideoTime(timeUs: Long) {
TODO("Not yet implemented")
}

override fun onCompleted() {
activity.runOnUiThread(Runnable {
result.success(null)
})
}

override fun onCanceled() {
activity.runOnUiThread(Runnable {
result.error("user_cancelled", "Cancelled by user", null)
})
}

override fun onFailed(exception: Exception?) {
exception?.printStackTrace()
activity.runOnUiThread(Runnable {
result.error("video_trim_failed", exception?.localizedMessage, exception?.stackTrace)
})
}

}).start();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,22 @@ public class VideoEditorPlugin : FlutterPlugin, MethodCallHandler, PluginRegistr
val endTime: Long = call.argument<Int>("endTime")?.toLong() ?: -1
VideoTrimmer(srcFilePath, destFilePath, result, getActivity).trimVideo(startTime, endTime)
}
"speed_change" -> {
val getActivity = activity ?: return
val srcFilePath: String = call.argument("srcFilePath") ?: run {
result.error("src_file_path_not_found", "the src file path is not found.", null)
return
}
val destFilePath: String = call.argument("destFilePath") ?: run {
result.error("dest_file_path_not_found", "the dest file path is not found.", null)
return
}
val speed: Float = call.argument<Double>("speed")?.toFloat() ?: 0F
print("===>$speed");
SpeedChanger(srcFilePath, destFilePath, result, getActivity).speed(speed)
}
else -> {
print("===>sxxxxxxxx");
result.notImplemented()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class VideoGeneratorService(
override fun onProgress(progress: Double) {
println("onProgress = " + progress)
}
override fun onCurrentWrittenVideoTime(timeUs: Long) {
TODO("Not yet implemented")
}

override fun onCompleted() {
activity.runOnUiThread(Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class VideoTrimmer(inputVideo: String, outputVideo: String, val result: Result,

}

override fun onCurrentWrittenVideoTime(timeUs: Long) {

}

override fun onCompleted() {
activity.runOnUiThread(Runnable {
result.success(null)
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.4.32'
repositories {
google()
jcenter()
Expand Down
21 changes: 21 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ PODS:
- Flutter
- image_picker (0.0.1):
- Flutter
- libwebp (1.2.0):
- libwebp/demux (= 1.2.0)
- libwebp/mux (= 1.2.0)
- libwebp/webp (= 1.2.0)
- libwebp/demux (1.2.0):
- libwebp/webp
- libwebp/mux (1.2.0):
- libwebp/demux
- libwebp/webp (1.2.0)
- path_provider (0.0.1):
- Flutter
- tapioca (0.0.1):
- Flutter
- video_player (0.0.1):
- Flutter
- video_thumbnail (0.0.1):
- Flutter
- libwebp

DEPENDENCIES:
- Flutter (from `Flutter`)
Expand All @@ -18,6 +30,11 @@ DEPENDENCIES:
- path_provider (from `.symlinks/plugins/path_provider/ios`)
- tapioca (from `.symlinks/plugins/tapioca/ios`)
- video_player (from `.symlinks/plugins/video_player/ios`)
- video_thumbnail (from `.symlinks/plugins/video_thumbnail/ios`)

SPEC REPOS:
trunk:
- libwebp

EXTERNAL SOURCES:
Flutter:
Expand All @@ -32,14 +49,18 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/tapioca/ios"
video_player:
:path: ".symlinks/plugins/video_player/ios"
video_thumbnail:
:path: ".symlinks/plugins/video_thumbnail/ios"

SPEC CHECKSUMS:
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
gallery_saver: 9fc173c9f4fcc48af53b2a9ebea1b643255be542
image_picker: 50e7c7ff960e5f58faa4d1f4af84a771c671bc4a
libwebp: e90b9c01d99205d03b6bb8f2c8c415e5a4ef66f0
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
tapioca: 59e9fc89671d49e2cefe6cd59c3efe678e589e89
video_player: 9cc823b1d9da7e8427ee591e8438bfbcde500e6e
video_thumbnail: c4e2a3c539e247d4de13cd545344fd2d26ffafd1

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c

Expand Down
12 changes: 8 additions & 4 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
TargetAttributes = {
97C146ED1CF9000F007C117D = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = SCAN67V3XX;
DevelopmentTeam = WQZP98NKJH;
LastSwiftMigration = 1100;
};
};
Expand Down Expand Up @@ -229,17 +229,21 @@
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/gallery_saver/gallery_saver.framework",
"${BUILT_PRODUCTS_DIR}/image_picker/image_picker.framework",
"${BUILT_PRODUCTS_DIR}/libwebp/libwebp.framework",
"${BUILT_PRODUCTS_DIR}/path_provider/path_provider.framework",
"${BUILT_PRODUCTS_DIR}/tapioca/tapioca.framework",
"${BUILT_PRODUCTS_DIR}/video_player/video_player.framework",
"${BUILT_PRODUCTS_DIR}/video_thumbnail/video_thumbnail.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/gallery_saver.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/image_picker.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libwebp.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/tapioca.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/video_player.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/video_thumbnail.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -373,7 +377,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = SCAN67V3XX;
DEVELOPMENT_TEAM = WQZP98NKJH;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -506,7 +510,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = SCAN67V3XX;
DEVELOPMENT_TEAM = WQZP98NKJH;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -534,7 +538,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = SCAN67V3XX;
DEVELOPMENT_TEAM = WQZP98NKJH;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down
16 changes: 10 additions & 6 deletions example/lib/video_player_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ class _VideoAppState extends State<VideoScreen> {
@override
void initState() {
super.initState();
_controller = VideoPlayerController.file(File(path))
..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {});
print("output video ==== ${_controller.value.duration.inSeconds}");
});
initialize();
}
initialize() async {
try {
_controller = VideoPlayerController.file(File(path));
await _controller.initialize();
setState(() {});
} catch(error){
print(error);
}
}

@override
Expand Down
46 changes: 27 additions & 19 deletions example/lib/video_trimmer/video_trim_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path_provider/path_provider.dart';
import 'package:tapioca/tapioca.dart';
Expand All @@ -20,6 +21,7 @@ class _VideoTrimScreenState extends State<VideoTrimScreen> {
double endPos = -1;

initializeVideo() {
if (_video == null) return;
_controller = VideoPlayerController.file(File(_video!.path))
..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
Expand Down Expand Up @@ -52,10 +54,13 @@ class _VideoTrimScreenState extends State<VideoTrimScreen> {
print("start time === $startPos === end time === $endPos");
var tempDir = await getTemporaryDirectory();
final path = '${tempDir.path}/result.mp4';
await VideoEditor.onTrimVideo(_video!.path, path, startPos, endPos);
print("outputpath === $path");
// await VideoEditor.onTrimVideo(_video!.path, path, startPos, endPos);
print("outputpath after === $path");
await VideoEditor.speed(_video!.path, path, 3);
Navigator.push(
context, MaterialPageRoute(builder: (_) => VideoScreen(path)));
} on Exception catch (e) {
} on PlatformException catch (e) {
print(e);
}
}
Expand All @@ -69,8 +74,7 @@ class _VideoTrimScreenState extends State<VideoTrimScreen> {
onPressed: this._onVideoSelectPressed,
icon: Icon(Icons.ondemand_video)),
IconButton(
onPressed: this.onTrimVideoPressed,
icon: Icon(Icons.done))
onPressed: this.onTrimVideoPressed, icon: Icon(Icons.done))
],
),
body: Center(
Expand All @@ -81,21 +85,25 @@ class _VideoTrimScreenState extends State<VideoTrimScreen> {
aspectRatio: _controller!.value.aspectRatio,
child: VideoPlayer(_controller!),
),
TrimEditor(
viewerWidth: MediaQuery.of(context).size.width,
viewerHeight: 50,
videoFile: _video!.path,
videoPlayerController: _controller!,
fit: BoxFit.cover,
onChangeEnd: (position) {
this.endPos = position;
print("onchange end ==== $position");
},
onChangeStart: (position) {
this.startPos = position;
print("onchange start ==== $position");
},
onChangePlaybackState: (state) {},
Positioned(
left: 20,
right: 20,
child: TrimEditor(
viewerWidth: MediaQuery.of(context).size.width - 40,
viewerHeight: 50,
videoFile: _video!.path,
videoPlayerController: _controller!,
fit: BoxFit.cover,
onChangeEnd: (position) {
this.endPos = position;
print("onchange end ==== $position");
},
onChangeStart: (position) {
this.startPos = position;
print("onchange start ==== $position");
},
onChangePlaybackState: (state) {},
),
)
],
)
Expand Down
Loading