From adea15f24b04301c6a925800c923fa2835fda7e6 Mon Sep 17 00:00:00 2001 From: Lorenzo Miniero Date: Tue, 30 Aug 2022 16:03:56 +0200 Subject: [PATCH] Fixed broken faststart when postprocessing H.264 recordings to MP4 (fixes #3037) --- src/postprocessing/pp-g722.c | 2 +- src/postprocessing/pp-h264.c | 4 +++- src/postprocessing/pp-h265.c | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/postprocessing/pp-g722.c b/src/postprocessing/pp-g722.c index 3c0ba314b1..6f8b51c36a 100644 --- a/src/postprocessing/pp-g722.c +++ b/src/postprocessing/pp-g722.c @@ -25,7 +25,7 @@ #include "../debug.h" /* G.722 decoder */ -static AVCodec *dec_codec; /* FFmpeg decoding codec */ +static const AVCodec *dec_codec; /* FFmpeg decoding codec */ static AVCodecContext *dec_ctx; /* FFmpeg decoding context */ /* WAV header */ diff --git a/src/postprocessing/pp-h264.c b/src/postprocessing/pp-h264.c index 8ec9154efc..2d03c38031 100644 --- a/src/postprocessing/pp-h264.c +++ b/src/postprocessing/pp-h264.c @@ -67,7 +67,7 @@ int janus_pp_h264_create(char *destination, char *metadata, gboolean faststart, char filename[1024]; snprintf(filename, sizeof(filename), "%s", destination); #ifdef USE_CODECPAR - AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_H264); + const AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_H264); if(!codec) { /* Error opening video codec */ JANUS_LOG(LOG_ERR, "Encoder not available\n"); @@ -122,6 +122,7 @@ int janus_pp_h264_create(char *destination, char *metadata, gboolean faststart, JANUS_LOG(LOG_ERR, "Error opening file for output (%d, %s)\n", res, av_err2str(res)); return -1; } + fctx->url = g_strdup(filename); if(avformat_write_header(fctx, &options) < 0) { JANUS_LOG(LOG_ERR, "Error writing header\n"); return -1; @@ -553,6 +554,7 @@ void janus_pp_h264_close(void) { } if(fctx != NULL) { avio_close(fctx->pb); + g_free(fctx->url); av_free(fctx); } } diff --git a/src/postprocessing/pp-h265.c b/src/postprocessing/pp-h265.c index 30d72fb1da..716b8f46e2 100644 --- a/src/postprocessing/pp-h265.c +++ b/src/postprocessing/pp-h265.c @@ -67,7 +67,7 @@ int janus_pp_h265_create(char *destination, char *metadata, gboolean faststart, char filename[1024]; snprintf(filename, sizeof(filename), "%s", destination); #ifdef USE_CODECPAR - AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_H265); + const AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_H265); if(!codec) { /* Error opening video codec */ JANUS_LOG(LOG_ERR, "Encoder not available\n"); @@ -110,8 +110,7 @@ int janus_pp_h265_create(char *destination, char *metadata, gboolean faststart, vStream->codec->width = max_width; vStream->codec->height = max_height; vStream->codec->pix_fmt = PIX_FMT_YUV420P; - //~ if (fctx->flags & AVFMT_GLOBALHEADER) - vStream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER; + vStream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER; #endif AVDictionary *options = NULL; if(faststart) @@ -122,6 +121,7 @@ int janus_pp_h265_create(char *destination, char *metadata, gboolean faststart, JANUS_LOG(LOG_ERR, "Error opening file for output (%d, %s)\n", res, av_err2str(res)); return -1; } + fctx->url = g_strdup(filename); if(avformat_write_header(fctx, &options) < 0) { JANUS_LOG(LOG_ERR, "Error writing header\n"); return -1; @@ -643,6 +643,7 @@ void janus_pp_h265_close(void) { } if(fctx != NULL) { avio_close(fctx->pb); + g_free(fctx->url); av_free(fctx); } }