在CODEC_ID_MPEG1VIDEO和PIX_FMT_YUV420P中收到错误

时间:2014-12-27 20:10:46

标签: java android javacv

我正在尝试创建一个将图像转换为视频的代码。我已经浏览了很多,并找到了一些方法来使用javacv。现在我在这些行中得到变量未找到错误。

recorder.setCodecID( CODEC_ID_MPEG1VIDEO);
recorder.setPixelFormat(  PIX_FMT_YUV420P);

我已将所有jar文件导入到我的库中,但仍然出现此错误。一些快速帮助将不胜感激。我已经通过以下链接将javacv导入我的工作区。

How to Import JavaCV libraries to Android Project

package com.example.photoaday;

import static com.googlecode.javacv.cpp.opencv_core.cvReleaseImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvShowImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvWaitKey;
import static com.googlecode.javacv.cpp.opencv_imgproc.CV_GAUSSIAN;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvSmooth;

import com.googlecode.javacv.FFmpegFrameRecorder;
import com.googlecode.javacv.cpp.opencv_core;
import com.googlecode.javacv.cpp.opencv_core.IplImage;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class Recordvideo extends Activity {

//  @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.create);
    opencv_core.IplImage img = cvLoadImage("/sdcard/folder/img1.jpg");
    FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("/sdcard/folder/test.mpeg",200,150);
    try {
        recorder.setCodecID( CODEC_ID_MPEG1VIDEO);
        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();
     }
}


}

1 个答案:

答案 0 :(得分:-1)

我假设你的编译器给出了如下错误

错误:未在此范围内声明“CODEC_ID_MPEG1VIDEO”

错误:未在此范围内声明'PIX_FMT_YUV420P'

然后解决错误是

更改:'CODEC_ID_MPEG1VIDEO'到'AV_CODEC_ID_MPEG1VIDEO'

更改:'PIX_FMT_YUV420P'为'AV_PIX_FMT_YUV420P'