bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.51k stars 1.58k forks source link

recorder.recordPacket(avPacket) Unable to convert opus to aac #1972

Open redoriental opened 1 year ago

redoriental commented 1 year ago

FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(o, grabber.getImageWidth(), grabber.getImageHeight()); // 部分监控设备流信息里携带的帧率为9000,如出现此问题,会导致dts、pts时间戳计算失败,播放器无法播放,故出现错误的帧率时,默认为25帧 if (grabber.getFrameRate() > 0 && grabber.getFrameRate() < 100) { framerate = grabber.getFrameRate(); } else { framerate = 25.0; } recorder.setInterleaved(true); // 关键帧间隔,一般与帧率相同或者是视频帧率的两倍 recorder.setGopSize((int) framerate * 2); // 视频帧率(保证视频质量的情况下最低25,低于25会出现闪屏) recorder.setFrameRate(framerate); // 设置比特率 recorder.setVideoBitrate(grabber.getVideoBitrate()); recorder.setVideoCodec(AV_CODEC_ID_H264); // h264编/解码器 recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P); //视频参数 Map<String, String> videoOption = new HashMap<>(); // 该参数用于降低延迟 videoOption.put("tune", "zerolatency"); videoOption.put("preset", "ultrafast"); videoOption.put("crf", "28"); videoOption.put("vcodec","libx264"); //------------------------------- recorder.setMaxDelay(500); recorder.setAudioOption("crf", "0"); // 最高音质 recorder.setAudioQuality(0); // 192 Kbps recorder.setAudioBitrate(192000); recorder.setSampleRate(44100); recorder.setAudioChannels(2); recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC); //-------------------------------- recorder.setOptions(videoOption);

            recorder.start(formatContext);//I made a mistake in this step

FLV does not support sample rate 48000, choose from (44100, 22050, 11025)

saudet commented 1 year ago

We can't do that with recordPacket(). Please use record() for that.

redoriental commented 1 year ago

thank you,my friend!What is the reason why the sound and picture are not synchronized sometimes in the record() method?

redoriental commented 1 year ago

我们不能用 recordPacket() 来做到这一点。请为此使用 record()。

What is the reason why the sound and picture are not synchronized sometimes in the record() method

saudet commented 1 year ago

Please try to call recorder.setTimestamp(grabber.getTimestamp()) before record().

redoriental commented 1 year ago

Make sure to call record() with a timestamp argument.

Oh,yes!thank you very much!Your project is very good,and hope you can create more fast javacv version that the delay can become lower.

redoriental commented 1 year ago

where are you from? I believe we can become very good friends.

saudet commented 1 year ago

Oh,yes!thank you very much!Your project is very good,and hope you can create more fast javacv version that the delay can become lower.

We can use hardware acceleration to make it faster: https://trac.ffmpeg.org/wiki/HWAccelIntro

saudet commented 1 year ago

where are you from? I believe we can become very good friends.

There's a few places where you can look for that information, like here: https://www.linkedin.com/in/samuel-audet-24aa1627/

redoriental commented 1 year ago

thank you