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

Setting trim start #28

Closed
nicksam112 opened this issue Sep 30, 2015 · 6 comments
Closed

Setting trim start #28

nicksam112 opened this issue Sep 30, 2015 · 6 comments

Comments

@nicksam112
Copy link

So poking around the code it seems as though it's only possible to trim starting from the very start of the video and setting an end point via duration.

Is there going to be any support for setting a starting trim time, or have I missed it somewhere? Thank you!

@rossmartin
Copy link
Collaborator

When it gets cold here and I'm not buried in my day job I'll add this feature if it hasn't already been. It would be nice to have.

Thanks.

@nicksam112
Copy link
Author

So looking into it, ffmpeg android supports a start time so it should be almost trivial. I'll try to submit a PR this weekend.

@kmturley
Copy link

I achieved this by doing:

VideoEditor.java
line 192

final String videoStartTime = options.getString("startTime");
final String videoEndTime = options.getString("endTime");

line 224

Clip clip2 = new Clip();
clip2.path = new File(inFile2.getAbsolutePath()).getCanonicalPath();
clip2.startTime = videoStartTime;
clip2.endTime = videoEndTime;
ffmpegController.getInfo(clip2);
listVideos.add(clip2);

FfmpegController.java
line 226

public static final String STARTTIME = "-ss";
public static final String DURATION = "-t";

line 658

public Clip convertToMP4Stream (Clip mediaIn, String startTime, String endTime, String outPath, ShellCallback sc) throws Exception
{

line 671

if (startTime != null) {
    cmd.add(Argument.STARTTIME);
    cmd.add(startTime);
}

if (endTime != null) {
    cmd.add(Argument.DURATION);
    cmd.add(endTime);
}

line 1182

mdOut = convertToMP4Stream(vdesc,vdesc.startTime,vdesc.endTime,fileOut.getCanonicalPath(), sc);

@rossmartin
Copy link
Collaborator

You can now trim a video in the latest version (0.0.6) of the plugin -

https://github.com/jbavari/cordova-plugin-video-editor/tree/0.0.6#trim-a-video

@jbavari
Copy link
Owner

jbavari commented Nov 11, 2015

@rossmartin Thanks for all your hard work on this plugin.

@kmturley
Copy link

Just a note, I had issues with the duration logic (FfmpegController.java line 672)

if (duration != -1)
    {
        cmd.add(Argument.DURATION);
        double dValue = mediaIn.duration;
        int hours = (int)(dValue/3600f);
        dValue -= (hours*3600);
        cmd.add("0");
        cmd.add(String.format(Locale.US,"%s",hours));
        cmd.add(":");
        int min = (int)(dValue/60f);
        dValue -= (min*60);
        cmd.add("0");
        cmd.add(String.format(Locale.US,"%s",min));
        cmd.add(":");
        cmd.add(String.format(Locale.US,"%f",dValue));
        //cmd.add("00:00:" + String.format(Locale.US,"%f",mediaIn.duration));
    }

It would output invalid commands for ffmpeg and create errors. I replaced it with:

if (startTime != null) {
    cmd.add(Argument.STARTTIME);
    cmd.add(startTime);
}

if (endTime != null) {
    cmd.add(Argument.DURATION);
    cmd.add(endTime);
}

And then javascript has to pass through the exact start time and end time strings (rather than integer durations):

startTime = '00:00:05.2'
endTime = '00:00:08.1'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants