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

Live broadcast Poor recording #1534

Open
202774025 opened this issue Aug 26, 2024 · 1 comment
Open

Live broadcast Poor recording #1534

202774025 opened this issue Aug 26, 2024 · 1 comment

Comments

@202774025
Copy link

Hello, why can't I use this to record the live broadcast I recorded from the Internet? It feels a little fuzzy, the original live broadcast picture is not like this, if the VideoBitrate setting is smaller, the Mosaic will be more obvious. I have tried to record many live broadcasts, and this is the code example. When I made the VideoBitrate smaller, it was more obvious. "ffmpeg.exe" record does not have this problem, I want to know how to optimize the configuration

try (FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(URL.of(URI.create(url), null))) {
            grabber.setOption("rtsp_transport", "tcp");
            grabber.setOption("rtsp_flags", "prefer_tcp");
            grabber.start();
            try (FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputPath, grabber.getAudioChannels())) {
                recorder.setImageWidth(grabber.getImageWidth());
                recorder.setImageHeight(grabber.getImageHeight());
                recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
                recorder.setVideoBitrate(grabber.getVideoBitrate());
                recorder.setAudioBitrate(grabber.getAudioBitrate());
                recorder.setFrameRate(grabber.getFrameRate());
                recorder.setGopSize(4);
                recorder.start();
                long lastFrameTime = System.currentTimeMillis();
                while (true) {
                    Frame capturedFrame = grabber.grabFrame();
                    if (capturedFrame != null) {
                        lastFrameTime = System.currentTimeMillis();
                        recorder.record(capturedFrame);
                    } else if (System.currentTimeMillis() - lastFrameTime > 30000) {
                        break;
                    }
                }
            } catch (Exception e) {
                log.error(e.getMessage());
            }
        }

This was recorded by current project
image

This was recorded by ffmpeg.exe
image

@saudet
Copy link
Member

saudet commented Sep 1, 2024

Please make sure you're using libx264

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

3 participants
@saudet @202774025 and others