Browse code

rawdec: add a pixel_format private option.

Anton Khirnov authored on 2011/05/24 16:02:11
Showing 2 changed files
... ...
@@ -25,6 +25,7 @@
25 25
 #include "rawdec.h"
26 26
 #include "libavutil/opt.h"
27 27
 #include "libavutil/parseutils.h"
28
+#include "libavutil/pixdesc.h"
28 29
 
29 30
 /* raw input */
30 31
 int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
... ...
@@ -70,30 +71,37 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
70 70
         case AVMEDIA_TYPE_VIDEO: {
71 71
             FFRawVideoDemuxerContext *s1 = s->priv_data;
72 72
             int width = 0, height = 0, ret;
73
+            enum PixelFormat pix_fmt;
74
+
73 75
             if(ap->time_base.num)
74 76
                 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
75 77
             else
76 78
                 av_set_pts_info(st, 64, 1, 25);
77
-            if (s1->video_size) {
78
-                ret = av_parse_video_size(&width, &height, s1->video_size);
79
-                av_freep(&s1->video_size);
80
-                if (ret < 0) {
81
-                    av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n");
82
-                    return ret;
83
-                }
79
+            if (s1->video_size && (ret = av_parse_video_size(&width, &height, s1->video_size)) < 0) {
80
+                av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n");
81
+                goto fail;
82
+            }
83
+            if ((pix_fmt = av_get_pix_fmt(s1->pixel_format)) == PIX_FMT_NONE) {
84
+                av_log(s, AV_LOG_ERROR, "No such pixel format: %s.\n", s1->pixel_format);
85
+                ret = AVERROR(EINVAL);
86
+                goto fail;
84 87
             }
85 88
 #if FF_API_FORMAT_PARAMETERS
86 89
             if (ap->width > 0)
87 90
                 width = ap->width;
88 91
             if (ap->height > 0)
89 92
                 height = ap->height;
93
+            if (ap->pix_fmt)
94
+                pix_fmt = ap->pix_fmt;
90 95
 #endif
91 96
             st->codec->width  = width;
92 97
             st->codec->height = height;
93
-            st->codec->pix_fmt = ap->pix_fmt;
94
-            if(st->codec->pix_fmt == PIX_FMT_NONE)
95
-                st->codec->pix_fmt= PIX_FMT_YUV420P;
98
+            st->codec->pix_fmt = pix_fmt;
96 99
             break;
100
+fail:
101
+            av_freep(&s1->video_size);
102
+            av_freep(&s1->pixel_format);
103
+            return ret;
97 104
             }
98 105
         default:
99 106
             return -1;
... ...
@@ -187,6 +195,7 @@ const AVClass ff_rawaudio_demuxer_class = {
187 187
 #define DEC AV_OPT_FLAG_DECODING_PARAM
188 188
 static const AVOption video_options[] = {
189 189
     { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
190
+    { "pixel_format", "", OFFSET(pixel_format), FF_OPT_TYPE_STRING, {.str = "yuv420p"}, 0, 0, DEC },
190 191
     { NULL },
191 192
 };
192 193
 #undef OFFSET
... ...
@@ -34,6 +34,7 @@ typedef struct RawAudioDemuxerContext {
34 34
 typedef struct FFRawVideoDemuxerContext {
35 35
     const AVClass *class;     /**< Class for private options. */
36 36
     char *video_size;         /**< String describing video size, set by a private option. */
37
+    char *pixel_format;       /**< Set by a private option. */
37 38
 } FFRawVideoDemuxerContext;
38 39
 
39 40
 extern const AVClass ff_rawaudio_demuxer_class;