带有 fr 和分辨率操作的 Android 视频编码 [英] Android video encoding with fr and resolution manipulation

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

问题描述

我希望能够拍摄用 Android 设备录制的视频,并使用我的应用将其编码为新的分辨率和帧速率.目的是上传比原始视频小得多的版本(大小),因为这将是 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.)

但是,我使用了这个优秀的库 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 input -s 480X320 -r 30 -vcodec libx264 -acodec copy output

The function processVideo produces a command similar to ffmpeg -i input -s 480X320 -r 30 -vcodec libx264 -acodec copy output

这是一个非常简单的例子,但它输出了由 ffmpeg 桌面完成的相同类型的转换.这些代码需要大量的工作!希望对大家有帮助.

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 和分辨率操作的 Android 视频编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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