Commit e762b1ce authored by Anton Khirnov's avatar Anton Khirnov

rawdec: add framerate private option.

parent ff494cbd
...@@ -61,11 +61,12 @@ static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -61,11 +61,12 @@ static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
AVInputFormat ff_ingenient_demuxer = { AVInputFormat ff_ingenient_demuxer = {
"ingenient", "ingenient",
NULL_IF_CONFIG_SMALL("raw Ingenient MJPEG"), NULL_IF_CONFIG_SMALL("raw Ingenient MJPEG"),
0, sizeof(FFRawVideoDemuxerContext),
NULL, NULL,
ff_raw_video_read_header, ff_raw_video_read_header,
ingenient_read_packet, ingenient_read_packet,
.flags= AVFMT_GENERIC_INDEX, .flags= AVFMT_GENERIC_INDEX,
.extensions = "cgi", // FIXME .extensions = "cgi", // FIXME
.value = CODEC_ID_MJPEG, .value = CODEC_ID_MJPEG,
.priv_class = &ff_rawvideo_demuxer_class,
}; };
...@@ -72,11 +72,8 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -72,11 +72,8 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
FFRawVideoDemuxerContext *s1 = s->priv_data; FFRawVideoDemuxerContext *s1 = s->priv_data;
int width = 0, height = 0, ret = 0; int width = 0, height = 0, ret = 0;
enum PixelFormat pix_fmt; enum PixelFormat pix_fmt;
AVRational framerate;
if(ap->time_base.num)
av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
else
av_set_pts_info(st, 64, 1, 25);
if (s1->video_size && (ret = av_parse_video_size(&width, &height, s1->video_size)) < 0) { if (s1->video_size && (ret = av_parse_video_size(&width, &height, s1->video_size)) < 0) {
av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n"); av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n");
goto fail; goto fail;
...@@ -86,6 +83,10 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -86,6 +83,10 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
ret = AVERROR(EINVAL); ret = AVERROR(EINVAL);
goto fail; goto fail;
} }
if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) {
av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate);
goto fail;
}
#if FF_API_FORMAT_PARAMETERS #if FF_API_FORMAT_PARAMETERS
if (ap->width > 0) if (ap->width > 0)
width = ap->width; width = ap->width;
...@@ -93,13 +94,17 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -93,13 +94,17 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
height = ap->height; height = ap->height;
if (ap->pix_fmt) if (ap->pix_fmt)
pix_fmt = ap->pix_fmt; pix_fmt = ap->pix_fmt;
if (ap->time_base.num)
framerate = (AVRational){ap->time_base.den, ap->time_base.num};
#endif #endif
av_set_pts_info(st, 64, framerate.den, framerate.num);
st->codec->width = width; st->codec->width = width;
st->codec->height = height; st->codec->height = height;
st->codec->pix_fmt = pix_fmt; st->codec->pix_fmt = pix_fmt;
fail: fail:
av_freep(&s1->video_size); av_freep(&s1->video_size);
av_freep(&s1->pixel_format); av_freep(&s1->pixel_format);
av_freep(&s1->framerate);
return ret; return ret;
} }
default: default:
...@@ -149,30 +154,36 @@ int ff_raw_video_read_header(AVFormatContext *s, ...@@ -149,30 +154,36 @@ int ff_raw_video_read_header(AVFormatContext *s,
AVFormatParameters *ap) AVFormatParameters *ap)
{ {
AVStream *st; AVStream *st;
FFRawVideoDemuxerContext *s1 = s->priv_data;
AVRational framerate;
int ret = 0;
st = av_new_stream(s, 0); st = av_new_stream(s, 0);
if (!st) if (!st) {
return AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto fail;
}
st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = s->iformat->value; st->codec->codec_id = s->iformat->value;
st->need_parsing = AVSTREAM_PARSE_FULL; st->need_parsing = AVSTREAM_PARSE_FULL;
/* for MJPEG, specify frame rate */ if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) {
/* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/ av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate);
if (ap->time_base.num) { goto fail;
st->codec->time_base= ap->time_base;
} else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
st->codec->codec_id == CODEC_ID_MPEG4 ||
st->codec->codec_id == CODEC_ID_DIRAC ||
st->codec->codec_id == CODEC_ID_DNXHD ||
st->codec->codec_id == CODEC_ID_VC1 ||
st->codec->codec_id == CODEC_ID_H264) {
st->codec->time_base= (AVRational){1,25};
} }
#if FF_API_FORMAT_PARAMETERS
if (ap->time_base.num)
framerate = (AVRational){ap->time_base.den, ap->time_base.num};
#endif
st->codec->time_base = (AVRational){framerate.den, framerate.num};
av_set_pts_info(st, 64, 1, 1200000); av_set_pts_info(st, 64, 1, 1200000);
return 0; fail:
av_freep(&s1->framerate);
return ret;
} }
/* Note: Do not forget to add new entries to the Makefile as well. */ /* Note: Do not forget to add new entries to the Makefile as well. */
...@@ -195,6 +206,7 @@ const AVClass ff_rawaudio_demuxer_class = { ...@@ -195,6 +206,7 @@ const AVClass ff_rawaudio_demuxer_class = {
static const AVOption video_options[] = { static const AVOption video_options[] = {
{ "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
{ "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = "yuv420p"}, 0, 0, DEC }, { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = "yuv420p"}, 0, 0, DEC },
{ "framerate", "", OFFSET(framerate), FF_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
{ NULL }, { NULL },
}; };
#undef OFFSET #undef OFFSET
......
...@@ -35,6 +35,7 @@ typedef struct FFRawVideoDemuxerContext { ...@@ -35,6 +35,7 @@ typedef struct FFRawVideoDemuxerContext {
const AVClass *class; /**< Class for private options. */ const AVClass *class; /**< Class for private options. */
char *video_size; /**< String describing video size, set by a private option. */ char *video_size; /**< String describing video size, set by a private option. */
char *pixel_format; /**< Set by a private option. */ char *pixel_format; /**< Set by a private option. */
char *framerate; /**< String describing framerate, set by a private option. */
} FFRawVideoDemuxerContext; } FFRawVideoDemuxerContext;
extern const AVClass ff_rawaudio_demuxer_class; extern const AVClass ff_rawaudio_demuxer_class;
...@@ -58,6 +59,8 @@ AVInputFormat ff_ ## shortname ## _demuxer = {\ ...@@ -58,6 +59,8 @@ AVInputFormat ff_ ## shortname ## _demuxer = {\
.extensions = ext,\ .extensions = ext,\
.flags = AVFMT_GENERIC_INDEX,\ .flags = AVFMT_GENERIC_INDEX,\
.value = id,\ .value = id,\
.priv_data_size = sizeof(FFRawVideoDemuxerContext),\
.priv_class = &ff_rawvideo_demuxer_class,\
}; };
#endif /* AVFORMAT_RAWDEC_H */ #endif /* AVFORMAT_RAWDEC_H */
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