From 420cda98cc818359e9882908f0d265572289f794 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 24 Sep 2016 10:42:58 +1200 Subject: [PATCH] Allow seek during movie export Some file formats require this, which meant that 1.2.27 broke export to them. --- src/moviemaker-legacy.cc | 8 +++++++- src/moviemaker.cc | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/moviemaker-legacy.cc b/src/moviemaker-legacy.cc index eca66748..9102a3a5 100644 --- a/src/moviemaker-legacy.cc +++ b/src/moviemaker-legacy.cc @@ -154,6 +154,12 @@ write_packet(void *opaque, uint8_t *buf, int buf_size) { size_t res = fwrite(buf, 1, buf_size, fh); return res > 0 ? res : -1; } + +static int64_t +seek_stream(void *opaque, int64_t offset, int whence) { + FILE * fh = (FILE*)opaque; + return fseek(fh, offset, whence); +} #endif #define MAX_EXTENSION_LEN 8 @@ -316,7 +322,7 @@ bool MovieMaker::Open(FILE* fh, const char * ext, int width, int height) const int buf_size = 8192; void * buf = av_malloc(buf_size); oc->pb = avio_alloc_context(static_cast(buf), buf_size, 1, - fh, NULL, write_packet, NULL); + fh, NULL, write_packet, seek_stream); if (!oc->pb) { averrno = AVERROR(ENOMEM); return false; diff --git a/src/moviemaker.cc b/src/moviemaker.cc index 102137f0..a884c538 100644 --- a/src/moviemaker.cc +++ b/src/moviemaker.cc @@ -101,6 +101,12 @@ write_packet(void *opaque, uint8_t *buf, int buf_size) { size_t res = fwrite(buf, 1, buf_size, fh); return res > 0 ? res : -1; } + +static int64_t +seek_stream(void *opaque, int64_t offset, int whence) { + FILE * fh = (FILE*)opaque; + return fseek(fh, offset, whence); +} #endif #define MAX_EXTENSION_LEN 8 @@ -230,7 +236,7 @@ bool MovieMaker::Open(FILE* fh, const char * ext, int width, int height) const int buf_size = 8192; void * buf = av_malloc(buf_size); oc->pb = avio_alloc_context(static_cast(buf), buf_size, 1, - fh, NULL, write_packet, NULL); + fh, NULL, write_packet, seek_stream); if (!oc->pb) { averrno = AVERROR(ENOMEM); return false; -- 2.11.4.GIT