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

Question: How to generate palette by Javacv/FFmpeg-FFmpegFrameFilter? #287

Closed
zhengxuzeng opened this issue Dec 5, 2015 · 8 comments
Closed

Comments

@zhengxuzeng
Copy link

from the FFmpeg documentation:

Generate a representative palette of a given video using ffmpeg:
ffmpeg -i input.mkv -vf palettegen palette.png

What I have done:

FFmpegFrameFilter paletteFilter = new FFmpegFrameFilter ("palettegen", iamgeWidth, iamgeHeight);
Frame frame;
Frame frame_get;
//...init Frame frame...
//...platteFilter start...
while(//...)
{
//...get frames...
paletteFilter.push(frame);
frame_get = paletteFilter.pull();
}
//...

Here I guess I could get the palette by frame_get, however, what I get is null.
The code above is just to test. I want to know how to generate palette from each frame of video stream and from the whole video stream. Also, how to program to use the palette as command below:

ffmpeg -i input.mkv -i palette.png -lavfi paletteuse output.gif

Is there any way to learn about programming of JavaCV/FFmpeg?
Or if you know anything about that, please help me.

@saudet
Copy link
Member

saudet commented Dec 5, 2015

It looks like it's expecting us to call some function before we can pull the result. I wonder which function that is...

Documentation for FFmpeg is available here: https://ffmpeg.org/documentation.html

There isn't a lot available for JavaCV I'm afraid, so if this is something you'd like to work on it would be very welcome. Reading FFmpeg's documentation should help with that. Let me know if you have other questions that I might be able to answer, thanks!

@zhengxuzeng
Copy link
Author

@saudet Got it. I'll try my best to help.

saudet added a commit that referenced this issue Dec 6, 2015
…required by some filters like "palettegen" (issue #287)

 * Call `cvHaarDetectObjects()` with `CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH` instead of `CV_HAAR_DO_CANNY_PRUNING` in the face detection samples to get acceptable performance with OpenCV 3.0 (issue #272)
@saudet
Copy link
Member

saudet commented Dec 6, 2015

It should now work with the commit above by calling push(null) before pull(). Let me know that it works, and thanks for reporting!

@zhengxuzeng
Copy link
Author

@saudet It works.I got the 16*16 Frame from pull(). Thanks!!

Could you tell me that how do you learn the usage below

// indicate EOF as required, for example, by the "palettegen" filter
      av_buffersrc_add_frame_flags(buffersrc_ctx, null, 0);

from Documentation for FFmpeg https://ffmpeg.org/documentation.html ?
Did you do anything else to learn that? For example,did you debug the FFmpeg of PC platform to learn how does it work? Is it efficient?
Maybe it's a strange question because I'm a freshman of programming. I want to learn how to learn and do something helpful.Thanks.(╯▽╰)

@saudet
Copy link
Member

saudet commented Dec 6, 2015

It's not part of the documentation. I just saw from the code at
https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/vf_palettegen.c#L499
that it outputs something only when the input returns AVERROR_EOF.

@saudet
Copy link
Member

saudet commented Dec 6, 2015

And av_buffersrc_add_frame_flags() itself comes with documentation comments that explain how to generate an EOF:
https://github.com/FFmpeg/FFmpeg/blob/624057df3fd5b0044eeed94d2b8e14105b8944dc/libavfilter/buffersrc.h#L105

@zhengxuzeng
Copy link
Author

I see! Thanks. I'm trying to learn how to use "paletteuse" filter.I will report if I found something useful. I hope it could help.

@saudet
Copy link
Member

saudet commented Jan 18, 2018

Thanks! The fix is now included in JavaCV since version 1.2.

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

No branches or pull requests

2 participants