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

FFmpegFrameGrabber.start() causes jvm to crash #1793

Closed
yangxinbo opened this issue Apr 7, 2022 · 5 comments
Closed

FFmpegFrameGrabber.start() causes jvm to crash #1793

yangxinbo opened this issue Apr 7, 2022 · 5 comments

Comments

@yangxinbo
Copy link

Parse the video file and get the first frame

use version

<dependency> <groupId>org.bytedeco</groupId> <artifactId>javacv-platform</artifactId> <version>1.5.7</version> </dependency>

use

`java
{
FFmpegFrameGrabber ff = new FFmpegFrameGrabber(inputStream);

    // frame对象
    Frame frame = null;

    // 标识
    int flag = 0;

    // 默认高
    int imageHeight = 1080;

    // 默认宽
    int imageWidth = 1920;

    // 时长
    long duration = 0;

    // 临时文件
    File tempFile = null;

    try {

        ff.startUnsafe();

        // 总帧数
        int ftp = ff.getLengthInFrames();
        duration = ff.getLengthInTime() / 1000000;
        imageHeight = ff.getImageHeight();
        imageWidth = ff.getImageWidth();
        log.info("[parseVideoInfo] ftp{},duration:{},imageHeight:{},imageWidth:{}", ftp, duration, imageHeight, imageWidth);

        while (flag <= ftp) {

            // 获取帧
            frame = ff.grabImage();

            if (frame == null) {
                break;
            }

            // 当为第30帧时,保存
            if (flag == 30) {
                //创建BufferedImage对象
                Java2DFrameConverter converter = new Java2DFrameConverter();
                BufferedImage bufferedImage = converter.getBufferedImage(frame);

                // 创建临时文件保存
                tempFile = File.createTempFile("tmp/cover/", IdUtils.id() + ".jpg");
                ImageIO.write(bufferedImage, "jpg", tempFile);
                break;
            }
            flag++;
        }
    } catch (Exception e) {
        log.info("[parseVideoInfo] errorMsg={}", e.getMessage(), e);
    } finally {
        try {
            ff.stop();
            ff.releaseUnsafe();
        } catch (FrameGrabber.Exception e) {
            e.printStackTrace();
        }
    }
    return ResourceDefinition.builder()
            .height(imageHeight)
            .width(imageWidth)
            .duration((int) duration)
            .tempFile(tempFile)
            .build();
}

`

crash log

A fatal error has been detected by the Java Runtime Environment:

SIGSEGV (0xb) at pc=0x000000000000d1f6, pid=1, tid=0x00007f4df84f0b10

JRE version: OpenJDK Runtime Environment (8.0_212-b04) (build 1.8.0_212-b04)

Java VM: OpenJDK 64-Bit Server VM (25.212-b04 mixed mode linux-amd64 compressed oops)

Derivative: IcedTea 3.12.0

Distribution: Custom build (Sat May 4 17:33:35 UTC 2019)

Problematic frame:

C 0x000000000000d1f6

Core dump written. Default location: /home/deploy/core or core.1

If you would like to submit a bug report, please include

instructions on how to reproduce the bug and visit:

https://icedtea.classpath.org/bugzilla

The crash happened outside the Java Virtual Machine in native code.

See problematic frame for where to report the bug.

--------------- T H R E A D ---------------

Current thread (0x000055eaf44d4800): JavaThread "http-nio-9090-exec-8" daemon [_thread_in_native, id=590, stack(0x00007f4df83f0000,0x00007f4df84f0ad0)]

siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x000000000000d1f6

Registers:
RAX=0x0000000000000000, RBX=0x000000007fffffff, RCX=0x0000000000000006, RDX=0x0000000000000000
RSP=0x00007f4df84ed5d8, RBP=0x000055eaf3519860, RSI=0x00007f4df4f261c0, RDI=0x000000007fffffff
R8 =0x0000000000000005, R9 =0x000000000000bdd0, R10=0x00007f4e1b04b158, R11=0x0000000000000000
R12=0x0000000000000000, R13=0x0000000000000000, R14=0x000055eaf35198ec, R15=0x00007f4df61958d8
RIP=0x000000000000d1f6, EFLAGS=0x0000000000010202, CSGSFS=0x0000000000000033, ERR=0x0000000000000014
TRAPNO=0x000000000000000e

Top of Stack: (sp=0x00007f4df84ed5d8)
0x00007f4df84ed5d8: 00007f4df617af28 0000000000000000
0x00007f4df84ed5e8: 0000000000000027 fffffffe00000000
0x00007f4df84ed5f8: 00007f4e1b04ddd0 00007f4e1b04da20
0x00007f4df84ed608: 00007f4df4f26200 000055eaf3519860
0x00007f4df84ed618: 0000000000000000 0000000000000000
0x00007f4df84ed628: 00007f4df617671a 00007f4df84ed903
0x00007f4df84ed638: 00007f4df84ed688 0000000000000000
0x00007f4df84ed648: 0000000000000000 000055eaf3519860
0x00007f4df84ed658: 000055eaf3519520 000055eaf351d5a0
0x00007f4df84ed668: 00007f4df28aa0a0 000000000000009c
0x00007f4df84ed678: 00007f4df3d985a9 0000000000000000
0x00007f4df84ed688: 000055eaf3519860 0000000000000000
0x00007f4df84ed698: 00007f4df3d9876e 000055eaf351d5a0
0x00007f4df84ed6a8: 000055eaf351cfc0 0000000000000000
0x00007f4df84ed6b8: 00007f4df295834e 00007f4df84ed656
0x00007f4df84ed6c8: 000055eaf3519520 000055eaf351b780
0x00007f4df84ed6d8: 000055eaf351b780 000055eaf351d5a0
0x00007f4df84ed6e8: 00007f4df28aa0e5 ffffffffffff0000
0x00007f4df84ed6f8: 0000000000000000 00007f4df84ed658
0x00007f4df84ed708: 0000000000000000 0000000000000000
0x00007f4df84ed718: 0000000000000000 0000000000000000
0x00007f4df84ed728: 0000000000000000 0000000000000000
0x00007f4df84ed738: 0000000000000000 0000000000000000
0x00007f4df84ed748: 0000000000000000 00007f4df28a83a0
0x00007f4df84ed758: 00007f4e1b0081fd 0000003000000018
0x00007f4df84ed768: 0000003000000018 0000000000000074
0x00007f4df84ed778: 000055eaf351b780 0000000000025e40
0x00007f4df84ed788: 000055eaf351d5a0 00007f4df84ed8e0
0x00007f4df84ed798: 00007f4df616e42a 0000003000000018
0x00007f4df84ed7a8: 00007f4df84ed880 00007f4df84ed7c0
0x00007f4df84ed7b8: 0000000000000000 0000000000000000
0x00007f4df84ed7c8: 0000000000000000 0000000000000000

Instructions: (pc=0x000000000000d1f6)
0x000000000000d1d6:
[error occurred during error reporting (printing registers, top of stack, instructions near pc), id 0xb]

Register to memory mapping:

RAX=0x0000000000000000 is an unknown value
RBX=0x000000007fffffff is an unknown value
RCX=0x0000000000000006 is an unknown value
RDX=0x0000000000000000 is an unknown value
RSP=0x00007f4df84ed5d8 is pointing into the stack for thread: 0x000055eaf44d4800
RBP=0x000055eaf3519860 is an unknown value
RSI=0x00007f4df4f261c0: <offset 0x17c31c0> in /home/deploy/.javacpp/cache/ffmpeg-3.4.2-1.4.1-linux-x86_64.jar/org/bytedeco/javacpp/linux-x86_64/libavcodec.so.57 at 0x00007f4df3763000
RDI=0x000000007fffffff is an unknown value
R8 =0x0000000000000005 is an unknown value
R9 =0x000000000000bdd0 is an unknown value
R10=0x00007f4e1b04b158: <offset 0x8d158> in /lib/ld-musl-x86_64.so.1 at 0x00007f4e1afbe000
R11=0x0000000000000000 is an unknown value
R12=0x0000000000000000 is an unknown value
R13=0x0000000000000000 is an unknown value
R14=0x000055eaf35198ec is an unknown value
R15=0x00007f4df61958d8: <offset 0x4c8d8> in /home/deploy/.javacpp/cache/ffmpeg-3.4.2-1.4.1-linux-x86_64.jar/org/bytedeco/javacpp/linux-x86_64/libavutil.so.55 at 0x00007f4df6149000

Stack: [0x00007f4df83f0000,0x00007f4df84f0ad0], sp=0x00007f4df84ed5d8, free space=1013k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C 0x000000000000d1f6

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j org.bytedeco.javacpp.avformat.avformat_open_input(Lorg/bytedeco/javacpp/avformat$AVFormatContext;Ljava/lang/String;Lorg/bytedeco/javacpp/avformat$AVInputFormat;Lorg/bytedeco/javacpp/avutil$AVDictionary;)I+0
j org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe()V+624
j org.bytedeco.javacv.FFmpegFrameGrabber.start()V+1
j com.withufuture.third.amazon.util.FileInfoUtils.parseVideoInfo(Ljava/io/InputStream;)Lcom/withufuture/third/amazon/util/ResourceDefinition;+30
j com.withufuture.third.amazon.service.impl.AwsS3V2ServiceImpl.uploadAndGetFileInformation(Lorg/springframework/web/multipart/MultipartFile;)Lcom/withufuture/core/api/Result;+294
j com.withufuture.resource.v2.web.ResourceV2Controller.uploadAndGetFileInformation(Lorg/springframework/web/multipart/MultipartFile;)Lcom/withufuture/core/api/Result;+5
v ~StubRoutines::call_stub

for details, see attached

hs_err_pid1.log

@saudet
Copy link
Member

saudet commented Apr 7, 2022

Please call start() instead of startUnsafe(). Also please give it a try with the snapshots: http://bytedeco.org/builds/

@yangxinbo
Copy link
Author

I replaced the container image successfully
success:openjdk:8u322-jre
fail:openjdk:8-jre-alpine

@yangxinbo
Copy link
Author

If I want to use this mirror ‘openjdk:8-jre-alpine’,What should I do

@saudet
Copy link
Member

saudet commented Apr 9, 2022

That most likely doesn't support glibc. You'll need to build from source:
https://github.com/bytedeco/javacpp-presets/#build-instructions

@saudet
Copy link
Member

saudet commented Jul 22, 2023

Duplicate of bytedeco/javacpp-presets#1379

@saudet saudet marked this as a duplicate of bytedeco/javacpp-presets#1379 Jul 22, 2023
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