bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.4k stars 1.57k forks source link

why FFmpegFrameRecorder.record() No data was retrieved? #2182

Open songbiaoself opened 5 months ago

songbiaoself commented 5 months ago

javacv version is 1.5.9

private ByteArrayOutputStream stream;

...
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(stream, grabber.getImageWidth(), grabber.getImageHeight(),grabber.getAudioChannels());
recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);
// ... Omit other parameters
recorder.record(frame);
log.info("byte size:{}", stream.size());
...

When my RTSP stream exists in audio, the total interval between my first frame data and the second frame is about 10 seconds (the subsequent frame interval is normal), and the data of the second frame is larger than other frames, which causes my front end to not work properly. Play. Frame spacing is normal when audio is not present.

2024-02-01 16:14:00.112INF012740---[1706775240085]byte size:401
2024-02-01 16:14:00.139INF012740---[1706775240085]byte size:0
2024-02-01 16:14:00.149INF012740---[1706775240085]byte size:0
2024-02-01 16:14:00.159INF012740---[1706775240085]byte size:0
...
2024-02-01 16:14:09.854INF012740---[1706775240085]byte size:321000
2024-02-01 16:14:09.889INF012740---[1706775240085]byte size:542

The front -end Chrome browser's WebSocket message data interface image

This is the media information of the rtsp video stream seen on the VLC software image

Hope a solution can be given!