2014-11-10 2 views
2

저는 비디오를 base64 문자열로 변환하려고합니다. 그래서 migBase64 메소드를 안드로이드 내 비디오를 통해 변환합니다. 성공적으로 비디오를 문자열로 변환하지만 비디오에서 문자열을 디코드 할 때 비디오에서 변환이 적절하지 않습니다. 아무도 모른다면 제발 도와주세요.base64에서 비디오를 디코딩하는 방법은 무엇입니까?

내가 다음과 같은 코드를 시도 :

 String encodedString; 

    //Decode Video To String 

      File tempFile = new File(Environment.getExternalStorageDirectory()+ "/my/part/my_0.mp4"); 

       byte fileContent[] = new byte[3000]; 

       try { 
        FileInputStream fin = new FileInputStream(tempFile); 
        while (fin.read(fileContent) >= 0) { 

         // b.append(Base64.encodeToString(fileContent, true)); 

         encodedString = Base64.encodeToString(fileContent, true); 

        } 
       } catch (IOException e) { 

       } 
//Encoding Video To String Successfully. 

//Decode String To Video 

    try { 

      byte[] decodedBytes = Base64.decodeF 
      File file2 = new File(Environment.getExternalStorageDirectory() 
        + "/my/Converted.mp4"); 
      FileOutputStream os = new FileOutputStream(file2, true); 
      os.write(decodedBytes); 
      os.close(); 

     } catch (Exception e) { 
      // TODO: handle exception 
      Log.e("Error", e.toString()); 
     } 
// Problem is in Decoding. 

내 문제는 비디오에 문자열을 디코드, 내 원래 비디오는 1MB입니다 및 비디오를 디코딩 한 후 1.1 킬로바이트입니다 내 원본 비디오가 저를 도와주세요 변환하지.

+0

비디오 처리를 위해 ffmpeg를 사용하십시오. –

+0

예가 있습니까? – Rajneesh

+0

이 https://github.com/churnlabs/android-ffmpeg-sample –

답변

5

나는 내 문제를 해결하고 누군가를위한 코드를 게시합니다.

//Encode Video To String With mig Base64. 

    File tempFile = new File(Environment.getExternalStorageDirectory() 
       + "/my/part/my_0.mp4"); 
     String encodedString = null; 

     InputStream inputStream = null; 
     try { 
      inputStream = new FileInputStream(tempFile); 
     } catch (Exception e) { 
      // TODO: handle exception 
     } 
     byte[] bytes; 
     byte[] buffer = new byte[8192]; 
     int bytesRead; 
     ByteArrayOutputStream output = new ByteArrayOutputStream(); 
     try { 
      while ((bytesRead = inputStream.read(buffer)) != -1) { 
       output.write(buffer, 0, bytesRead); 
      } 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     bytes = output.toByteArray(); 
     encodedString = Base64.encodeToString(bytes, true); 
     Log.i("Strng", encodedString); 


//Decode String To Video With mig Base64. 
     byte[] decodedBytes = Base64.decodeFast(encodedString.getBytes()); 

     try { 

      FileOutputStream out = new FileOutputStream(
        Environment.getExternalStorageDirectory() 
          + "/my/Convert.mp4"); 
      out.write(decodedBytes); 
      out.close(); 
     } catch (Exception e) { 
      // TODO: handle exception 
      Log.e("Error", e.toString()); 

     } 
관련 문제