Javacv: Some frames lost resolution when merge 2 videos

Created on 20 Apr 2018  Â·  4Comments  Â·  Source: bytedeco/javacv

Hi @saudet, I got an issue when I merged 2 videos. What's wrong there? thank you.

whatsapp image 2018-04-20 at 2 09 11 pm

Input video x2 : https://www.youtube.com/watch?v=MJZe_Awexhw
Result Video: https://www.youtube.com/watch?v=G1kTZyIVwuU


  recorder = new FFmpegFrameRecorder(outputVideo, Constants.FINAL_VIDEO_RESOLUTION_WIDTH, Constants.FINAL_VIDEO_RESOLUTION_HEIGHT, 1);
        recorder.setFormat(Constants.VIDEO_RECORD_FORMAT);
        recorder.setSampleRate(Constants.SAMPLE_AUDIO_RATE_IN_HZ);
        recorder.setFrameRate(VIDEO_FRAME_RATE);
        recorder.setVideoOption("preset", Constants.VIDEO_PRESET);
        recorder.setVideoCodec(VIDEO_CODEC);
        recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
        recorder.setVideoQuality(Constants.VIDEO_QUALITY);
        recorder.setVideoBitrate(Constants.VIDEO_BITRATE);


for (FFmpegFrameGrabber grabber : grabbers) {
                        grabber.start();
                    }

                    recorder.start();
                    totalRecord = 0;

                    for (FFmpegFrameGrabber grabber : grabbers) {
                        Frame frame;

                        while ((frame = grabber.grab()) != null) {
                            recorder.setTimestamp(grabber.getTimestamp() + totalRecord);
                            recorder.record(frame, grabber.getPixelFormat());
                        }

                        totalRecord = totalRecord + grabber.getTimestamp();
                    }

                    recorder.stop();
                    for (FFmpegFrameGrabber grabber : grabbers) {
                        grabber.stop();
                    }
                    recorder.release();


 implementation group: 'org.bytedeco', name: 'javacv', version: '1.4.2-SNAPSHOT'
    implementation group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.4.1-1.4.1', classifier: 'android-arm'
    implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.4.2-1.4.1', classifier: 'android-arm'

question

All 4 comments

Hi @saudet, I checked it works fine in the old version.
Video result: https://www.youtube.com/watch?v=sNcs5L6xGiQ&feature=youtu.be

compile group: 'org.bytedeco', name: 'javacv', version: '1.1'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.1', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.8.1–1.1', classifier: 'android-arm'

Also I got this issues: av_interleaved_write_frame() error -22 while writing interleaved video packet.

Your call to setTimestamp() is incorrect. Remove at least that and see.

It works perfectly. Thank you so much 😄

The video input is H.264 and I need H.264 is output so I set recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
then this issue occurs.

Do you have any solution without remove setTimestamp() because I need setTimestamp() in my case the voice not sync with lips?

It works normally if I don't set output Codec so It's AV_CODEC_ID_NONE and setTimestamp()

Thank in advance, @saudet

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fif10 picture fif10  Â·  3Comments

cansik picture cansik  Â·  4Comments

Bahramudin picture Bahramudin  Â·  3Comments

iamazy picture iamazy  Â·  4Comments

chrisliu12345 picture chrisliu12345  Â·  4Comments