2014-12-01 4 views
1

여러 mp4 파일을 하나로 결합해야하는 앱에서 https://github.com/hiteshsondhi88/ffmpeg-android-java을 사용하고 있습니다. 여기 안드로이드에서 FFmpeg로 mp4 파일을 병합 할 수 없습니다.

는 명령을 파일을 추가 할

ffmpeg -i concat:"/data/data/com.testapp.app/cache:temp/lds82df9skov65i15k3ct16cik.mp4|/data/data/com.testapp.app/cache:temp/qm5s0utmb8c1gbhch6us2tnilo.mp4" -codec copy /data/data/com.testapp.app/cache:temp/4egqalludvs03tnfleu5dgb6iv.mp4 

자바 방법, 동영상 파일 인 배열 잡고 파일 내가

public void appendFiles() { 

    showProgressDialog(); 

    movieFile = getRandomFile(); 

    StringBuilder b = new StringBuilder(); 

    try { 

     for (int i = 0; i < movieFiles.size(); i++) { 

      File f = movieFiles.get(i); 

      if (!f.exists()) { 
       continue; 
      } 

      if(i != 0){ 
       b.append("|"); 
      } 

      b.append(f.getPath()); 


     } 

     final String command = "-i concat:\""+b.toString() + "\" -codec copy " + movieFile.getPath(); 



     try { 
      ffmpeg.execute(command, new ExecuteBinaryResponseHandler() { 
       @Override 
       public void onFailure(String s) { 
        app.log("FAILED with output : " + s); 
       } 

       @Override 
       public void onSuccess(String s) { 
        app.log("SUCCESS with output : " + s); 

        createThumbnail(); 

        stopProgressDialog(); 

        startReview(); 
       } 

       @Override 
       public void onProgress(String s) { 
        app.log("Started command : ffmpeg " + command); 

       } 

       @Override 
       public void onStart() { 

        app.log("Started command : ffmpeg " + command); 

       } 

       @Override 
       public void onFinish() { 
        app.log("Finished command : ffmpeg " + command); 

       } 
      }); 
     } 
     catch (FFmpegCommandAlreadyRunningException e) { 
      e.printStackTrace(); 
     } 


    } 

    catch (Exception e) { 
     e.printStackTrace(); 
    } 

} 

및 getRandomFile()

public File getRandomFile() { 
     if (captureDir != null) { 
      if (captureDir.exists()) { 

       SecureRandom random = new SecureRandom(); 
       File file = new File(captureDir, new BigInteger(130, random).toString(32) + ".mp4"); 
       return file; 
      } 
     } 
     return null; 
    } 

을 결합하려는 것입니다 하지만 그 파일이나 디렉토리에 오류가 나타나지 않습니다.

concat : "/ data/data/com.testapp.app/cache : temp/lds82df9skov65i15k3ct16cik.mp4 | /data/data/com.testapp.app/cache : temp/qm5s0utmb8c1gbhch6us2tnilo.mp4": 해당 파일이나 디렉토리가 없습니다.

어떤 아이디어가 있습니까?

+0

작동하도록 만들었습니까? –

답변

0

방금이 문제를 해결했습니다. 명령

ffmpeg -i "concat:file1.mp4|file2.mp4" 

은 작동하지 않습니다. 파일 목록을 텍스트 파일로 저장 한 다음 발포해야합니다.

ffmpeg -f concat -i list.txt -c:v copy -c:a copy result.mp4 

시도해보십시오. 동일한 라이브러리를 사용하고있었습니다.

1

다음 명령을 사용할 수 있습니다. 는 FFmpeg -f CONCAT -i List.txt 파일 -c : -c V 복사 : 복사 result.mp4

하지만 당신은 다음

file '/sdcard/blabla/v0.mp4' 
file '/sdcard/blabla/v1.mp4' 
file '/sdcard/blabla/v2.mp4' 

처럼 List.txt 파일 파일에서 파일의 전체 경로를 저장할 경우 -safe 0 플래그를 추가해야합니다.

String[] cmd = new String[]{"-f", "concat", "-safe", "0", "-i", "list.txt", "-c", "copy", "-preset", "ultrafast", outFile}; 

ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() 
{ 

    @Override 
    public void onFailure(String message) 
    { 
    } 
    @Override 
    public void onSuccess(String message) 
    { 
    } 
    @Override 
    public void onProgress(String message) 
    { 
    } 

    @Override 
    public void onStart() 
    { 
    } 

    @Override 
    public void onFinish() 
    { 
    } 
} 
0

아주 늦게 : 당신이 사용하는 라이브러리에

ffmpeg -f concat -safe 0 -i list.txt -c:v copy -c:a copy result.mp4 

그리고 사용법은 비슷하지만이 개념은 문제에 대한 해결책을 추구하는 사람에게 도움이 될 수 있습니다.
두 가지 비디오의 샘플 속도와 프레임 속도가 서로 다를 수 있습니다. 따라서 먼저 동일한 비율로 변환하거나 코드 변환해야합니다. 그러면 각 동영상을 연결할 수 있습니다.

관련 문제