Ejemplo n.º 1
0
 private boolean ffmpegIsCorrectlyInstalled() {
   File ffmpegTargetLocation = AndroidFFMPEGLocator.ffmpegTargetLocation();
   // assumed to be correct if existing and executable and larger than 1MB:
   return ffmpegTargetLocation.exists()
       && ffmpegTargetLocation.canExecute()
       && ffmpegTargetLocation.length() > 1000000;
 }
Ejemplo n.º 2
0
 private void unpackFFmpeg(AssetManager assetManager, String ffmpegAssetFileName) {
   InputStream inputStream = null;
   OutputStream outputStream = null;
   try {
     File ffmpegTargetLocation = AndroidFFMPEGLocator.ffmpegTargetLocation();
     inputStream = assetManager.open(ffmpegAssetFileName);
     outputStream = new FileOutputStream(ffmpegTargetLocation);
     byte buffer[] = new byte[1024];
     int length = 0;
     while ((length = inputStream.read(buffer)) > 0) {
       outputStream.write(buffer, 0, length);
     }
     // makes ffmpeg executable
     ffmpegTargetLocation.setExecutable(true);
     Log.i(
         TAG,
         "Unpacked ffmpeg binary "
             + ffmpegAssetFileName
             + " , extracted  "
             + ffmpegTargetLocation.length()
             + " bytes. Extracted to: "
             + ffmpegTargetLocation.getAbsolutePath());
   } catch (IOException e) {
     e.printStackTrace();
   } finally {
     // cleanup
     try {
       if (inputStream != null) {
         inputStream.close();
       }
     } catch (IOException e) {
       e.printStackTrace();
     }
     try {
       if (outputStream != null) {
         outputStream.close();
       }
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }
Ejemplo n.º 3
0
  public AndroidFFMPEGLocator(Context context) {
    CPUArchitecture architecture = getCPUArchitecture();

    Log.i(TAG, "Detected Native CPU Architecture: " + architecture.name());

    if (!ffmpegIsCorrectlyInstalled()) {
      String ffmpegFileName = getFFMPEGFileName(architecture);
      AssetManager assetManager = context.getAssets();
      unpackFFmpeg(assetManager, ffmpegFileName);
    }
    File ffmpegTargetLocation = AndroidFFMPEGLocator.ffmpegTargetLocation();
    Log.i(
        TAG,
        "Ffmpeg binary location: "
            + ffmpegTargetLocation.getAbsolutePath()
            + " is executable? "
            + ffmpegTargetLocation.canExecute()
            + " size: "
            + ffmpegTargetLocation.length()
            + " bytes");
  }