DemuxException: type = CodecUnsupported, info = Flv: Unsupported codec in video frame: 12
#1,962 opened on Jan 2, 2023
Repository metrics
- Stars
- (6,985 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
javacv version is 1.5.8,the server is nginx-http-flv-module,the front is : vue+flv.js; then the page console print error:DemuxException: type = CodecUnsupported, info = Flv: Unsupported codec in video frame: 12
my code is: `public static Boolean start(String deviceId, String formUrl, String toUrl) { if (null != get(deviceId)) return true; final RtmpAnalyseHandler convertVideoPakcet = new RtmpAnalyseHandler(); BaseConstants.CONVERT_VIDEO_PACKETS.put(deviceId, convertVideoPakcet); new Thread(() -> { LOG.info("start device"); try { convertVideoPakcet.rtsp(formUrl).rtmp(toUrl).start(); } catch (IOException e) { LOG.error("start dvice error,{}", e); } catch (Exception e) { e.printStackTrace(); } }).start(); LOG.info("start device finish!"); return true; }
/**
*
* @param id
* @return
*/
public static Boolean stop(String id) {
LOG.info("stop device ,{}", id);
RtmpAnalyseHandler convertVideoPakcet = get(id);
if (null != convertVideoPakcet) {
BaseConstants.CONVERT_VIDEO_PACKETS.remove(id);
return convertVideoPakcet.stop();
}
return false;
}
/**
*
* @param src
* @throws Exception
* @author JW
*/
private RtmpAnalyseHandler rtsp(String src) throws Exception {
grabber = new FFmpegFrameGrabber(src);
grabber.setOption("rtsp_transport", "tcp");
LOG.info("grabber start begin");
grabber.start();
LOG.info("grabber start end");
if (width < 0 || height < 0) {
width = grabber.getImageWidth();
height = grabber.getImageHeight();
}
audiocodecid = grabber.getAudioCodec();
codecid = grabber.getVideoCodec();
framerate = grabber.getVideoFrameRate();
bitrate = grabber.getVideoBitrate();
audioChannels = grabber.getAudioChannels();
audioBitrate = grabber.getAudioBitrate();
if (audioBitrate < 1) {
audioBitrate = 128 * 1000;
}
return this;
}
/**
* @throws IOException
* @author JW
*/
private RtmpAnalyseHandler rtmp(String out) throws IOException {
LOG.info("rtmp start begin");
record = new FFmpegFrameRecorder(out, width, height);
record.setVideoOption("tune", "zerolatency");
record.setVideoOption("preset", "ultrafast");
record.setVideoOption("crf", "28");
record.setMaxDelay(500000);
record.setGopSize(10);
record.setFrameRate(framerate);
record.setVideoBitrate(bitrate);
// record.setAudioChannels(audioChannels); // record.setAudioBitrate(audioBitrate); // record.setSampleRate(sampleRate); AVFormatContext fc = null; record.setVideoOption("preset", "ultrafast"); record.setFormat("flv"); record.setAudioCodecName("aac"); // record.setVideoCodec(codecid); record.setVideoCodec(avcodec.AV_CODEC_ID_H264); fc = grabber.getFormatContext(); record.start(fc); // record.start(); LOG.info("rtmp start end"); return this; }
/**
*
*
* @throws IOException
* @author eguid
*/
private void start() throws IOException {
LOG.info("rtmp start……");
if (null != grabber)
grabber.flush();
while (flag) {
AVPacket pkt = null;
try {
pkt = grabber.grabPacket();
if (pkt == null || pkt.size() <= 0 || pkt.data() == null) {
continue;
}
record.recordPacket(pkt);
avcodec.av_packet_unref(pkt);
try {
Thread.sleep(0, 1000);
} catch (InterruptedException e) {
LOG.error("error,{}", e);
}
} catch (Exception e) {
LOG.error("error,{}", e);
}
}
}`
Does anyone know why? thank you very much!