错误:CODEC_ID_MPEG1VIDEO无法解析为变量javacv

时间:2014-07-09 08:48:02

标签: android javacv

我正在尝试从android中的图像列表创建视频我正在使用此代码: package com.example.videotest;

import static com.googlecode.javacv.cpp.avcodec.AV_CODEC_ID_MPEG4;
import static com.googlecode.javacv.cpp.avutil.AV_PIX_FMT_YUV420P;
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage;

import java.util.ArrayList;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.googlecode.javacv.FFmpegFrameRecorder;
import com.googlecode.javacv.FrameRecorder.Exception;
import com.googlecode.javacv.cpp.opencv_core;

public class MainActivity extends Activity implements OnClickListener {

    Button start;
    ArrayList<Bitmap>images=new ArrayList<Bitmap>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        start=(Button)findViewById(R.id.start);
        start.setOnClickListener(this);

    }

    public void videoRecorder() throws Exception
    {


        opencv_core.IplImage img = cvLoadImage("/sdcard/Pictures/Boat.jpg");
        FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("/sdcard/DCIM/test4.mp4",200,150);

            try {
                recorder.setVideoCodec(CODEC_ID_MPEG4);

               recorder.setFrameRate(30);
               recorder.setPixelFormat(PIX_FMT_YUV420P);
               recorder.start();

               for (int i=0;i<100;i++)
               {
                  recorder.record(img);
               }
               recorder.stop();
            }
            catch (Exception e){
               e.printStackTrace();
            }
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if(v.getId()==R.id.start)
        {
            try {
                videoRecorder();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }


    }



}

但我得到的CODEC_ID_MPEG1VIDEO无法解析为变量

我应该导入什么?如果我想使用位图图像而不是从SD卡加载我怎样才能在javacv中执行此操作?

1 个答案:

答案 0 :(得分:0)

您的意思是CODEC_ID_MPEG1VIDEO无法解决或CODEC_ID_MPEG4

CODEC_ID_MPEG4PIX_FMT_YUV420P无法解决,我只是添加:

import static com.googlecode.javacv.cpp.avcodec.*;

并更改CODEC_ID_MPEG4PIX_FMT_YUV420P AV_CODEC_ID_MPEG4AV_PIX_FMT_YUV420P

希望有所帮助!