bytedeco/javacv

Rtmp streams are stored as mp4 files

Open

#1,953 opened on Dec 8, 2022

View on GitHub
 (5 comments) (0 reactions) (0 assignees)Java (1,583 forks)batch import
enhancementhelp wantedquestion

Repository metrics

Stars
 (6,985 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Hi,I want to store the rmtp stream as an mp4 file,For example, use the ffmpeg command :ffmpeg -i rtmp://xx.com/3573613170/18573613170 -f mp4 -vcodec copy -acodec copy C:\Users\lhd\Desktop\2.mp4 But what should we do in javacv can you give me some advise? thank you! If there is some example code, that's perfect! thank you ~~

This is the code I tried to use javacv to complete this task, but the recorded video cannot be played:

        FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("rtmp://xx.com/3573613170/18573613170");
        grabber.start();
        FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("C:\\Users\\lhd\\Desktop\\2.mp4", grabber.getImageWidth(), grabber.getImageHeight(),grabber.getAudioChannels());
        recorder.setFormat("mp4");
        recorder.start(grabber.getFormatContext());
        LocalDateTime startTime = LocalDateTime.now();
        int times = 0;
        AVPacket avPacket = null;
        while (startTime.plusSeconds(10).compareTo(LocalDateTime.now()) > 0) {
            avPacket = grabber.grabPacket();
            if (avPacket != null) {
                recorder.recordPacket(avPacket);
                times++;
                System.out.println("record! "+times);
            }
        }
        recorder.close();
        grabber.close();

Dependent version:

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

Contributor guide