diff --git a/libavformat/bintext.c b/libavformat/bintext.c index d9395f0798..c85222756e 100644 --- a/libavformat/bintext.c +++ b/libavformat/bintext.c @@ -31,15 +31,20 @@ */ #include "libavutil/intreadwrite.h" +#include "libavutil/opt.h" +#include "libavutil/parseutils.h" #include "avformat.h" #include "internal.h" #include "sauce.h" #include "libavcodec/bintext.h" -#define LINE_RATE 6000 /** characters per second */ - typedef struct { - int chars_per_frame; + const AVClass *class; + int chars_per_frame; /**< characters to send decoder per frame; + set by private options as characters per second, and then + converted to characters per frame at runtime */ + char *video_size; /**< video size (WxH pixels) (private option) */ + char *framerate; /**< frames per second (private option) */ uint64_t fsize; /**< file size less metadata buffer */ } BinDemuxContext; @@ -108,17 +113,30 @@ static AVStream * init_stream(AVFormatContext *s) st->codec->codec_tag = 0; st->codec->codec_type = AVMEDIA_TYPE_VIDEO; -// if (!ap->time_base.num) { + if (bin->video_size) { + if (av_parse_video_size(&st->codec->width, &st->codec->height, bin->video_size) < 0) { + av_log(s, AV_LOG_ERROR, "Could not parse video size: '%s'\n", bin->video_size); + return NULL; + } + } else { + st->codec->width = (80<<3); + st->codec->height = (25<<4); + } + + if (bin->framerate) { + AVRational framerate; + if (av_parse_video_rate(&framerate, bin->framerate) < 0) { + av_log(s, AV_LOG_ERROR, "Could not parse framerate: '%s'\n", bin->framerate); + return NULL; + } + avpriv_set_pts_info(st, 60, framerate.den, framerate.num); + } else { avpriv_set_pts_info(st, 60, 1, 25); -// } else { -// avpriv_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den); -// } + } /* simulate tty display speed */ - bin->chars_per_frame = FFMAX(av_q2d(st->time_base) * (/*ap->sample_rate ? ap->sample_rate :*/ LINE_RATE), 1); + bin->chars_per_frame = FFMAX(av_q2d(st->time_base) * bin->chars_per_frame, 1); - st->codec->width = /*ap->width ? ap->width :*/ (80<<3); - st->codec->height = /*ap->height ? ap->height :*/ (25<<4); return st; } @@ -144,10 +162,10 @@ static int bintext_read_header(AVFormatContext *s) bin->fsize = avio_size(pb); if (ff_sauce_read(s, &bin->fsize, &got_width, 0) < 0) next_tag_read(s, &bin->fsize); -// if (!ap->width) + if (!bin->video_size) { predict_width(st->codec, bin->fsize, got_width); -// if (!ap->height) calculate_height(st->codec, bin->fsize); + } avio_seek(pb, 0, SEEK_SET); } return 0; @@ -243,7 +261,7 @@ static int adf_read_header(AVFormatContext *s) bin->fsize = avio_size(pb) - 1 - 192 - 4096; st->codec->width = 80<<3; ff_sauce_read(s, &bin->fsize, &got_width, 0); -// if (!ap->height) + if (!bin->video_size) calculate_height(st->codec, bin->fsize); avio_seek(pb, 1 + 192 + 4096, SEEK_SET); } @@ -296,7 +314,7 @@ static int idf_read_header(AVFormatContext *s) bin->fsize = avio_size(pb) - 12 - 4096 - 48; ff_sauce_read(s, &bin->fsize, &got_width, 0); -// if (!ap->height) + if (!bin->video_size) calculate_height(st->codec, bin->fsize); avio_seek(pb, 12, SEEK_SET); return 0; @@ -325,6 +343,22 @@ static int read_packet(AVFormatContext *s, return 0; } +#define OFFSET(x) offsetof(BinDemuxContext, x) +static const AVOption options[] = { + { "linespeed", "set simulated line speed (bytes per second)", OFFSET(chars_per_frame), AV_OPT_TYPE_INT, {.dbl = 6000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM}, + { "video_size", "set video size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, + { "framerate", "set framerate (frames per second)", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, + { NULL }, +}; + +#define CLASS(name) \ +(const AVClass[1]){{ \ + .class_name = name, \ + .item_name = av_default_item_name, \ + .option = options, \ + .version = LIBAVUTIL_VERSION_INT, \ +}} + #if CONFIG_BINTEXT_DEMUXER AVInputFormat ff_bintext_demuxer = { .name = "bin", @@ -333,6 +367,7 @@ AVInputFormat ff_bintext_demuxer = { .read_header = bintext_read_header, .read_packet = read_packet, .extensions = "bin", + .priv_class = CLASS("Binary text demuxer"), }; #endif @@ -344,6 +379,7 @@ AVInputFormat ff_xbin_demuxer = { .read_probe = xbin_probe, .read_header = xbin_read_header, .read_packet = read_packet, + .priv_class = CLASS("eXtended BINary text (XBIN) demuxer"), }; #endif @@ -355,6 +391,7 @@ AVInputFormat ff_adf_demuxer = { .read_header = adf_read_header, .read_packet = read_packet, .extensions = "adf", + .priv_class = CLASS("Artworx Data Format demuxer"), }; #endif @@ -367,5 +404,6 @@ AVInputFormat ff_idf_demuxer = { .read_header = idf_read_header, .read_packet = read_packet, .extensions = "idf", + .priv_class = CLASS("iCE Draw File demuxer"), }; #endif