Commit c69ff12d authored by Rodger Combs's avatar Rodger Combs Committed by Michael Niedermayer

lavf/mpeg: vobsub add an option to specify the .sub's URI

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 30ce065f
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#if CONFIG_VOBSUB_DEMUXER #if CONFIG_VOBSUB_DEMUXER
# include "subtitles.h" # include "subtitles.h"
# include "libavutil/bprint.h" # include "libavutil/bprint.h"
# include "libavutil/opt.h"
#endif #endif
#include "libavutil/avassert.h" #include "libavutil/avassert.h"
...@@ -121,6 +122,7 @@ static int mpegps_probe(AVProbeData *p) ...@@ -121,6 +122,7 @@ static int mpegps_probe(AVProbeData *p)
} }
typedef struct MpegDemuxContext { typedef struct MpegDemuxContext {
AVClass *class;
int32_t header_state; int32_t header_state;
unsigned char psm_es_type[256]; unsigned char psm_es_type[256];
int sofdec; int sofdec;
...@@ -129,6 +131,7 @@ typedef struct MpegDemuxContext { ...@@ -129,6 +131,7 @@ typedef struct MpegDemuxContext {
#if CONFIG_VOBSUB_DEMUXER #if CONFIG_VOBSUB_DEMUXER
AVFormatContext *sub_ctx; AVFormatContext *sub_ctx;
FFDemuxSubtitlesQueue q[32]; FFDemuxSubtitlesQueue q[32];
char *sub_name;
#endif #endif
} MpegDemuxContext; } MpegDemuxContext;
...@@ -684,9 +687,8 @@ static int vobsub_read_header(AVFormatContext *s) ...@@ -684,9 +687,8 @@ static int vobsub_read_header(AVFormatContext *s)
{ {
int i, ret = 0, header_parsed = 0, langidx = 0; int i, ret = 0, header_parsed = 0, langidx = 0;
MpegDemuxContext *vobsub = s->priv_data; MpegDemuxContext *vobsub = s->priv_data;
char *sub_name = NULL;
size_t fname_len; size_t fname_len;
char *ext, *header_str; char *header_str;
AVBPrint header; AVBPrint header;
int64_t delay = 0; int64_t delay = 0;
AVStream *st = NULL; AVStream *st = NULL;
...@@ -695,17 +697,25 @@ static int vobsub_read_header(AVFormatContext *s) ...@@ -695,17 +697,25 @@ static int vobsub_read_header(AVFormatContext *s)
char alt[MAX_LINE_SIZE] = {0}; char alt[MAX_LINE_SIZE] = {0};
AVInputFormat *iformat; AVInputFormat *iformat;
sub_name = av_strdup(s->filename); if (!vobsub->sub_name) {
fname_len = strlen(sub_name); char *ext;
ext = sub_name - 3 + fname_len; vobsub->sub_name = av_strdup(s->filename);
if (fname_len < 4 || *(ext - 1) != '.') { if (!vobsub->sub_name) {
av_log(s, AV_LOG_ERROR, "The input index filename is too short " ret = AVERROR(ENOMEM);
"to guess the associated .SUB file\n"); goto end;
ret = AVERROR_INVALIDDATA; }
goto end;
fname_len = strlen(vobsub->sub_name);
ext = vobsub->sub_name - 3 + fname_len;
if (fname_len < 4 || *(ext - 1) != '.') {
av_log(s, AV_LOG_ERROR, "The input index filename is too short "
"to guess the associated .SUB file\n");
ret = AVERROR_INVALIDDATA;
goto end;
}
memcpy(ext, !strncmp(ext, "IDX", 3) ? "SUB" : "sub", 3);
av_log(s, AV_LOG_VERBOSE, "IDX/SUB: %s -> %s\n", s->filename, vobsub->sub_name);
} }
memcpy(ext, !strncmp(ext, "IDX", 3) ? "SUB" : "sub", 3);
av_log(s, AV_LOG_VERBOSE, "IDX/SUB: %s -> %s\n", s->filename, sub_name);
if (!(iformat = av_find_input_format("mpeg"))) { if (!(iformat = av_find_input_format("mpeg"))) {
ret = AVERROR_DEMUXER_NOT_FOUND; ret = AVERROR_DEMUXER_NOT_FOUND;
...@@ -721,9 +731,9 @@ static int vobsub_read_header(AVFormatContext *s) ...@@ -721,9 +731,9 @@ static int vobsub_read_header(AVFormatContext *s)
if ((ret = ff_copy_whitelists(vobsub->sub_ctx, s)) < 0) if ((ret = ff_copy_whitelists(vobsub->sub_ctx, s)) < 0)
goto end; goto end;
ret = avformat_open_input(&vobsub->sub_ctx, sub_name, iformat, NULL); ret = avformat_open_input(&vobsub->sub_ctx, vobsub->sub_name, iformat, NULL);
if (ret < 0) { if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Unable to open %s as MPEG subtitles\n", sub_name); av_log(s, AV_LOG_ERROR, "Unable to open %s as MPEG subtitles\n", vobsub->sub_name);
goto end; goto end;
} }
...@@ -860,7 +870,6 @@ static int vobsub_read_header(AVFormatContext *s) ...@@ -860,7 +870,6 @@ static int vobsub_read_header(AVFormatContext *s)
av_free(header_str); av_free(header_str);
end: end:
av_free(sub_name);
return ret; return ret;
} }
...@@ -996,6 +1005,18 @@ static int vobsub_read_close(AVFormatContext *s) ...@@ -996,6 +1005,18 @@ static int vobsub_read_close(AVFormatContext *s)
return 0; return 0;
} }
static const AVOption options[] = {
{ "sub_name", "URI for .sub file", offsetof(MpegDemuxContext, sub_name), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
{ NULL }
};
static const AVClass vobsub_demuxer_class = {
.class_name = "vobsub",
.item_name = av_default_item_name,
.option = options,
.version = LIBAVUTIL_VERSION_INT,
};
AVInputFormat ff_vobsub_demuxer = { AVInputFormat ff_vobsub_demuxer = {
.name = "vobsub", .name = "vobsub",
.long_name = NULL_IF_CONFIG_SMALL("VobSub subtitle format"), .long_name = NULL_IF_CONFIG_SMALL("VobSub subtitle format"),
...@@ -1007,5 +1028,6 @@ AVInputFormat ff_vobsub_demuxer = { ...@@ -1007,5 +1028,6 @@ AVInputFormat ff_vobsub_demuxer = {
.read_close = vobsub_read_close, .read_close = vobsub_read_close,
.flags = AVFMT_SHOW_IDS, .flags = AVFMT_SHOW_IDS,
.extensions = "idx", .extensions = "idx",
.priv_class = &vobsub_demuxer_class,
}; };
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment