X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fimg2.c;h=bc35591a0b2510ec2c86efb945891ff1536d676f;hb=dfa77dead2c97ec84092066102b14a2524d4d88b;hp=b5f88e0801f1411c0c2966b3349721505fea879f;hpb=102a2463d3a3f2c46f6ef9b30803491b91ffb653;p=ffmpeg diff --git a/libavformat/img2.c b/libavformat/img2.c index b5f88e0801f..bc35591a0b2 100644 --- a/libavformat/img2.c +++ b/libavformat/img2.c @@ -43,6 +43,7 @@ typedef struct { char *video_size; /**< Set by a private option. */ char *framerate; /**< Set by a private option. */ int loop; + int updatefirst; } VideoData; typedef struct { @@ -254,7 +255,7 @@ static int read_header(AVFormatContext *s1, AVFormatParameters *ap) st->need_parsing = AVSTREAM_PARSE_FULL; } - av_set_pts_info(st, 60, framerate.den, framerate.num); + avpriv_set_pts_info(st, 60, framerate.den, framerate.num); if (width && height) { st->codec->width = width; @@ -283,6 +284,8 @@ static int read_header(AVFormatContext *s1, AVFormatParameters *ap) s->split_planes = str && !av_strcasecmp(str + 1, "y"); st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = av_str2id(img_tags, s->path); + if (st->codec->codec_id == CODEC_ID_LJPEG) + st->codec->codec_id = CODEC_ID_MJPEG; } if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO && pix_fmt != PIX_FMT_NONE) st->codec->pix_fmt = pix_fmt; @@ -391,10 +394,11 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) if (!img->is_pipe) { if (av_get_frame_filename(filename, sizeof(filename), - img->path, img->img_number) < 0 && img->img_number==2) { - av_log(s, AV_LOG_WARNING, - "Writing multiple frames to the same file, check the pattern '%s' if this is not what you want\n", - img->path); + img->path, img->img_number) < 0 && img->img_number>1 && !img->updatefirst) { + av_log(s, AV_LOG_ERROR, + "Could not get frame filename number %d from pattern '%s'\n", + img->img_number, img->path); + return AVERROR(EINVAL); } for(i=0; i<3; i++){ if (avio_open2(&pb[i], filename, AVIO_FLAG_WRITE, @@ -442,7 +446,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) (!st->codec->extradata_size && AV_RL32(pkt->data+4) != MKTAG('j','P',' ',' '))){ // signature error: - av_log(s, AV_LOG_ERROR, "malformated jpeg2000 codestream %X\n", AV_RB32(pkt->data)); + av_log(s, AV_LOG_ERROR, "malformed JPEG 2000 codestream %X\n", AV_RB32(pkt->data)); return -1; } } @@ -461,6 +465,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) #define OFFSET(x) offsetof(VideoData, x) #define DEC AV_OPT_FLAG_DECODING_PARAM +#define ENC AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { { "pixel_format", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, { "video_size", "", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, @@ -469,6 +474,11 @@ static const AVOption options[] = { { NULL }, }; +static const AVOption muxoptions[] = { + { "updatefirst", "", OFFSET(updatefirst), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, ENC }, + { NULL }, +}; + /* input */ #if CONFIG_IMAGE2_DEMUXER static const AVClass img2_class = { @@ -507,6 +517,12 @@ AVInputFormat ff_image2pipe_demuxer = { /* output */ #if CONFIG_IMAGE2_MUXER +static const AVClass img2mux_class = { + .class_name = "image2 muxer", + .item_name = av_default_item_name, + .option = muxoptions, + .version = LIBAVUTIL_VERSION_INT, +}; AVOutputFormat ff_image2_muxer = { .name = "image2", .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"), @@ -516,7 +532,8 @@ AVOutputFormat ff_image2_muxer = { .video_codec = CODEC_ID_MJPEG, .write_header = write_header, .write_packet = write_packet, - .flags = AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS | AVFMT_NOFILE + .flags = AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS | AVFMT_NOFILE, + .priv_class = &img2mux_class, }; #endif #if CONFIG_IMAGE2PIPE_MUXER