与FR和分辨率操作的Andr​​oid视频编码 [英] Android video encoding with fr and resolution manipulation

查看:260
本文介绍了与FR和分辨率操作的Andr​​oid视频编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够把录制的Andr​​oid设备和连接code它的视频使用我的应用程序一个新的分辨率和帧速率。目的是要上传的原始视频(大小)的一个更小的版本,因为这将是视频30分钟长或更长。

I want to be able to take a video recorded with an Android device and encode it to a new Resolution and Frame Rate using my app. The purpose is to upload a much smaller version of the original video (in size), since this will be videos 30 min long or more.

到目前为止,我读过的人说,FFmpeg的是他们的路要走。然而,文档似乎缺乏

So far, I've read of people saying FFmpeg is they way to go. However, the documentation seems to be lacking.

我也考虑使用HTTP的OpenCV http://opencv.org/platforms/android.html

I have also considered using http opencv http://opencv.org/platforms/android.html

考虑到我需要处理的视频分辨率和帧速率,哪一种工具,你认为可以做这样的事情做得更好?是否有任何其他技术来考虑?

Considering I need to manipulate the video resolution and frame rate, which tool do you think can do such things better? Are there any other technologies to consider?

这是重要的问题是,因为这将是漫长的影片,它是合理的做编码在Android设备(考虑电力资源,时间,等等。)

An important question is, since this will be long videos, is it reasonable to do the encoding in an android device (Consider power resources, time, etc.)

在此先感谢!

推荐答案

我决定使用的ffmpeg来解决这个项目。经过反复研究和试验,我是不是能够建立的ffmpeg的库(使用Ubuntu 14.04 LTS。)

I decided to use ffmpeg to tackle this project. After much researching and trials, I was not able to build ffmpeg for library (using Ubuntu 14.04 LTS.)

不过,我用这个优秀的库<一href="https://github.com/guardianproject/android-ffmpeg-java">https://github.com/guardianproject/android-ffmpeg-java 我刚刚创建了一个项目,并补充说,图书馆和它的工作原理就像一个魅力。无需借助Android NDK建立自己的文件或混乱。当然,你仍然需要建立自己的图书馆,如果你想定制。但它有我需要的一切。

However, I used this excellent library https://github.com/guardianproject/android-ffmpeg-java I just created a project and added that library and it works like a charm. No need to build your own files or mess with the Android NDK. Of course you would still need to build the library yourself if you want to customize it. But it has everything I need.

下面是我如何用于降低视频分辨率和改变帧速率的例子:

Here is an example of how I used to lower a video resolution and change the frame rate:

                    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // input source
            final Clip clip_in = new Clip("/storage/emulated/0/Developer/test.mp4"); 

            Activity activity = (Activity) MainActivity.this;
            File fileTmp = activity.getCacheDir(); 
            File fileAppRoot = new File(activity.getApplicationInfo().dataDir);

            final Clip clip_out = new Clip("/storage/emulated/0/Developer/result2.mp4");
            //put flags in clip
            clip_out.videoFps = "30";
            clip_out.width = 480;
            clip_out.height = 320;
            clip_out.videoCodec = "libx264";
            clip_out.audioCodec = "copy";

            try {
                FfmpegController fc = new FfmpegController(fileTmp, fileAppRoot);
                fc.processVideo(clip_in, clip_out, false, new ShellUtils.ShellCallback() {

                    @Override
                    public void shellOut(String shellLine) {
                        System.out.println("MIX> " + shellLine);
                    }

                    @Override
                    public void processComplete(int exitValue) {

                        if (exitValue != 0) {
                            System.err.println("concat non-zero exit: " + exitValue);
                            Log.d("ffmpeg","Compilation error. FFmpeg failed");
                            Toast.makeText(MainActivity.this, "result: ffmpeg failed", Toast.LENGTH_LONG).show();
                        } else {
                            if(new File( "/storage/emulated/0/Developer/result2.mp4").exists()) {
                                Log.d("ffmpeg","Success file:"+ "/storage/emulated/0/Developer/result2.mp4");
                            }
                        }
                    }
                });
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            // automated try and catch
            setContentView(R.layout.activity_main);
        }
    }

功能 processVideo 产生类似于的ffmpeg -i输入-s -r 480X320 30 -v codeC libx264 -a $命令C $ CC复印输出

这是一个很简单的例子,但它输出的同种转换由ffmpeg的桌面完成。这个C $ CS $需要大量的工作!我希望它能帮助任何人。

This a very simple example, but it outputted the same kind of conversion done by ffmpeg desktop. This codes needs lots of work! I hope it helps anyone.

这篇关于与FR和分辨率操作的Andr​​oid视频编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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