2016-06-01 45 views
0

使用FFMPEG android java庫處理視頻異常播放速度(使視頻變慢)後發生異常。編碼器'aac'在處理視頻時不啓用異常處理速度緩慢

[aac @ 0x416c26f0] The encoder 'aac' is experimental but experimental codecs are not enabled, add '-strict -2' if you want to use it. 
+0

您使用的ffmpeg的舊版本。添加'-strict -2' – Mulvya

+0

在哪裏添加它?在命令? –

+0

是的,在命令。 – Mulvya

回答

0

這裏是改變速度

VideoIn = getInternalDirectoryPath() + "/Download/input.mp4"; 
VideoOut = getInternalDirectoryPath() + "/Download/output.mp4"; 
cmd = "-i "+VideoIn+" -vf setpts=2*PTS -strict -2 "+VideoOut; 

在命令避免編碼器「AAC」添加-strict的重放的命令不啓用異常。你可以按照這個鏈接來實現ffmpeg視頻命令。

下面是完整的示例代碼

public class TestFFMpegActivity { 
     private static String cmd, 
     private static FFmpeg ffmpeg; 
     private static Context mContext; 


     public static String getInternalDirectoryPath() { 
      return Environment.getExternalStorageDirectory().getAbsolutePath(); 
     } 

     public static void initiateFFmpeg(Context context, String path) { 
      mContext = context; 
      ffmpeg = FFmpeg.getInstance(context); 
      VideoIn = getInternalDirectoryPath() + "/Download/input.mp4"; 
      VideoOut = getInternalDirectoryPath() + "/Download/output.mp4"; 
      cmd = "-i "+VideoIn+" -vf setpts=2*PTS -strict -2 "+VideoOut; 
      try { 
       ffmpeg.loadBinary(new LoadBinaryResponseHandler() { 

        @Override 
        public void onStart() { 
        } 

        @Override 
        public void onFailure() { 
        } 

        @Override 
        public void onSuccess() { 
        } 

        @Override 
        public void onFinish() { 
         processVideo(); 
        } 
       }); 
      } catch (FFmpegNotSupportedException e) { 
       // Handle if FFmpeg is not supported by device 
      } 
     } 
     private static void processVideo(){ 
     try { 
      ffmpeg.execute(cmd , 
        new ExecuteBinaryResponseHandler() { 

         @Override 
         public void onStart() { 
          //for logcat 
          Log.w(null,"processing started"); 
         } 

         @Override 
       public void onProgress(String message) { 
        //for logcat 
        Log.w(null, "onProgress"); 
       } 

       @Override 
       public void onFailure(String message) { 
        Log.w(null, message.toString()); 
       } 

       @Override 
       public void onSuccess(String message) { 
        Log.w(null, message.toString()); 
       } 

       @Override 
       public void onFinish() { 

       } 
      }); 
     } catch (FFmpegCommandAlreadyRunningException e) { 
      Toast.makeText(mContext, "Video processing failed due to exception", Toast.LENGTH_LONG).show(); 

      // Handle if FFmpeg is already running 
      e.printStackTrace(); 
      Log.w(null, e.toString()); 
     } 
    } 
}