aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <nfxjfg@googlemail.com>2014-03-02 22:36:42 +0100
committerClément Bœsch <u@pkh.me>2014-03-03 23:33:47 +0100
commitb416517cce6b05bcdd838b8f34a0050e729beec2 (patch)
treeb39a47944916e8b696529d2f00199075aee5bab0
parent0786598f51ce0811cce7a087ba76fa6fd984327e (diff)
downloadffmpeg-b416517cce6b05bcdd838b8f34a0050e729beec2.tar.gz
avformat/microdvd: export the declared frame rate
MicroDVD files are normally frame-based (i.e. there are no absolute timestamps), but can have an optional frame rate header. If this header is missing, the timestamps depend on the frame rate of the video they were created for. The demuxer will use a fallback frame rate if it's missing from the header. Currently, applications using libavformat can't know whether the time base is based on the fallback value, or if a frame rate header was present. This commit introduces a subfps AVOption for MicroDVD, and the demuxer sets it if and only if a frame rate header was present. Signed-off-by: Clément Bœsch <u@pkh.me>
-rw-r--r--libavformat/microdvddec.c31
-rw-r--r--libavformat/version.h2
2 files changed, 31 insertions, 2 deletions
diff --git a/libavformat/microdvddec.c b/libavformat/microdvddec.c
index 42c6de0098..49d2b68192 100644
--- a/libavformat/microdvddec.c
+++ b/libavformat/microdvddec.c
@@ -24,12 +24,15 @@
#include "internal.h"
#include "subtitles.h"
#include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
#define MAX_LINESIZE 2048
typedef struct {
+ const AVClass *class;
FFDemuxSubtitlesQueue q;
+ AVRational frame_rate;
} MicroDVDContext;
@@ -80,6 +83,7 @@ static int microdvd_read_header(AVFormatContext *s)
AVStream *st = avformat_new_stream(s, NULL);
int i = 0;
char line_buf[MAX_LINESIZE];
+ int has_real_fps = 0;
if (!st)
return AVERROR(ENOMEM);
@@ -105,8 +109,10 @@ static int microdvd_read_header(AVFormatContext *s)
if ((sscanf(line, "{%d}{}%6lf", &frame, &fps) == 2 ||
sscanf(line, "{%d}{%*d}%6lf", &frame, &fps) == 2)
- && frame <= 1 && fps > 3 && fps < 100)
+ && frame <= 1 && fps > 3 && fps < 100) {
pts_info = av_d2q(fps, 100000);
+ has_real_fps = 1;
+ }
if (!st->codec->extradata && sscanf(line, "{DEFAULT}{}%c", &c) == 1) {
st->codec->extradata = av_strdup(line + 11);
if (!st->codec->extradata)
@@ -135,6 +141,13 @@ static int microdvd_read_header(AVFormatContext *s)
sub->duration = get_duration(line);
}
ff_subtitles_queue_finalize(&microdvd->q);
+ if (has_real_fps) {
+ /* export the FPS info only if set in the file */
+ microdvd->frame_rate = pts_info;
+ } else if (microdvd->frame_rate.num) {
+ /* fallback on user specified frame rate */
+ pts_info = microdvd->frame_rate;
+ }
avpriv_set_pts_info(st, 64, pts_info.den, pts_info.num);
st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
st->codec->codec_id = AV_CODEC_ID_MICRODVD;
@@ -162,6 +175,21 @@ static int microdvd_read_close(AVFormatContext *s)
return 0;
}
+
+#define OFFSET(x) offsetof(MicroDVDContext, x)
+#define SD AV_OPT_FLAG_SUBTITLE_PARAM|AV_OPT_FLAG_DECODING_PARAM
+static const AVOption microdvd_options[] = {
+ { "subfps", "set the movie frame rate fallback", OFFSET(frame_rate), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX, SD },
+ { NULL }
+};
+
+static const AVClass microdvd_class = {
+ .class_name = "microdvddec",
+ .item_name = av_default_item_name,
+ .option = microdvd_options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVInputFormat ff_microdvd_demuxer = {
.name = "microdvd",
.long_name = NULL_IF_CONFIG_SMALL("MicroDVD subtitle format"),
@@ -171,4 +199,5 @@ AVInputFormat ff_microdvd_demuxer = {
.read_packet = microdvd_read_packet,
.read_seek2 = microdvd_read_seek,
.read_close = microdvd_read_close,
+ .priv_class = &microdvd_class,
};
diff --git a/libavformat/version.h b/libavformat/version.h
index 9f0695c86d..7b011b2734 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,7 +31,7 @@
#define LIBAVFORMAT_VERSION_MAJOR 55
#define LIBAVFORMAT_VERSION_MINOR 33
-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \