sawpawan / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

Can i use JavaCV make a Mirror from video #354

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

In android, use the front camera, preview the video and recorded video is not 
the same,
preview is record'Mirror.
and now i want to use JavaCV, get video's Mirror. What can I do, please help 
me, thank you

Original issue reported on code.google.com by kukudete...@gmail.com on 19 Aug 2013 at 4:31

GoogleCodeExporter commented 8 years ago
Does cvFlip() do what you need?

Original comment by samuel.a...@gmail.com on 28 Aug 2013 at 9:58

GoogleCodeExporter commented 8 years ago
Given the lack of feedback, I'm assuming cvFlip() does the job!

Please post your questions on the mailing list next time if possible, thank you!

Original comment by samuel.a...@gmail.com on 16 Sep 2013 at 11:33

GoogleCodeExporter commented 8 years ago
For the delay, very apologize。
Yes, I have do the Work
Like This:

    public static boolean flipMovie(String in, String out) {

        boolean isSuccess = false;
        // 读视频
        FFmpegFrameGrabber ffmpegframegrabber = null;
        // 写视频
        FFmpegFrameRecorder ffmpegframerecorder = null;

        try {

            ffmpegframegrabber = new FFmpegFrameGrabber(in);
            ffmpegframegrabber.setFormat("mp4");

            ffmpegframerecorder = new FFmpegFrameRecorder(out,
                    ffmpegframegrabber.getImageWidth(),
                    ffmpegframegrabber.getImageHeight(),
                    ffmpegframegrabber.getAudioChannels());

            ffmpegframegrabber.start();

            ffmpegframerecorder.setImageWidth(ffmpegframegrabber.getImageWidth());
            ffmpegframerecorder.setImageHeight(ffmpegframegrabber.getImageHeight());
//          ffmpegframerecorder.setVideoCodec(13);
//          ffmpegframerecorder.setFormat("mp4");
//          ffmpegframerecorder.setPixelFormat(0);
//          ffmpegframerecorder.setVideoBitrate(0x16e360);
//          ffmpegframerecorder.setSampleRate(ffmpegframegrabber.getSampleRate());
//          ffmpegframerecorder.setFrameRate(ffmpegframegrabber.getFrameRate());

            ffmpegframerecorder.setFrameRate(ffmpegframegrabber.getFrameRate()); 
            ffmpegframerecorder.setSampleRate(ffmpegframegrabber.getSampleRate()); 

            ffmpegframerecorder.start();

//          com.googlecode.javacv.Frame frame = ffmpegframegrabber.grabFrame();

            com.googlecode.javacv.cpp.opencv_core.IplImage iplimage = ffmpegframegrabber.grab();

            while (iplimage != null) {

                Log.d("debug", "iplimage != null");
                // 关键,反转
                opencv_core.cvFlip(iplimage, iplimage, 1);
                ffmpegframerecorder.setTimestamp(ffmpegframegrabber.getTimestamp());
                ffmpegframerecorder.record(iplimage);
//              ffmpegframerecorder.record(frame.samples);
//              
//              frame = ffmpegframegrabber.grabFrame();
//              
                iplimage = ffmpegframegrabber.grab();
            }

            isSuccess = true;

            Log.d("debug", "useJar End");

        } catch (Exception e) {

            Log.d("debug", "useJar Exception" + e.getMessage());

            e.printStackTrace();
        } catch (com.googlecode.javacv.FrameRecorder.Exception e) {

            Log.d("debug", "useJar Exception" + e.getMessage());

            e.printStackTrace();
        } finally {

            // 释放资源
            if(ffmpegframegrabber != null) {

                try {
                    ffmpegframegrabber.stop();
                    ffmpegframegrabber.release();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

            // 释放资源
            if(ffmpegframerecorder != null) {

                try {
                    ffmpegframerecorder.stop();
                    ffmpegframerecorder.release();
                } catch (com.googlecode.javacv.FrameRecorder.Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

            return isSuccess;
        }
    }

Original comment by kukudete...@gmail.com on 16 Sep 2013 at 3:16