motion: write trailer even if codec drain fails

This commit is contained in:
Joo Aun Saw 2017-09-18 16:30:29 +10:00
parent 5e743f3477
commit 7e50bcbcce

View File

@ -1,11 +1,11 @@
commit 9c604dc427804b9620044a2bdddca1b8c1831627
commit ff55aecd6fb88a030790b494dcd55bd99cace52b
Author: Joo Aun Saw <jasaw@dius.com.au>
Date: Mon Sep 18 14:30:22 2017 +1000
Date: Mon Sep 18 16:25:44 2017 +1000
drain codec at end of recording
diff --git a/ffmpeg.c b/ffmpeg.c
index aa06bef..c690896 100644
index aa06bef..ecdc3e5 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -350,7 +350,7 @@ static int ffmpeg_write_packet(struct ffmpeg *ffmpeg){
@ -46,7 +46,20 @@ index aa06bef..c690896 100644
}
if (retcd < 0 ){
av_strerror(retcd, errstr, sizeof(errstr));
@@ -404,7 +409,7 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){
@@ -385,7 +390,11 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){
if (retcd < 0) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error while writing video frame");
my_packet_unref(ffmpeg->pkt);
- ffmpeg_free_context(ffmpeg);
+ /* Do not free ffmpeg context if we are draining codec. We still
+ * need to write trailer even if draining fails.
+ */
+ if (picture != NULL)
+ ffmpeg_free_context(ffmpeg);
return -1;
}
}
@@ -404,7 +413,7 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){
ffmpeg->pkt.data = NULL;
ffmpeg->pkt.size = 0;
@ -55,7 +68,20 @@ index aa06bef..c690896 100644
if (retcd < 0 ){
av_strerror(retcd, errstr, sizeof(errstr));
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error encoding video:%s",errstr);
@@ -441,7 +446,7 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){
@@ -421,7 +430,11 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){
if (retcd < 0) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error while writing video frame");
my_packet_unref(ffmpeg->pkt);
- ffmpeg_free_context(ffmpeg);
+ /* Do not free ffmpeg context if we are draining codec. We still
+ * need to write trailer even if draining fails.
+ */
+ if (picture != NULL)
+ ffmpeg_free_context(ffmpeg);
return -1;
}
@@ -441,7 +454,7 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){
video_outbuf_size = (ffmpeg->ctx_codec->width +16) * (ffmpeg->ctx_codec->height +16) * 1;
video_outbuf = mymalloc(video_outbuf_size);
@ -64,7 +90,7 @@ index aa06bef..c690896 100644
if (retcd < 0 ){
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error encoding video");
my_packet_unref(ffmpeg->pkt);
@@ -457,11 +462,12 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){
@@ -457,11 +470,12 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){
ffmpeg->pkt.size = retcd;
ffmpeg->pkt.data = video_outbuf;
@ -82,7 +108,20 @@ index aa06bef..c690896 100644
retcd = ffmpeg_write_packet(ffmpeg);
if (retcd < 0) {
@@ -817,7 +823,7 @@ static int ffmpeg_put_frame(struct ffmpeg *ffmpeg, const struct timeval *tv1){
@@ -469,7 +483,11 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error while writing video frame");
my_packet_unref(ffmpeg->pkt);
free(video_outbuf);
- ffmpeg_free_context(ffmpeg);
+ /* Do not free ffmpeg context if we are draining codec. We still
+ * need to write trailer even if draining fails.
+ */
+ if (picture != NULL)
+ ffmpeg_free_context(ffmpeg);
return -1;
}
@@ -817,7 +835,7 @@ static int ffmpeg_put_frame(struct ffmpeg *ffmpeg, const struct timeval *tv1){
return 0;
}
@ -91,7 +130,7 @@ index aa06bef..c690896 100644
if (retcd < 0){
if (retcd != -2)
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error while encoding picture");
@@ -957,6 +963,7 @@ void ffmpeg_close(struct ffmpeg *ffmpeg){
@@ -957,6 +975,7 @@ void ffmpeg_close(struct ffmpeg *ffmpeg){
#ifdef HAVE_FFMPEG
if (ffmpeg != NULL) {