Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem on using FFmpegFrameFilter to apply Fade In Fade Out effect on video. #928

Closed
wa4663039 opened this issue Feb 26, 2018 · 2 comments
Labels

Comments

@wa4663039
Copy link

wa4663039 commented Feb 26, 2018

Hello,

I am trying to apply the fade in and fade out effect on a video useing FFmpegFrameFilter, however, the FFmpegFrameFilter seems to process individual frame, and I got a totally black video.

Here is a part of my code, would you please advise how to apply a fade in effect correctly? Thanks a lot

FrameRecorder recorder = new FFmpegFrameRecorder(ENV_PATH + "/output" + time + ".mp4", frameGrabbers.get(0).getImageWidth(), frameGrabbers.get(0).getImageHeight());
recorder.setFrameRate(frameGrabbers.get(0).getFrameRate());
recorder.setSampleFormat(frameGrabbers.get(0).getSampleFormat());
recorder.setSampleRate(frameGrabbers.get(0).getSampleRate());
recorder.start();

FFmpegFrameFilter fFmpegFrameFilter = new FFmpegFrameFilter("fade=t=in:st=5.5:d=1",frameGrabbers.get(0).getImageWidth(),frameGrabbers.get(0).getImageHeight());

            fFmpegFrameFilter.start();
            int frameNum = 0;
            for (FrameGrabber fg : frameGrabbers) {

                while ((frame = fg.grabFrame()) != null) {
                    if(frame.image != null) {

                            fFmpegFrameFilter.push(frame);
                            frame = fFmpegFrameFilter.pull();

                        recorder.record(frame);
                        frameNum++;
                    }

                }

                if (k == frameGrabbers.size()) {
                    fg.stop();
                    Log.i(LOG_TAG, "STOP");
                }
            }

fFmpegFrameFilter.stop();
recorder.stop();
recorder.release();
@saudet
Copy link
Member

saudet commented Feb 26, 2018

This has already been answered on the mailing list at
https://groups.google.com/forum/#!topic/javacv/4UDKpdaMHSM :

Ok, then according to the source code of the ffmpeg program at
https://github.com/FFmpeg/FFmpeg/blob/n2.8.4/ffmpeg_filter.c#L773
that command automatically appends a "setpts=N" filter to the graph. So, we can do that with FFmpegFrameFilter as well this way:

filter = new FFmpegFrameFilter("setpts=N,fade=t=in:st=2.5:d=1", ...);

And that works as expected.

@saudet
Copy link
Member

saudet commented Mar 31, 2018

FYI, with the changes in commit 35dd7f8 it's no longer necessary to add the setpts=N filter manually, so please give it a try with JavaCV 1.4.2-SNAPSHOT: http://bytedeco.org/builds/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants