summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorTheAMM <the.actual.amm@gmail.com>2021-05-29 01:28:15 +0300
committerJan Ekström <jeebjp@gmail.com>2021-07-08 12:44:06 +0300
commit4d3df1c842532e3a48578ab6daef39076289c8ef (patch)
treef38668f28dca977818525416494c162f42f65b51 /common
parentf9527497c68c86b247ade965dafe362f0f43be09 (diff)
downloadmpv-4d3df1c842532e3a48578ab6daef39076289c8ef.tar.bz2
mpv-4d3df1c842532e3a48578ab6daef39076289c8ef.tar.xz
recorder: add support for attachments (fonts)
Though, only when the output format is matroska, to avoid muxing errors. This is quite useful when the input has ASS subtitles, as they tend to rely on embedded fonts.
Diffstat (limited to 'common')
-rw-r--r--common/recorder.c34
-rw-r--r--common/recorder.h5
2 files changed, 37 insertions, 2 deletions
diff --git a/common/recorder.c b/common/recorder.c
index 1621e8a602..0cbc81d51c 100644
--- a/common/recorder.c
+++ b/common/recorder.c
@@ -23,6 +23,7 @@
#include "common/common.h"
#include "common/global.h"
#include "common/msg.h"
+#include "demux/demux.h"
#include "demux/packet.h"
#include "demux/stheader.h"
@@ -119,7 +120,9 @@ static int add_stream(struct mp_recorder *priv, struct sh_stream *sh)
struct mp_recorder *mp_recorder_create(struct mpv_global *global,
const char *target_file,
struct sh_stream **streams,
- int num_streams)
+ int num_streams,
+ struct demux_attachment **attachments,
+ int num_attachments)
{
struct mp_recorder *priv = talloc_zero(NULL, struct mp_recorder);
@@ -153,6 +156,35 @@ struct mp_recorder *mp_recorder_create(struct mpv_global *global,
}
}
+ if (!strcmp(priv->mux->oformat->name, "matroska")) {
+ // Only attach attachments (fonts) to matroska - mp4, nut, mpegts don't
+ // like them, and we find that out too late in the muxing process.
+ AVStream *a_stream = NULL;
+ for (int i = 0; i < num_attachments; ++i) {
+ a_stream = avformat_new_stream(priv->mux, NULL);
+ if (!a_stream) {
+ MP_ERR(priv, "Can't mux one of the attachments.\n");
+ goto error;
+ }
+ struct demux_attachment *attachment = attachments[i];
+
+ a_stream->codecpar->codec_type = AVMEDIA_TYPE_ATTACHMENT;
+
+ a_stream->codecpar->extradata = av_mallocz(
+ attachment->data_size + AV_INPUT_BUFFER_PADDING_SIZE
+ );
+ if (!a_stream->codecpar->extradata) {
+ goto error;
+ }
+ memcpy(a_stream->codecpar->extradata,
+ attachment->data, attachment->data_size);
+ a_stream->codecpar->extradata_size = attachment->data_size;
+
+ av_dict_set(&a_stream->metadata, "filename", attachment->name, 0);
+ av_dict_set(&a_stream->metadata, "mimetype", attachment->type, 0);
+ }
+ }
+
// Not sure how to write this in a "standard" way. It appears only mkv
// and mp4 support this directly.
char version[200];
diff --git a/common/recorder.h b/common/recorder.h
index c0b1e36495..e86d978067 100644
--- a/common/recorder.h
+++ b/common/recorder.h
@@ -5,12 +5,15 @@ struct mp_recorder;
struct mpv_global;
struct demux_packet;
struct sh_stream;
+struct demux_attachment;
struct mp_recorder_sink;
struct mp_recorder *mp_recorder_create(struct mpv_global *global,
const char *target_file,
struct sh_stream **streams,
- int num_streams);
+ int num_streams,
+ struct demux_attachment **demux_attachments,
+ int num_attachments);
void mp_recorder_destroy(struct mp_recorder *r);
void mp_recorder_mark_discontinuity(struct mp_recorder *r);