如何从base64解码视频? [英] how to decode video from base64?

查看:197
本文介绍了如何从base64解码视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在base64字符串中转换视频所以我通过我在Android中的视频转换migBase64方法它将视频转换为字符串成功但是当我解码字符串到视频然后它没有正确转换视频。所以,如果有人知道,请帮助我。

I want convert video in base64 String so i convert migBase64 Method through my video in android it convert video to string successfully but when i decode String to Video then it not proper converting in video. so please help me if anyone knows.

我尝试如下代码:

      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 kb它没有转换我原来的视频请帮助我。

my problem is decoding string to video, my original video is 1 MB and after decoding video is 1.1 kb it not convert my original video please help me.

推荐答案

我解决了我的问题,我发布了某人帮助的代码。

I solve my problem, i post code for someone help.

//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());

        }

这篇关于如何从base64解码视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆