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

Selecting Videos from Gallery for transcoding #33

Closed
cameronws opened this issue Nov 5, 2015 · 12 comments
Closed

Selecting Videos from Gallery for transcoding #33

cameronws opened this issue Nov 5, 2015 · 12 comments

Comments

@cameronws
Copy link

I'm busy collaborating on an app that requires video upload but we have restrictions in place as to the length and size of videos that can be uploaded. I don't have any issues trans-coding videos straight after recording from the video camera, but I keep getting a JSON error when trying to trans-code a video from my phone's gallery. I've tried all sorts of ways of getting the file path so that it is similar to that provided by the camera's success callback to no avail. Has anyone else experienced this or have a solution?

@rossmartin
Copy link
Collaborator

Is this occurring on iOS or Android? What is the error that you are seeing?

@cameronws
Copy link
Author

Android

@cameronws
Copy link
Author

OK, so I got the trans-coding to work with Gallery videos, but now I have another issue with Gallery videos - they are not getting trimmed to my specified time/duration. I set the duration to 12, select a video that's around 50 seconds in length, start tran-scoding and end up with a full 50 second video that has been trans-coded. Any ideas as to how to get this to work???

@rossmartin
Copy link
Collaborator

What os version of android is on the device? What is the version of cordova android platform?

I have an iPhone/android app that uses this plugin and limits duration, I haven't seen any issues limiting duration on android.

Do you see anything in the adb logcat shellOut: that indicates any errors with ffmpeg?

@cameronws
Copy link
Author

OS version is 4.4.2, cordova version is 5.1.1. I'm only having issues with trimming videos that are longer than my specified duration, so the duration of a video before trans-coding is the same after trans-coding.

I've noticed in the ffmpeg plugin, there is no handling/passing of the duration parameter into the processVideo function, only in the other functions. Maybe this is the reason?

@srinivasulurao
Copy link

@rossmartin even i am facing the same situation,i am not able to trim the video based on end time & start time, can u please do something for this, i will be very grateful to you, thanks in advance :)

@rossmartin
Copy link
Collaborator

@srinivasulurao @cameronws I plan to work on this issue tomorrow.

@srinivasulurao
Copy link

Thanks a ton, really appreciated !

@cameronws
Copy link
Author

I managed to get this working and have submitted a pull request on the ffmpeg project for the solution. guardianproject/android-ffmpeg-java#19
For now you can do the following:

  • Open [app]/platforms/android/org.apache.cordova.videoeditor/[app]-android-ffmpeg-java/src/org/ffmpeg/android/FfmpegController.java in your text editor, in the processVideo function after the if (out.format != null) statement, add the following piece of code:
if (out.duration > 0)
{
    cmd.add(Argument.DURATION);
    cmd.add(out.duration+"");
}
  • Save the file and you're good to go.

@rossmartin
Copy link
Collaborator

@cameronws Thanks for finding this. I think I never noticed the issue on android because trimming used to work before I rewrote the android plugin to use android-ffmpeg-java. I do use the duration argument passed to the plugin class but the underlying android-ffmpeg-java is the culprit as you pointed out. I'll wait a reasonable time for your pull request to happen and then re-integrate the latest version of android-ffmpeg-java. I'll leave this issue open for now.

Also, I'll be adding some instructions on how to select a video from the gallery for transcoding. It is easy using the cordova-camera plugin like this -

var options = {
  sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM,
  mediaType: Camera.MediaType.VIDEO,
  allowEdit: true
};

navigator.camera.getPicture(
  function (uri) {

  },
  function (message) {

  }, 
  options
);

The uri in the success callback is the path to the video and you can then do a VideoEditor.transcodeVideo using it.

@n8fr8
Copy link

n8fr8 commented Nov 10, 2015

Sorry about that guys. I am surprised myself that duration didn't work with that command, since we use this for trimming in our StoryMaker app. Anyhow, patch merged. Thanks @cameronws

@rossmartin
Copy link
Collaborator

@n8fr8 @cameronws Thanks!

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