---
 libavdevice/v4l2.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 4e0b499..f829e50 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -69,6 +69,7 @@ struct video_data {
     unsigned int *buf_len;
     char *standard;
     int channel;
+    char *pix_fmt;
 };
 
 struct buff_data {
@@ -542,12 +543,12 @@ static int v4l2_set_parameters(AVFormatContext *s1, 
AVFormatParameters *ap)
 }
 
 static uint32_t device_try_init(AVFormatContext *s1,
-                                const AVFormatParameters *ap,
+                                enum PixelFormat pix_fmt,
                                 int *width,
                                 int *height,
                                 enum CodecID *codec_id)
 {
-    uint32_t desired_format = fmt_ff2v4l(ap->pix_fmt, s1->video_codec_id);
+    uint32_t desired_format = fmt_ff2v4l(pix_fmt, s1->video_codec_id);
 
     if (desired_format == 0 ||
         device_init(s1, width, height, desired_format) < 0) {
@@ -580,6 +581,7 @@ static int v4l2_read_header(AVFormatContext *s1, 
AVFormatParameters *ap)
     int res;
     uint32_t desired_format, capabilities;
     enum CodecID codec_id;
+    enum PixelFormat pix_fmt = av_get_pix_fmt(s->pix_fmt);
 
     st = av_new_stream(s1, 0);
     if (!st) {
@@ -592,6 +594,8 @@ static int v4l2_read_header(AVFormatContext *s1, 
AVFormatParameters *ap)
         s->width  = ap->width;
     if (ap->height > 0)
         s->height = ap->height;
+    if (ap->pix_fmt)
+        pix_fmt = ap->pix_fmt;
 #endif
 
     capabilities = 0;
@@ -615,10 +619,10 @@ static int v4l2_read_header(AVFormatContext *s1, 
AVFormatParameters *ap)
         av_log(s1, AV_LOG_VERBOSE, "Setting frame size to %dx%d\n", s->width, 
s->height);
     }
 
-    desired_format = device_try_init(s1, ap, &s->width, &s->height, &codec_id);
+    desired_format = device_try_init(s1, pix_fmt, &s->width, &s->height, 
&codec_id);
     if (desired_format == 0) {
         av_log(s1, AV_LOG_ERROR, "Cannot find a proper format for "
-               "codec_id %d, pix_fmt %d.\n", s1->video_codec_id, ap->pix_fmt);
+               "codec_id %d, pix_fmt %d.\n", s1->video_codec_id, pix_fmt);
         close(s->fd);
 
         return AVERROR(EIO);
@@ -696,6 +700,8 @@ static int v4l2_read_close(AVFormatContext *s1)
         mmap_close(s);
     }
 
+    av_freep(&s->pix_fmt);
+
     close(s->fd);
     return 0;
 }
@@ -705,6 +711,7 @@ static const AVOption options[] = {
     { "channel",  "", offsetof(struct video_data, channel),  FF_OPT_TYPE_INT,  
  {.dbl = 0 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
     { "width",    "", offsetof(struct video_data, width),    FF_OPT_TYPE_INT, 
{.dbl = 640}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
     { "height",   "", offsetof(struct video_data, height),   FF_OPT_TYPE_INT, 
{.dbl = 480}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+    { "pixel_format", "", offsetof(struct video_data, pix_fmt),  
FF_OPT_TYPE_STRING, {.str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
     { NULL },
 };
 
-- 
1.7.5.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to