X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Ftty.c;h=d4c4873b81dad941013dcf4fd9333b2d8e8b1e78;hb=70c77fdfc1076fd7f6cd20079237ddc97e1a10bc;hp=970274eb54fc8c937f3899b4c83622ab8bf83a6a;hpb=367732832faaf1bac4ece37cf7fef8c911e16312;p=ffmpeg diff --git a/libavformat/tty.c b/libavformat/tty.c index 970274eb54f..d4c4873b81d 100644 --- a/libavformat/tty.c +++ b/libavformat/tty.c @@ -27,16 +27,19 @@ #include "libavutil/intreadwrite.h" #include "libavutil/avstring.h" #include "libavutil/log.h" +#include "libavutil/dict.h" #include "libavutil/opt.h" #include "libavutil/parseutils.h" #include "avformat.h" +#include "internal.h" #include "sauce.h" -typedef struct { +typedef struct TtyDemuxContext { AVClass *class; int chars_per_frame; uint64_t fsize; /**< file size less metadata buffer */ char *video_size;/**< A string describing video size, set by a private option. */ + char *framerate; /**< Set by a private option. */ } TtyDemuxContext; /** @@ -59,7 +62,7 @@ static int efi_read(AVFormatContext *avctx, uint64_t start_pos) return -1; \ if (avio_read(pb, buf, size) == size) { \ buf[len] = 0; \ - av_metadata_set2(&avctx->metadata, name, buf, 0); \ + av_dict_set(&avctx->metadata, name, buf, 0); \ } GET_EFI_META("filename", 12) @@ -69,45 +72,35 @@ static int efi_read(AVFormatContext *avctx, uint64_t start_pos) return 0; } -static int read_header(AVFormatContext *avctx, - AVFormatParameters *ap) +static int read_header(AVFormatContext *avctx) { TtyDemuxContext *s = avctx->priv_data; int width = 0, height = 0, ret = 0; - AVStream *st = av_new_stream(avctx, 0); + AVStream *st = avformat_new_stream(avctx, NULL); + AVRational framerate; if (!st) { ret = AVERROR(ENOMEM); goto fail; } - st->codec->codec_tag = 0; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = CODEC_ID_ANSI; + st->codecpar->codec_tag = 0; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_ANSI; if (s->video_size && (ret = av_parse_video_size(&width, &height, s->video_size)) < 0) { av_log (avctx, AV_LOG_ERROR, "Couldn't parse video size.\n"); goto fail; } -#if FF_API_FORMAT_PARAMETERS - if (ap->width > 0) - width = ap->width; - if (ap->height > 0) - height = ap->height; -#endif - st->codec->width = width; - st->codec->height = height; - - if (!ap->time_base.num) { - av_set_pts_info(st, 60, 1, 25); - } else { - av_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den); + if ((ret = av_parse_video_rate(&framerate, s->framerate)) < 0) { + av_log(avctx, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s->framerate); + goto fail; } + st->codecpar->width = width; + st->codecpar->height = height; + avpriv_set_pts_info(st, 60, framerate.den, framerate.num); + st->avg_frame_rate = framerate; /* simulate tty display speed */ -#if FF_API_FORMAT_PARAMETERS - if (ap->sample_rate) - s->chars_per_frame = ap->sample_rate; -#endif s->chars_per_frame = FFMAX(av_q2d(st->time_base)*s->chars_per_frame, 1); if (avctx->pb->seekable) { @@ -150,8 +143,9 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt) #define OFFSET(x) offsetof(TtyDemuxContext, x) #define DEC AV_OPT_FLAG_DECODING_PARAM static const AVOption options[] = { - { "chars_per_frame", "", offsetof(TtyDemuxContext, chars_per_frame), FF_OPT_TYPE_INT, {.dbl = 6000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM}, - { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, + { "chars_per_frame", "", offsetof(TtyDemuxContext, chars_per_frame), AV_OPT_TYPE_INT, {.i64 = 6000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM}, + { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, + { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC }, { NULL }, };