7

i want to convert the sdcard images into video in android.After many of searching i found it is possible in javacv.when i try simple javacv sample in pure java,its working perfectly in my eclipse.but when i turn into android,the same sample does not run in android.i download and add all the .jar files and .so files in myproject->libs/armeabi folder.my project doesn't show any errors.but error occcured during the runtime.

i try with this class,

package com.example.ndkfoo_sample;

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.cpp.opencv_core.IplImage;

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

public class MainActivity extends Activity {

//  @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
IplImage img=cvLoadImage("helloworld.jpg");

    cvShowImage("/mnt/sdcard/helloworld",img);
    cvSmooth(img,img,CV_GAUSSIAN,13);
    cvShowImage("Blur-Image",img);
    cvWaitKey();
    cvReleaseImage(img);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
}

My error is like as,

  opencv error unspecified error.

My question is how to integrate opencv/javacv in android.is there any steps or tutorials.?

thanks,

rams
  • 273
  • 1
  • 5
  • 13
  • can you please put the code for more guidance because i have same problem occure. – jack Jul 07 '15 at 12:37
  • Can you please me list me the jars that you used in your project for javacv ? I am using android studio so everything is new to me. – San Oct 12 '15 at 08:30

1 Answers1

9

Use the following lines .

**

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(image[x]);
       }
       recorder.stop();
    }
    catch (Exception e){
       e.printStackTrace();
    }

** This is supported by javacv library. for more details read Javacv Readme.txt file. Hope this will help you.

itsrajesh4uguys
  • 4,610
  • 3
  • 20
  • 31
  • did u got video from images without green color? – rams Nov 30 '12 at 10:26
  • 1
    hi tried your answer.i am getting error in this line,recorder.setCodecID(CODEC_ID_MPEG1VIDEO); error:CODEC_ID_MPEG1VIDEO can't be resolved to a variable. – rams Nov 30 '12 at 13:24
  • for that you need to use javacv.jar and javacpp.jar files in your lib folder.. import from that jar files.. – itsrajesh4uguys Nov 30 '12 at 14:30
  • Experiment with other codecs: `CODEC_ID_MPEG4` followed by `recorder.setFormat("mp4");` – karlphillip Dec 01 '12 at 11:02
  • @karlphillip yeah i have checked with both of them also.. it will create a file but i didn't got a perfect video file.. – itsrajesh4uguys Dec 03 '12 at 07:24
  • thanks,i got the correct video from set of images.then how to add audio to that generated video? – rams Dec 07 '12 at 05:53
  • no rams.. for that we have options in Ffmpegrecorder.java but need to get the author advice . so please proceed with that and let me know.. – itsrajesh4uguys Dec 07 '12 at 07:06
  • If managed to obtain the video, could you please share with us a link to a miniproject? – Duna Mar 27 '13 at 15:58
  • @Lunatikul please have a look at this app. https://play.google.com/store/apps/details?id=com.rajesh.capture&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5yYWplc2guY2FwdHVyZSJd – itsrajesh4uguys Mar 28 '13 at 05:27
  • i mean with un rooted devices. – Duna Mar 31 '13 at 16:55
  • you can make video from images with unrooted devices also. – itsrajesh4uguys Apr 18 '13 at 06:05
  • `for (int i=0;i<100;i++)` What is the significance of 100 here? Why loop it 100 times? – Abhishek V Oct 22 '13 at 18:21
  • cvLoadImage() function showing error even after adding all the jar files correctly also recorder.setCodecID(CODEC_ID_MPEG4) also showing error – Vivek Singh Dec 04 '13 at 08:59
  • Hi , I know it is too late to comment on this post . Please Guide what should i import so that CODEC_ID_MPEG1VIDEO and PIX_FMT_YUV420P stop giving me error. I added javacv.jar and javacpp.jar in libs folder – Amarjit Jul 13 '14 at 17:20
  • I obtained all the jars and .so files from http://javacv4android.blogspot.ae/2014/02/how-to-import-javacv-libraries-to.html. Please take a look at it,its official documentation. – San Oct 12 '15 at 10:34
  • @itsrajesh4uguys, can you please post a completely working code ? I am able to create a video but nothing plays in it, it just says "Cant play this file" and the size is just 258 bytes !! I am not sure what I am missing but it will be highly helpful if you could just assist me. Thanks in advance. – San Oct 12 '15 at 10:37