Browse code

rawdec: add video_size private option.

Anton Khirnov authored on 2011/05/24 14:43:01
Showing 3 changed files
... ...
@@ -24,6 +24,7 @@
24 24
 #include "avio_internal.h"
25 25
 #include "rawdec.h"
26 26
 #include "libavutil/opt.h"
27
+#include "libavutil/parseutils.h"
27 28
 
28 29
 /* raw input */
29 30
 int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
... ...
@@ -66,17 +67,34 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
66 66
             av_set_pts_info(st, 64, 1, st->codec->sample_rate);
67 67
             break;
68 68
             }
69
-        case AVMEDIA_TYPE_VIDEO:
69
+        case AVMEDIA_TYPE_VIDEO: {
70
+            FFRawVideoDemuxerContext *s1 = s->priv_data;
71
+            int width = 0, height = 0, ret;
70 72
             if(ap->time_base.num)
71 73
                 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
72 74
             else
73 75
                 av_set_pts_info(st, 64, 1, 25);
74
-            st->codec->width = ap->width;
75
-            st->codec->height = ap->height;
76
+            if (s1->video_size) {
77
+                ret = av_parse_video_size(&width, &height, s1->video_size);
78
+                av_freep(&s1->video_size);
79
+                if (ret < 0) {
80
+                    av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n");
81
+                    return ret;
82
+                }
83
+            }
84
+#if FF_API_FORMAT_PARAMETERS
85
+            if (ap->width > 0)
86
+                width = ap->width;
87
+            if (ap->height > 0)
88
+                height = ap->height;
89
+#endif
90
+            st->codec->width  = width;
91
+            st->codec->height = height;
76 92
             st->codec->pix_fmt = ap->pix_fmt;
77 93
             if(st->codec->pix_fmt == PIX_FMT_NONE)
78 94
                 st->codec->pix_fmt= PIX_FMT_YUV420P;
79 95
             break;
96
+            }
80 97
         default:
81 98
             return -1;
82 99
         }
... ...
@@ -165,6 +183,22 @@ const AVClass ff_rawaudio_demuxer_class = {
165 165
     .version        = LIBAVUTIL_VERSION_INT,
166 166
 };
167 167
 
168
+#define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
169
+#define DEC AV_OPT_FLAG_DECODING_PARAM
170
+static const AVOption video_options[] = {
171
+    { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
172
+    { NULL },
173
+};
174
+#undef OFFSET
175
+#undef DEC
176
+
177
+const AVClass ff_rawvideo_demuxer_class = {
178
+    .class_name     = "rawvideo demuxer",
179
+    .item_name      = av_default_item_name,
180
+    .option         = video_options,
181
+    .version        = LIBAVUTIL_VERSION_INT,
182
+};
183
+
168 184
 #if CONFIG_G722_DEMUXER
169 185
 AVInputFormat ff_g722_demuxer = {
170 186
     "g722",
... ...
@@ -31,7 +31,13 @@ typedef struct RawAudioDemuxerContext {
31 31
     int channels;
32 32
 } RawAudioDemuxerContext;
33 33
 
34
+typedef struct FFRawVideoDemuxerContext {
35
+    const AVClass *class;     /**< Class for private options. */
36
+    char *video_size;         /**< String describing video size, set by a private option. */
37
+} FFRawVideoDemuxerContext;
38
+
34 39
 extern const AVClass ff_rawaudio_demuxer_class;
40
+extern const AVClass ff_rawvideo_demuxer_class;
35 41
 
36 42
 int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap);
37 43
 
... ...
@@ -47,11 +47,12 @@ static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
47 47
 AVInputFormat ff_rawvideo_demuxer = {
48 48
     "rawvideo",
49 49
     NULL_IF_CONFIG_SMALL("raw video format"),
50
-    0,
50
+    sizeof(FFRawVideoDemuxerContext),
51 51
     NULL,
52 52
     ff_raw_read_header,
53 53
     rawvideo_read_packet,
54 54
     .flags= AVFMT_GENERIC_INDEX,
55 55
     .extensions = "yuv,cif,qcif,rgb",
56 56
     .value = CODEC_ID_RAWVIDEO,
57
+    .priv_class = &ff_rawvideo_demuxer_class,
57 58
 };