aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ffmpeg_utils.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2026-08-05 14:56:59 +0200
committerdec05eba <dec05eba@protonmail.com>2026-08-05 14:56:59 +0200
commite6c1cf0ec1ce220912a6ef6b6fac5ba9b2e98276 (patch)
tree5e5636b9bc485a0efc37af6b03fccc99401d671b /src/ffmpeg_utils.c
parentfbc31a9561d16418226c0efa65e2a73923516dbd (diff)
workaround ffmpeg hybrid_fragmented bug when no packets have been recorded yet
Diffstat (limited to 'src/ffmpeg_utils.c')
-rw-r--r--src/ffmpeg_utils.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/ffmpeg_utils.c b/src/ffmpeg_utils.c
index ce239a1..fc4e4ed 100644
--- a/src/ffmpeg_utils.c
+++ b/src/ffmpeg_utils.c
@@ -1,7 +1,10 @@
#include "../include/ffmpeg_utils.h"
+#include "../include/log.h"
#include <string.h>
#include <libavutil/error.h>
+#include <libavutil/opt.h>
+#include <libavformat/avformat.h>
static _Thread_local char av_error_buffer[AV_ERROR_MAX_STRING_SIZE];
@@ -10,3 +13,28 @@ const char* gsr_av_error_to_string(int err) {
strcpy(av_error_buffer, "Unknown error");
return av_error_buffer;
}
+
+void gsr_av_format_context_mark_packet_written(AVFormatContext *av_format_context) {
+ av_format_context->opaque = (void*)1;
+}
+
+static bool av_format_context_uses_hybrid_fragmented(AVFormatContext *av_format_context) {
+ if(LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(62, 6, 101))
+ return false;
+
+ const AVOption *opt = av_opt_find(av_format_context->priv_data, "movflags", NULL, 0, 0);
+ if(!opt || !opt->unit)
+ return false;
+
+ return av_opt_find(av_format_context->priv_data, "hybrid_fragmented", opt->unit, 0, 0) != NULL;
+}
+
+int gsr_av_format_context_write_trailer(AVFormatContext *av_format_context) {
+ const bool packet_written = av_format_context->opaque != NULL;
+ if(!packet_written && av_format_context_uses_hybrid_fragmented(av_format_context)) {
+ gsr_log(GSR_LOG_LEVEL_WARNING, "not finalizing the video file because it has no video/audio data");
+ return 0;
+ }
+
+ return av_write_trailer(av_format_context);
+}