bytedeco / javacv

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

rtsp to rtmp Delay up to about 30 seconds #2020

Open hou718945431 opened 1 year ago

hou718945431 commented 1 year ago

I use FFmpegFrameGrabber to process images frame by frame and push the stream to the rtmp server, but the rtmp playback delay is too high. What can I do to reduce this delay? I think I can accept it within 5 seconds

saudet commented 1 year ago

Did you make sure to use hardware acceleration everywhere?

hou718945431 commented 1 year ago

My testing environment does not have a GPU. After using ffmpeg to block audio, the delay drops to about 3 seconds. Does JavaCV provide ffmpeg - an parameter configuration? how can i do

saudet commented 1 year ago

If the problem doesn't occur without audio, that's probably because of a synchronization issue between audio and video frames. Make sure audio and video frames are synchronized within ~1 second.

hou718945431 commented 1 year ago

i use setTimestamp, But it seems to have no effect

saudet commented 1 year ago

setTimestamp() doesn't affect audio frames, that's normal.

hou718945431 commented 1 year ago

I want to use FFmpegFrameGrabber by my own compiled ffmpeg and how can I do it

saudet commented 1 year ago

Build from source? https://github.com/bytedeco/javacpp-presets#build-instructions

hou718945431 commented 1 year ago

I want to use cuda for hardware acceleration. Does 1.5.8 support it? ffmpeg6.0 should compiling the corresponding files

saudet commented 1 year ago

Yes, most hardware acceleration is available in 1.5.8.

hou718945431 commented 1 year ago

how can i do ? grabber.setOption("hwaccel", "cuda"); and How do I know the decoder and encoder?h264_?

saudet commented 1 year ago

I don't believe hwaccel works, but setting video codecs with setVideoCodecName() does work: https://trac.ffmpeg.org/wiki/HWAccelIntro

hou718945431 commented 1 year ago

When I want to compile ffmpeg to support cuda, I need to tell him the installation path of cuda and how I need to inform it of the location in Javacv

saudet commented 1 year ago

You're talking about the --enable-cuda-nvcc build option? That's not currently part of the presets, but we can add it to the cppbuild.sh script.

hou718945431 commented 1 year ago

I don't believe hwaccel works, but setting video codecs with setVideoCodecName() does work: https://trac.ffmpeg.org/wiki/HWAccelIntro

i try to set grabber.setVideoCodecName("h264_cuvid") and recorder.setVideoCodecName("h264_nvenc") get error, Error: [h264_cuvid @ 0xfffdbc1e06f0] Cannot load libnvcuvid.so.1 Error: [h264_cuvid @ 0xfffdbc1e06f0] Failed loading nvcuvid. Error: [h264_nvenc @ 0xffff0c2c5ec0] Cannot load libnvidia-encode.so.1 how can i know what decoder and encoder it support

saudet commented 1 year ago

Those files come with the video drivers. You'll need to install the latest version of the video drivers for your GPU.