add AVOption list_formats to print available pixel formats
---
 libavdevice/avfoundation_dec.m | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/libavdevice/avfoundation_dec.m b/libavdevice/avfoundation_dec.m
index c5ec320..0a3f535 100644
--- a/libavdevice/avfoundation_dec.m
+++ b/libavdevice/avfoundation_dec.m
@@ -91,6 +91,7 @@ typedef struct AVFoundationCaptureContext {
     AVClass *class;
     /* AVOptions */
     int list_devices;
+    int list_formats;
     enum AVPixelFormat pixel_format;
 
     int video_stream_index;
@@ -114,10 +115,11 @@ typedef struct AVFoundationCaptureContext {
 #define OFFSET(x) offsetof(AVFoundationCaptureContext, x)
 #define DEC AV_OPT_FLAG_DECODING_PARAM
 static const AVOption options[] = {
-    { "list_devices", "List available devices and exit", OFFSET(list_devices), 
 AV_OPT_TYPE_INT,    {.i64 = 0 },             0, INT_MAX, DEC, "list_devices" },
-    { "all",          "Show all the supported devices",  OFFSET(list_devices), 
 AV_OPT_TYPE_CONST,  {.i64 = ALL_DEVICES },   0, INT_MAX, DEC, "list_devices" },
-    { "audio",        "Show only the audio devices",     OFFSET(list_devices), 
 AV_OPT_TYPE_CONST,  {.i64 = AUDIO_DEVICES }, 0, INT_MAX, DEC, "list_devices" },
-    { "video",        "Show only the video devices",     OFFSET(list_devices), 
 AV_OPT_TYPE_CONST,  {.i64 = VIDEO_DEVICES }, 0, INT_MAX, DEC, "list_devices" },
+    { "list_devices", "List available devices and exit", OFFSET(list_devices), 
AV_OPT_TYPE_INT,    {.i64 = 0 },             0, INT_MAX, DEC, "list_devices" },
+    { "all",          "Show all the supported devices",  OFFSET(list_devices), 
AV_OPT_TYPE_CONST,  {.i64 = ALL_DEVICES },   0, INT_MAX, DEC, "list_devices" },
+    { "audio",        "Show only the audio devices",     OFFSET(list_devices), 
AV_OPT_TYPE_CONST,  {.i64 = AUDIO_DEVICES }, 0, INT_MAX, DEC, "list_devices" },
+    { "video",        "Show only the video devices",     OFFSET(list_devices), 
AV_OPT_TYPE_CONST,  {.i64 = VIDEO_DEVICES }, 0, INT_MAX, DEC, "list_devices" },
+    { "list_formats", "List available formats and exit", OFFSET(list_formats), 
AV_OPT_TYPE_INT,    {.i64 = 0 },  0, INT_MAX, DEC, "list_formats" },
     { NULL },
 };
 
@@ -152,6 +154,23 @@ static int 
avfoundation_list_capture_devices(AVFormatContext *s)
     return AVERROR_EXIT;
 }
 
+static int list_formats(AVFormatContext *s)
+{
+    av_log(s, AV_LOG_VERBOSE, "Supported pixel formats (first is more 
efficient):\n");
+    AVCaptureVideoDataOutput* out = [[AVCaptureVideoDataOutput alloc] init];
+
+    for (NSNumber *cv_pixel_format in [out availableVideoCVPixelFormatTypes]) {
+        OSType cv_fmt = [cv_pixel_format intValue];
+        enum AVPixelFormat pix_fmt = core_video_to_pix_fmt(cv_fmt);
+        if (pix_fmt != AV_PIX_FMT_NONE) {
+            av_log(s, AV_LOG_VERBOSE, "  %s: %d\n",
+                   av_get_pix_fmt_name(pix_fmt),
+                   cv_fmt);
+        }
+    }
+    return AVERROR_EXIT;
+}
+
 static void lock_frames(AVFoundationCaptureContext* ctx)
 {
     pthread_mutex_lock(&ctx->frame_lock);
@@ -451,6 +470,9 @@ static int avfoundation_read_header(AVFormatContext *s)
     ctx->first_pts = av_gettime();
     if (ctx->list_devices)
         return avfoundation_list_capture_devices(s);
+    if (ctx->list_formats) {
+        return list_formats(s);
+    }
 
     return setup_streams(s);
 }
-- 
2.6.2

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

Reply via email to