| @@ -22,12 +22,17 @@ · 21 unmodified lines |
| 22 | 22 | |
| 23 | 23 | #include "libavutil/intreadwrite.h" |
| 24 | 24 | #include "libavutil/avstring.h" |
| 25 | +#include "libavutil/log.h" |
| 26 | +#include "libavutil/opt.h" |
| 27 | +#include "libavutil/pixdesc.h" |
| 28 | +#include "libavutil/parseutils.h" |
| 25 | 29 | #include "avformat.h" |
| 26 | 30 | #include "avio_internal.h" |
| 27 | 31 | #include "internal.h" |
| 28 | 32 | #include <strings.h> |
| 29 | 33 | |
| 30 | 34 | typedef struct { |
| 35 | + const AVClass *class; /**< Class for private options. */ |
| 31 | 36 | int img_first; |
| 32 | 37 | int img_last; |
| 33 | 38 | int img_number; |
| @@ -35,6 +40,9 @@ typedef struct { · 1 unmodified line |
| 35 | 40 | int is_pipe; |
| 36 | 41 | int split_planes; /**< use independent file for each Y, U, V plane */ |
| 37 | 42 | char path[1024]; |
| 43 | + char *pixel_format; /**< Set by a private option. */ |
| 44 | + char *video_size; /**< Set by a private option. */ |
| 45 | + char *framerate; /**< Set by a private option. */ |
| 38 | 46 | } VideoData; |
| 39 | 47 | |
| 40 | 48 | typedef struct { |
| @@ -202,8 +210,11 @@ enum CodecID av_guess_image2_codec(const char *filename){ · 161 unmodified lines |
| 202 | 210 | static int read_header(AVFormatContext *s1, AVFormatParameters *ap) |
| 203 | 211 | { |
| 204 | 212 | VideoData *s = s1->priv_data; |
| 205 | | − int first_index, last_index; |
| 213 | + int first_index, last_index, ret = 0; |
| 214 | + int width = 0, height = 0; |
| 206 | 215 | AVStream *st; |
| 216 | + enum PixelFormat pix_fmt = PIX_FMT_NONE; |
| 217 | + AVRational framerate; |
| 207 | 218 | |
| 208 | 219 | s1->ctx_flags |= AVFMTCTX_NOHEADER; |
| 209 | 220 | |
| @@ -212,6 +223,29 @@ static int read_header(AVFormatContext *s1, AVFormatParameters *ap) · 2 unmodified lines |
| 212 | 223 | return AVERROR(ENOMEM); |
| 213 | 224 | } |
| 214 | 225 | |
| 226 | + if (s->pixel_format && (pix_fmt = av_get_pix_fmt(s->pixel_format)) == PIX_FMT_NONE) { |
| 227 | + av_log(s1, AV_LOG_ERROR, "No such pixel format: %s.\n", s->pixel_format); |
| 228 | + return AVERROR(EINVAL); |
| 229 | + } |
| 230 | + if (s->video_size && (ret = av_parse_video_size(&width, &height, s->video_size)) < 0) { |
| 231 | + av_log(s, AV_LOG_ERROR, "Could not parse video size: %s.\n", s->video_size); |
| 232 | + return ret; |
| 233 | + } |
| 234 | + if ((ret = av_parse_video_rate(&framerate, s->framerate)) < 0) { |
| 235 | + av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s->framerate); |
| 236 | + return ret; |
| 237 | + } |
| 238 | +#if FF_API_FORMAT_PARAMETERS |
| 239 | + if (ap->pix_fmt != PIX_FMT_NONE) |
| 240 | + pix_fmt = ap->pix_fmt; |
| 241 | + if (ap->width > 0) |
| 242 | + width = ap->width; |
| 243 | + if (ap->height > 0) |
| 244 | + height = ap->height; |
| 245 | + if (ap->time_base.num) |
| 246 | + framerate = (AVRational){ap->time_base.den, ap->time_base.num}; |
| 247 | +#endif |
| 248 | + |
| 215 | 249 | av_strlcpy(s->path, s1->filename, sizeof(s->path)); |
| 216 | 250 | s->img_number = 0; |
| 217 | 251 | s->img_count = 0; |
| @@ -224,15 +258,11 @@ static int read_header(AVFormatContext *s1, AVFormatParameters *ap) · 6 unmodified lines |
| 224 | 258 | st->need_parsing = AVSTREAM_PARSE_FULL; |
| 225 | 259 | } |
| 226 | 260 | |
| 227 | | − if (!ap->time_base.num) { |
| 228 | | − av_set_pts_info(st, 60, 1, 25); |
| 229 | | − } else { |
| 230 | | − av_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den); |
| 231 | | − } |
| 261 | + av_set_pts_info(st, 60, framerate.den, framerate.num); |
| 232 | 262 | |
| 233 | | − if(ap->width && ap->height){ |
| 234 | | − st->codec->width = ap->width; |
| 235 | | − st->codec->height= ap->height; |
| 263 | + if (width && height) { |
| 264 | + st->codec->width = width; |
| 265 | + st->codec->height = height; |
| 236 | 266 | } |
| 237 | 267 | |
| 238 | 268 | if (!s->is_pipe) { |
| @@ -258,8 +288,8 @@ static int read_header(AVFormatContext *s1, AVFormatParameters *ap) · 19 unmodified lines |
| 258 | 288 | st->codec->codec_type = AVMEDIA_TYPE_VIDEO; |
| 259 | 289 | st->codec->codec_id = av_str2id(img_tags, s->path); |
| 260 | 290 | } |
| 261 | | − if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ap->pix_fmt != PIX_FMT_NONE) |
| 262 | | − st->codec->pix_fmt = ap->pix_fmt; |
| 291 | + if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO && pix_fmt != PIX_FMT_NONE) |
| 292 | + st->codec->pix_fmt = pix_fmt; |
| 263 | 293 | |
| 264 | 294 | return 0; |
| 265 | 295 | } |
| @@ -430,6 +460,22 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) · 164 unmodified lines |
| 430 | 460 | |
| 431 | 461 | #endif /* CONFIG_IMAGE2_MUXER || CONFIG_IMAGE2PIPE_MUXER */ |
| 432 | 462 | |
| 463 | +#define OFFSET(x) offsetof(VideoData, x) |
| 464 | +#define DEC AV_OPT_FLAG_DECODING_PARAM |
| 465 | +static const AVOption options[] = { |
| 466 | + { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, |
| 467 | + { "video_size", "", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, |
| 468 | + { "framerate", "", OFFSET(framerate), FF_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC }, |
| 469 | + { NULL }, |
| 470 | +}; |
| 471 | + |
| 472 | +static const AVClass img2_class = { |
| 473 | + .class_name = "image2 demuxer", |
| 474 | + .item_name = av_default_item_name, |
| 475 | + .option = options, |
| 476 | + .version = LIBAVUTIL_VERSION_INT, |
| 477 | +}; |
| 478 | + |
| 433 | 479 | /* input */ |
| 434 | 480 | #if CONFIG_IMAGE2_DEMUXER |
| 435 | 481 | AVInputFormat ff_image2_demuxer = { |
| @@ -440,6 +486,7 @@ AVInputFormat ff_image2_demuxer = { · 4 unmodified lines |
| 440 | 486 | .read_header = read_header, |
| 441 | 487 | .read_packet = read_packet, |
| 442 | 488 | .flags = AVFMT_NOFILE, |
| 489 | + .priv_class = &img2_class, |
| 443 | 490 | }; |
| 444 | 491 | #endif |
| 445 | 492 | #if CONFIG_IMAGE2PIPE_DEMUXER |
| @@ -449,6 +496,7 @@ AVInputFormat ff_image2pipe_demuxer = { · 3 unmodified lines |
| 449 | 496 | .priv_data_size = sizeof(VideoData), |
| 450 | 497 | .read_header = read_header, |
| 451 | 498 | .read_packet = read_packet, |
| 499 | + .priv_class = &img2_class, |
| 452 | 500 | }; |
| 453 | 501 | #endif |
| 454 | 502 | |