bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.54k stars 1.58k forks source link

Linux error:avformat_open_input() error -2;windows 10 is success #1818

Closed xckouy closed 2 years ago

xckouy commented 2 years ago

hello: The following is Linux error info: Error on InputStream.reset() or skip(): java.io.IOException: Resetting to invalid mark Error on InputStream.reset() or skip(): java.io.IOException: Resetting to invalid mark Warning: Invalid return value 0 for stream protocol

Error: [mxf @ 0x7fe754002fc0] local tag 0x3c0a with 0 size

Warning: Invalid return value 0 for stream protocol Warning: Invalid return value 0 for stream protocol

Error: [mxf @ 0x7fe754002fc0] no essence

org.bytedeco.javacv.FFmpegFrameGrabber$Exception: avformat_open_input() error -2: Could not open input "java.io.BufferedInputStream@5efc1d9d". (Has setFormat() been called?) (For more details, make sure FFmpegLogCallback.set() has been called.) at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:920) at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:846) at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:841)

The following is my code: run at windows 10 ,result is success。

S3Utils s3Utils = new S3Utils();
InputStream is = s3Utils.getInputStreamFromS3(bucketName, key);  // fetch video InputStream 
FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(is,1000000);
Frame captured_frame = null;
FFmpegFrameRecorder recorder = null;
try {
            FFmpegLogCallback.set();
            frameGrabber.setOption("rtsp_transport", "tcp");
            frameGrabber.start();
            frameGrabber.flush();

            recorder = new FFmpegFrameRecorder("demo.mp4", 720, 405, frameGrabber.getAudioChannels());
            recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
            recorder.setFormat("mp4");
            recorder.setFrameRate(frameGrabber.getFrameRate());

            recorder.setVideoBitrate(640 * 1024); 
            recorder.setAudioBitrate(192000);
            recorder.setAudioOptions(frameGrabber.getAudioOptions());
            recorder.setAudioQuality(0);
            recorder.setSampleRate(44100);
            recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);
            recorder.start();

           while (true) {
                try {
                    captured_frame = frameGrabber.grabFrame();

                    if (captured_frame == null) {
                       break;
                    }

                    recorder.record(captured_frame);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            recorder.stop();
            recorder.release();
            frameGrabber.stop();
            frameGrabber.release();
            recorder.close();
            frameGrabber.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            s3Utils.shutdown();
        }

The following is pom dependency: `

org.bytedeco javacv 1.5.6 org.bytedeco ffmpeg-platform 4.4-1.5.6 pom

`

saudet commented 2 years ago

Please try again with JavaCV 1.5.7.

xckouy commented 2 years ago

Using javacv 1.5.7, the same error occurs, and windos10 also reports an error. If the following parameter 1000000 is removed,

FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(is,1000000);

Then windows10 runs successfully. The conversion of small files on Linux will be successful, and the following errors will be reported for large files (such as 27g). The Linux memory is 16g


Error on InputStream.reset() or skip(): java.lang.OutOfMemoryError: Java heap space
Error on InputStream.read(): java.lang.OutOfMemoryError: Java heap space
Error: [mxf @ 0x7f802c0684c0] local tag 0x3c0a with 0 size

Error on InputStream.read(): java.lang.OutOfMemoryError: Java heap space
Error: [mxf @ 0x7f802c0684c0] no essence

org.bytedeco.javacv.FFmpegFrameGrabber$Exception: avformat_open_input() error -2: Could not open input "java.io.BufferedInputStream@4c90c75b". (Has setFormat() been called?) (For more details, make sure FFmpegLogCallback.set() has been called.)

Top command:
top - 05:21:52 up 147 days, 19:26,  6 users,  load average: 0.28, 0.32, 0.38
Tasks: 161 total,   1 running, 160 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.6 us,  0.7 sy,  0.0 ni, 97.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.8 st
KiB Mem : 16430156 total, 11047180 free,  4998540 used,   384436 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 11125804 avail Mem 
saudet commented 2 years ago

If sounds like you're trying to use a format that doesn't support streams well. Please try to use another format.

xckouy commented 2 years ago

FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(is, 0); Set the parameter maximumsize to 0 and run successfully on both Linux and windows

saudet,Thanks for your answer