aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorRonald S. Bultje <rsbultje@gmail.com>2015-07-10 21:15:35 -0400
committerMichael Niedermayer <michael@niedermayer.cc>2015-07-11 14:46:19 +0200
commit733c5d889b9887babbae85a5435e8f0d39473c51 (patch)
tree687d38943f79b82312f53d756e4f0078023187a5 /libavformat
parentc381af77c5a9581750b2534a95a1249c8f8953d3 (diff)
downloadffmpeg-733c5d889b9887babbae85a5435e8f0d39473c51.tar.gz
yuv4mpeg: add rough duration estimate and seeking.
Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/yuv4mpeg.h1
-rw-r--r--libavformat/yuv4mpegdec.c26
2 files changed, 20 insertions, 7 deletions
diff --git a/libavformat/yuv4mpeg.h b/libavformat/yuv4mpeg.h
index 750f498407..eba7337fe6 100644
--- a/libavformat/yuv4mpeg.h
+++ b/libavformat/yuv4mpeg.h
@@ -23,5 +23,6 @@
#define Y4M_MAGIC "YUV4MPEG2"
#define Y4M_FRAME_MAGIC "FRAME"
+#define Y4M_FRAME_MAGIC_LEN 6
#endif /* AVFORMAT_YUV4MPEG_H */
diff --git a/libavformat/yuv4mpegdec.c b/libavformat/yuv4mpegdec.c
index 7613c3cdc3..4ebdb7807c 100644
--- a/libavformat/yuv4mpegdec.c
+++ b/libavformat/yuv4mpegdec.c
@@ -256,6 +256,12 @@ static int yuv4_read_header(AVFormatContext *s)
st->sample_aspect_ratio = (AVRational){ aspectn, aspectd };
st->codec->chroma_sample_location = chroma_sample_location;
st->codec->field_order = field_order;
+ s->packet_size = avpicture_get_size(st->codec->pix_fmt, width, height) + Y4M_FRAME_MAGIC_LEN;
+ if ((int) s->packet_size < 0)
+ return s->packet_size;
+ s->internal->data_offset = avio_tell(pb);
+
+ st->duration = (avio_size(pb) - avio_tell(pb)) / s->packet_size;
return 0;
}
@@ -264,7 +270,7 @@ static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt)
{
int i;
char header[MAX_FRAME_HEADER+1];
- int packet_size, width, height, ret;
+ int width, height, ret, off = avio_tell(s->pb);
AVStream *st = s->streams[0];
for (i = 0; i < MAX_FRAME_HEADER; i++) {
@@ -287,17 +293,22 @@ static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt)
width = st->codec->width;
height = st->codec->height;
- packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
- if (packet_size < 0)
- return packet_size;
-
- ret = av_get_packet(s->pb, pkt, packet_size);
+ ret = av_get_packet(s->pb, pkt, s->packet_size - Y4M_FRAME_MAGIC_LEN);
if (ret < 0)
return ret;
- else if (ret != packet_size)
+ else if (ret != s->packet_size - Y4M_FRAME_MAGIC_LEN)
return s->pb->eof_reached ? AVERROR_EOF : AVERROR(EIO);
pkt->stream_index = 0;
+ pkt->pts = (off - s->internal->data_offset) / s->packet_size;
+ pkt->duration = 1;
+ return 0;
+}
+
+static int yuv4_read_seek(AVFormatContext *s, int stream_index,
+ int64_t pts, int flags)
+{
+ avio_seek(s->pb, pts * s->packet_size + s->internal->data_offset, SEEK_SET);
return 0;
}
@@ -316,5 +327,6 @@ AVInputFormat ff_yuv4mpegpipe_demuxer = {
.read_probe = yuv4_probe,
.read_header = yuv4_read_header,
.read_packet = yuv4_read_packet,
+ .read_seek = yuv4_read_seek,
.extensions = "y4m",
};