2014-11-10 3 views
2

Я хочу конвертировать видео в base64 String, поэтому я конвертирую метод migBase64 через мое видео в android, чтобы он конвертировал видео в строку успешно, но когда я декодирую String в Video, тогда это не правильно конвертирует в видео. поэтому, пожалуйста, помогите мне, если кто-нибудь знает.как декодировать видео из 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. 

моей проблема декодирование строки видео, мое оригинальное видео 1 MB и после декодирования видео в 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()); 

     } 
Смежные вопросы