GithubHelp home page GithubHelp logo

Comments (7)

saudet avatar saudet commented on June 10, 2024

Looks like a bug in Android 4.0: https://code.google.com/p/android/issues/detail?id=24327

So if you cannot update to 4.1 at least, it looks like the workaround is to recreate the buffers you are using, in Java.

from javacpp.

szitguy avatar szitguy commented on June 10, 2024

@aydinkn I get the same problem. Do you use FFmpegFrameFilter?
On Android4.0.4, I removed FFmpegFrameFilter process code, and it worked, but certainly no more crop process.

from javacpp.

aydinkn avatar aydinkn commented on June 10, 2024

@szitguy my application need FFmpegFrameFilter (for transpose). I changed application min android version to >= 4.1 for now.

from javacpp.

szitguy avatar szitguy commented on June 10, 2024

@aydinkn OK, but my app still want to support from Android4.0.
I am trying to find some way to fix it.

from javacpp.

szitguy avatar szitguy commented on June 10, 2024

@aydinkn I fixed the problem just now, i modified the "pull" method of class FFmpegFrameFilter, here is my "pull" code(look at the line writing "if (SystemVersionUtil.hasJellyBean())"):

public Frame pull() throws Exception {
    av_frame_unref(filt_frame);

    /* pull a filtered frame from the filtergraph */
    int ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
    if (ret == -11 /*AVERROR(EAGAIN)*/ || ret == AVERROR_EOF) {
        return null;
    } else if (ret < 0) {
        throw new Exception("av_buffersink_get_frame(): Error occurred: "
                + av_make_error_string(new BytePointer(256), 256, ret).getString());
    }
    frame.imageWidth  = filt_frame.width();
    frame.imageHeight = filt_frame.height();
    frame.imageDepth = Frame.DEPTH_UBYTE;
    if (filt_frame.data(1) == null) {
        frame.imageStride = filt_frame.linesize(0);
        BytePointer ptr = filt_frame.data(0);
        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;
    } else {
        frame.imageStride = frame.imageWidth;
        int size = avpicture_get_size(filt_frame.format(), frame.imageWidth, frame.imageHeight);
        // Fix bug on Android4.0,check out https://github.com/bytedeco/javacpp/issues/39
        if (SystemVersionUtil.hasJellyBean()) {
            if (image_ptr[0] == null || image_ptr[0].capacity() < size) {
                image_ptr[0] = new BytePointer(size);
                image_buf[0] = image_ptr[0].asBuffer();
            }
            frame.image = image_buf;
            frame.image[0].position(0).limit(size);
            frame.imageChannels = 2;
            ret = avpicture_layout(new AVPicture(filt_frame), filt_frame.format(),
                    frame.imageWidth, frame.imageHeight, image_ptr[0].position(0), image_ptr[0].capacity());
        } else {
            if (image_buf[0] == null || image_buf[0].capacity() < size) {
                image_buf[0] = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
            }
            frame.image = image_buf;
            frame.image[0].position(0).limit(size);
            frame.imageChannels = 2;
            ret = avpicture_layout(new AVPicture(filt_frame), filt_frame.format(),
                    frame.imageWidth, frame.imageHeight, (ByteBuffer) frame.image[0].position(0), frame.image[0].capacity());
        }
    }
    return frame;
}

from javacpp.

saudet avatar saudet commented on June 10, 2024

@szitguy Your fix looks to me, no need to keep the old code around. So, remove the SystemVersionUtil.hasJellyBean() check that doesn't work on Java SE anyway, and send me a pull request. I'll merge that in, thanks!

from javacpp.

szitguy avatar szitguy commented on June 10, 2024

@saudet OK!

from javacpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.