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

how to get notified as javacv finished writing each segment #2275

Open
marlsenwang opened this issue Aug 16, 2024 · 0 comments
Open

how to get notified as javacv finished writing each segment #2275

marlsenwang opened this issue Aug 16, 2024 · 0 comments

Comments

@marlsenwang
Copy link

I use javacv to make hls segments from mp4 and upload them to cloud, everything works fine except one drawback, the process waits all segments finished, then start to upload, which is acceptable for small video, but for large video it wastes time. is there any mechanism in javacv that I can get notified after one segment finished writing . below is my code

FFmpegFrameRecorder recorder = null;
        FFmpegLogCallback.set();
        try (FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(path)
        ) {
            long start = System.currentTimeMillis();
            System.out.println("start segment " + start);
            grabber.start(true);
            recorder = new FFmpegFrameRecorder(output, grabber.getImageWidth(), grabber.getImageHeight(),
                    grabber.getAudioChannels());

            recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
            recorder.setVideoOption("crf", "18");
            recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);

            recorder.setFormat("hls");
            recorder.setOption("hls_time", "2");
            recorder.setOption("hls_list_size", "0");
            recorder.setOption("start_number", "0");

            AVFormatContext formatContext = grabber.getFormatContext();

            recorder.start();
            AVPacket pkt = null;
            Frame frame = null;
            long dts = 0, pts = 0;
            grabber.flush();
            while ((frame = grabber.grab()) != null) {
                recorder.record(frame);
            }
//            while ((pkt = grabber.grabPacket()) != null) {
//                recorder.recordPacket(pkt);
//            }
            System.out.println("end segment total time " + (System.currentTimeMillis() - start));
        } finally {
            if (recorder != null) {
                recorder.close();
            }
        }
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