Browse code

tty: add framerate private option.

Anton Khirnov authored on 2011/06/04 03:58:01
Showing 1 changed files
... ...
@@ -37,6 +37,7 @@ typedef struct {
37 37
     int chars_per_frame;
38 38
     uint64_t fsize;  /**< file size less metadata buffer */
39 39
     char *video_size;/**< A string describing video size, set by a private option. */
40
+    char *framerate; /**< Set by a private option. */
40 41
 } TtyDemuxContext;
41 42
 
42 43
 /**
... ...
@@ -75,6 +76,7 @@ static int read_header(AVFormatContext *avctx,
75 75
     TtyDemuxContext *s = avctx->priv_data;
76 76
     int width = 0, height = 0, ret = 0;
77 77
     AVStream *st = av_new_stream(avctx, 0);
78
+    AVRational framerate;
78 79
 
79 80
     if (!st) {
80 81
         ret = AVERROR(ENOMEM);
... ...
@@ -88,20 +90,21 @@ static int read_header(AVFormatContext *avctx,
88 88
         av_log (avctx, AV_LOG_ERROR, "Couldn't parse video size.\n");
89 89
         goto fail;
90 90
     }
91
+    if ((ret = av_parse_video_rate(&framerate, s->framerate)) < 0) {
92
+        av_log(avctx, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s->framerate);
93
+        goto fail;
94
+    }
91 95
 #if FF_API_FORMAT_PARAMETERS
92 96
     if (ap->width > 0)
93 97
         width = ap->width;
94 98
     if (ap->height > 0)
95 99
         height = ap->height;
100
+    if (ap->time_base.num)
101
+        framerate = (AVRational){ap->time_base.den, ap->time_base.num};
96 102
 #endif
97 103
     st->codec->width  = width;
98 104
     st->codec->height = height;
99
-
100
-    if (!ap->time_base.num) {
101
-        av_set_pts_info(st, 60, 1, 25);
102
-    } else {
103
-        av_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den);
104
-    }
105
+    av_set_pts_info(st, 60, framerate.den, framerate.num);
105 106
 
106 107
     /* simulate tty display speed */
107 108
 #if FF_API_FORMAT_PARAMETERS
... ...
@@ -152,6 +155,7 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
152 152
 static const AVOption options[] = {
153 153
     { "chars_per_frame", "", offsetof(TtyDemuxContext, chars_per_frame), FF_OPT_TYPE_INT, {.dbl = 6000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM},
154 154
     { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
155
+    { "framerate", "", OFFSET(framerate), FF_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
155 156
     { NULL },
156 157
 };
157 158