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

vflip fliter throws an exception on FFmpegFrameFilter #975

Closed
SIY1121 opened this issue Apr 26, 2018 · 3 comments
Closed

vflip fliter throws an exception on FFmpegFrameFilter #975

SIY1121 opened this issue Apr 26, 2018 · 3 comments
Labels

Comments

@SIY1121
Copy link
Contributor

SIY1121 commented Apr 26, 2018

Hi
I have one bug report and question.

I'm using javacv as FFmpeg wrapper.
I received raw video frames and tried to flip frames when encoding, but using vflip fliter throws an exception.

java.lang.IllegalArgumentException
	at java.nio.Buffer.limit(Buffer.java:275)
	at org.bytedeco.javacv.FFmpegFrameFilter.pull(FFmpegFrameFilter.java:359)

On debugging,I identified the cause.
With vflip filter, the imageStride of the frame returned by ffmpeg will be negative.

if (ptr != null && !ptr.equals(image_ptr[0])) {
image_ptr[0] = ptr.capacity(frame.imageHeight * frame.imageStride);
image_buf[0] = ptr.asBuffer();
}
frame.image = image_buf;
frame.image[0].position(0).limit(frame.imageHeight * frame.imageStride);
frame.imageChannels = frame.imageStride / frame.imageWidth;

This process doesn't seem to consider it.
So I changed code to use absolute value and it works fine.

if (ptr != null && !ptr.equals(image_ptr[0])) { 
     image_ptr[0] = ptr.capacity(frame.imageHeight * Math.abs(frame.imageStride)); 
     image_buf[0] = ptr.asBuffer(); 
 } 
 frame.image = image_buf; 
 frame.image[0].position(0).limit(frame.imageHeight *  Math.abs(frame.imageStride)); 
 frame.imageChannels = frame.imageStride / Math.abs(frame.imageWidth);

I didn't use OpenCV flip function because process of converting array to mat and converting it to FFmpeg frame looks inefficiency.
Was it good choice?

Thank you.

@saudet
Copy link
Member

saudet commented Apr 26, 2018 via email

@saudet saudet added the bug label Apr 27, 2018
@saudet
Copy link
Member

saudet commented Apr 30, 2018

Fixed with pull #977, thanks!

@saudet
Copy link
Member

saudet commented Jul 18, 2018

Which has now been integrated in version 1.4.2. Thanks again for the fix!

@saudet saudet closed this as completed Jul 18, 2018
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