How to solve error “AAC with no global headers is currently not supported” #2065
-
I'm trying to transcode dhav (one of the container format) to RTSP By JavaCV(FFmpegFrameGrabber + FFmpegFrameRecorder) , It's fine when i transcoding dhav to RTMP , but when I change to RTSP ,error occurred:
the key code is public static synchronized void grabAndPush(InputStream inputStream, String pushAddress, String pushPotocol) throws Exception {
avutil.av_log_set_level(AV_LOG_DEBUG);
FFmpegLogCallback.set();
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputStream,0);
long startTime = System.currentTimeMillis();
grabber.start();
AVFormatContext avFormatContext = grabber.getFormatContext();
int streamNum = avFormatContext.nb_streams();
if (streamNum < 1) {
log.error("no media!");
return;
}
int frameRate = (int) grabber.getVideoFrameRate();
if (0 == frameRate) {
frameRate = 15;
}
log.info("frameRate[{}],duration[{}]secs,number streams[{}]",
frameRate,
avFormatContext.duration() / 1000000,
avFormatContext.nb_streams());
for (int i = 0; i < streamNum; i++) {
AVStream avStream = avFormatContext.streams(i);
AVCodecParameters avCodecParameters = avStream.codecpar();
log.info("stream index[{}],codec type[{}],codec ID[{}]", i, avCodecParameters.codec_type(), avCodecParameters.codec_id());
}
int frameWidth = grabber.getImageWidth();
int frameHeight = grabber.getImageHeight();
int audioChannels = grabber.getAudioChannels();
log.info("frameWidth[{}],frameHeight[{}],audioChannels[{}]",
frameWidth,
frameHeight,
audioChannels);
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(pushAddress,
frameWidth,
frameHeight,
audioChannels);
recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
recorder.setInterleaved(true);
switch (pushPotocol) {
case "rtsp" -> {
recorder.setFormat("rtsp");
}
case "rtmp" -> {
recorder.setFormat("flv");
}
}
log.info("push protocol:{}| grabber format:{} | recorder format:{}",pushPotocol,grabber.getFormat(),recorder.getFormat());
recorder.setFrameRate(frameRate);
recorder.setAudioCodec(AV_CODEC_ID_AAC);
log.info("grabber audio codec name :{}|recorder audio codec name :{}",grabber.getAudioCodecName(),recorder.getAudioCodecName());
recorder.setGopSize(frameRate * 2);
recorder.setAudioChannels(grabber.getAudioChannels());
startTime = System.currentTimeMillis();
avFormatContext.max_interleave_delta(0);
avFormatContext.flags(avformat.AVFMT_TS_NONSTRICT);
recorder.setTimestamp(0);
recorder.start(avFormatContext);
Frame frame;
int videoFrameNum = 0;
int audioFrameNum = 0;
int dataFrameNum = 0;
AVPacket packet;
long lastDTS = 0;
while ((packet = grabber.grabPacket()) != null) {
if (packet.pts() == AV_NOPTS_VALUE) {
if (packet.dts() != AV_NOPTS_VALUE) {
packet.pts(packet.dts());
lastDTS = packet.dts();
} else {
packet.pts(lastDTS + 1);
packet.dts(packet.pts());
lastDTS = packet.pts();
}
} else {
if (packet.dts() != AV_NOPTS_VALUE) {
if (packet.dts() < lastDTS) {
packet.dts(lastDTS + 1);
}
lastDTS = packet.dts();
} else {
packet.dts(packet.pts());
lastDTS = packet.dts();
}
}
if (packet.pts() < packet.dts()) {
packet.pts(packet.dts());
}
recorder.recordPacket(packet);
Thread.sleep(1);
}
log.info("push complete,videoFrameNum[{}],audioFrameNum[{}],dataFrameNum[{}],耗时[{}]秒",
videoFrameNum,
audioFrameNum,
dataFrameNum,
(System.currentTimeMillis() - startTime) / 1000);
recorder.close();
grabber.close();
} After googled , I tried fowllowing :
could someone guide me on this that will be grateful! These mabay can help,about the dhav (snapshot) :
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
ok, I figure out, just add recorder.setAudioBitrate(grabber.getAudioBitrate()); , dhav to rtsp is ok |
Beta Was this translation helpful? Give feedback.
ok, I figure out, just add recorder.setAudioBitrate(grabber.getAudioBitrate()); , dhav to rtsp is ok