bytedeco/javacv
View on GitHubav_write_frame() error -22 while writing video packet.
Open
#1,221 opened on Jun 3, 2019
enhancementhelp wanted
Repository metrics
- Stars
- (6,985 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
I use FFmpegFrameRecorder to forward live stream. But every once in a while, always throw exception av_write_frame() error -22 while writing video packet. I find some answer, such like pts must be greater than or equal to dts, but I print pts and dts, they're always equal.
public ConvertVideoPacket go() throws IOException {
long errTime = 0; // error times
int no_frame_index = 0; // no frame times
grabber.flush();
// It will stop if error times greater than 20
while(switchMap.get(id) && no_frame_index < 20 && errTime < MAX_WRITE_PACKET_ERR_TIME) {
AVPacket pkt = null;
try {
// get av_packet
pkt = grabber.grabPacket();
if(pkt == null || pkt.size() <= 0 || pkt.data() == null || pkt.data().isNull()) {
no_frame_index++;
continue;
}
// push
int ret = (record.recordPacket(pkt) ? 0 : 1);
errTime += ret;
// release packet
av_free_packet(pkt);
} catch (Exception e) { // failed
logger.error(e.getMessage());
logger.error("exception! pts=" + pkt.pts() + ", dts=" + pkt.dts());
errTime++;
} catch (IOException e) {
logger.error(e.getMessage());
logger.error("exception! pts=" + pkt.pts() + ", dts=" + pkt.dts());
errTime++;
}
}
// gc
release();
// reconnect
if(switchMap.get(id) && cur_reconnect_time < MAX_RECONNECT_TIME) {
logger.warn("reconnecting... IPC ID=" + id);
cur_reconnect_time++;
return this.from(this.src).to(this.output).go();
} else {
logger.info("stop forward. IPC ID=" + id);
}
return this;
}
/**
* Release grabber, recorder
* @throws IOException
*/
private void release() throws IOException {
record.stop();
grabber.stop();
record.close();
record.release();
grabber.close();
grabber.release();
}
> 2019-06-03 15:54:11 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -av_write_frame() error -22 while writing video packet.
2019-06-03 15:54:11 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -exception! pts=205855, dts=205855
2019-06-03 15:54:11 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -av_write_frame() error -22 while writing video packet.
2019-06-03 15:54:11 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -exception! pts=205904, dts=205904
2019-06-03 15:54:11 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -av_write_frame() error -22 while writing video packet.
2019-06-03 15:54:11 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -exception! pts=205954, dts=205954
2019-06-03 15:54:11 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -av_write_frame() error -22 while writing video packet.
2019-06-03 15:54:11 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -exception! pts=206004, dts=206004
2019-06-03 15:54:11 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -av_write_frame() error -22 while writing video packet.
2019-06-03 15:54:11 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -exception! pts=206057, dts=206057
2019-06-03 15:54:11 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -av_write_frame() error -22 while writing video packet.
2019-06-03 15:54:11 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -exception! pts=206104, dts=206104
2019-06-03 15:54:12 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -av_write_frame() error -22 while writing video packet.
2019-06-03 15:54:12 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -exception! pts=206155, dts=206155
2019-06-03 15:54:12 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -av_write_frame() error -22 while writing video packet.
2019-06-03 15:54:12 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -exception! pts=206205, dts=206205
2019-06-03 15:54:12 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -av_write_frame() error -22 while writing video packet.
2019-06-03 15:54:12 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -exception! pts=206254, dts=206254
2019-06-03 15:54:12 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -av_write_frame() error -22 while writing video packet.
2019-06-03 15:54:12 [Thread-22] ERROR com.video.demo.util.javacv.ConvertVideoPacket -exception! pts=206304, dts=206304
2019-06-03 15:54:12 [Thread-22] WARN com.video.demo.util.javacv.ConvertVideoPacket -reconnecting... IPC ID=4