libxvid: remove temporary files at the end

Fixes Ticket924

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-03-02 20:22:08 +01:00
parent 03bc7a004e
commit 6a8f6c773d
1 changed files with 9 additions and 2 deletions

View File

@ -60,6 +60,7 @@ struct xvid_context {
char *twopassbuffer; /**< Character buffer for two-pass */ char *twopassbuffer; /**< Character buffer for two-pass */
char *old_twopassbuffer; /**< Old character buffer (two-pass) */ char *old_twopassbuffer; /**< Old character buffer (two-pass) */
char *twopassfile; /**< second pass temp file name */ char *twopassfile; /**< second pass temp file name */
int twopassfd;
unsigned char *intra_matrix; /**< P-Frame Quant Matrix */ unsigned char *intra_matrix; /**< P-Frame Quant Matrix */
unsigned char *inter_matrix; /**< I-Frame Quant Matrix */ unsigned char *inter_matrix; /**< I-Frame Quant Matrix */
}; };
@ -356,6 +357,8 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
xvid_enc_create_t xvid_enc_create = { 0 }; xvid_enc_create_t xvid_enc_create = { 0 };
xvid_enc_plugin_t plugins[7]; xvid_enc_plugin_t plugins[7];
x->twopassfd = -1;
/* Bring in VOP flags from ffmpeg command-line */ /* Bring in VOP flags from ffmpeg command-line */
x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */ x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */
if( xvid_flags & CODEC_FLAG_4MV ) if( xvid_flags & CODEC_FLAG_4MV )
@ -491,6 +494,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
"Xvid: Cannot write 2-pass pipe\n"); "Xvid: Cannot write 2-pass pipe\n");
return -1; return -1;
} }
x->twopassfd = fd;
if( avctx->stats_in == NULL ) { if( avctx->stats_in == NULL ) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
@ -500,13 +504,11 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
if( strlen(avctx->stats_in) > if( strlen(avctx->stats_in) >
write(fd, avctx->stats_in, strlen(avctx->stats_in)) ) { write(fd, avctx->stats_in, strlen(avctx->stats_in)) ) {
close(fd);
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"Xvid: Cannot write to 2-pass pipe\n"); "Xvid: Cannot write to 2-pass pipe\n");
return -1; return -1;
} }
close(fd);
rc2pass2.filename = x->twopassfile; rc2pass2.filename = x->twopassfile;
plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2; plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;
plugins[xvid_enc_create.num_plugins].param = &rc2pass2; plugins[xvid_enc_create.num_plugins].param = &rc2pass2;
@ -741,6 +743,11 @@ static av_cold int xvid_encode_close(AVCodecContext *avctx) {
av_free(x->old_twopassbuffer); av_free(x->old_twopassbuffer);
avctx->stats_out = NULL; avctx->stats_out = NULL;
} }
if (x->twopassfd>=0) {
unlink(x->twopassfile);
close(x->twopassfd);
x->twopassfd = -1;
}
av_free(x->twopassfile); av_free(x->twopassfile);
av_free(x->intra_matrix); av_free(x->intra_matrix);
av_free(x->inter_matrix); av_free(x->inter_matrix);