2

I'm looking for a way to convert 3gp to mp4 in Android. I'm using the device's camera through 'MediaStore.ACTION_VIDEO_CAPTURE', and the video is transferred to my server. My server allows only mp4 files. Almost all devices save video as a mp4 files, but some devices save as a 3gp file. So, I have to convert 3gp to mp4 for some devices.

Please help!!

JstnPwll
  • 8,585
  • 2
  • 33
  • 56
Storm
  • 21
  • 1
  • 3

1 Answers1

0

You can pretty easily use ffmpeg via a shell command with java's Runtime.getRuntime().exec(...) to convert your video from 3gp to mp4. Get the ffmpeg binary for arm devices (the majority of android devices) here: https://www.dropbox.com/s/nxjnrb71qdrq5jn/ffmpeg.zip?n=138005726. You'll want to package this with your rom, detect when a file is 3gp, and then use ffmpeg to convert it to mp4 before uploading it to the server.

To execute the binary in your java code, you'll want to make a method like this where input is the location of input video, output is the location of output video, and fmpeg is the location of the ffmpeg binary you include:

public void convertVideo(String input, String output) throws IOException, InterruptedException
{
    String args = ffmpeg + "-i" + input + "ffmpeg encoding paramaters..." + "-f mp4" + output;
    Runtime r = Runtime.getRuntime();
    Process p = r.exec("/system/bin/sh" + "-c" + args);
    p.waitFor();
}

Your ffmpeg command parameters may need to be optimized for a target video size. I would also build a static x86 ffmpeg for the minority of x86 androids out there. Then you can detect the device architecture with the shell command "uname -a" and pick which one to use.

Hope this helps!

jan
  • 336
  • 1
  • 4
  • 1
    Thank you for your answer! Is there any way to convert with Android API? If it is possible, I want to avoid using ffmpeg because of ffmpeg's license issue and porting. When I used ffmepg for handling a video, some devices had troubles. – Storm Nov 19 '14 at 01:50
  • can you upload your ffmpeg lib for x86? – xtr Jan 29 '15 at 05:49