Re: [FFmpeg-devel] [PATCH 1/4] libavdevice/avfoundation: add framerate and video size options
Am 27.03.15 um 14:34 schrieb Matthieu Bouron: On Sat, Mar 21, 2015 at 4:51 PM, Thilo Borgmann thilo.borgm...@mail.de wrote: [...] +[video_device setValue:selected_format forKey:@activeFormat]; +[video_device setValue:min_frame_duration forKey:@activeVideoMinFrameDuration]; +[video_device setValue:min_frame_duration forKey:@activeVideoMaxFrameDuration]; ^^^ Should be max_frame_duration in the third line. IIRC there is functionality in the API to check if setting min/max_frame_duration is available for the device, isn't it? Please check, in case there it is not, there is an alternative way to set the framerate (IIRC). It is purely intentionnal to use the min_frame_duration for the activeVideoMaxFrameDuration to acheive a better consistant framerate. There is no way to check if the range is accepted by the device but as stated by the documentation, applied range values that does not come from ranges returned by the API will throw an exception. There is an alternative way to set the framerate using AVCaptureConnection.setVideo(Min|Max)FrameDuration but it has been deprecated in iOS 7 and I do not intend to support it. I misunderstood your these lines. Patch ok, please apply. Thanks, Thilo ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/4] libavdevice/avfoundation: add framerate and video size options
On Sun, Mar 29, 2015 at 12:27:54AM +0100, Thilo Borgmann wrote: Am 27.03.15 um 14:34 schrieb Matthieu Bouron: On Sat, Mar 21, 2015 at 4:51 PM, Thilo Borgmann thilo.borgm...@mail.de wrote: [...] +[video_device setValue:selected_format forKey:@activeFormat]; +[video_device setValue:min_frame_duration forKey:@activeVideoMinFrameDuration]; +[video_device setValue:min_frame_duration forKey:@activeVideoMaxFrameDuration]; ^^^ Should be max_frame_duration in the third line. IIRC there is functionality in the API to check if setting min/max_frame_duration is available for the device, isn't it? Please check, in case there it is not, there is an alternative way to set the framerate (IIRC). It is purely intentionnal to use the min_frame_duration for the activeVideoMaxFrameDuration to acheive a better consistant framerate. There is no way to check if the range is accepted by the device but as stated by the documentation, applied range values that does not come from ranges returned by the API will throw an exception. There is an alternative way to set the framerate using AVCaptureConnection.setVideo(Min|Max)FrameDuration but it has been deprecated in iOS 7 and I do not intend to support it. I misunderstood your these lines. Patch ok, please apply. applied thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB He who knows, does not speak. He who speaks, does not know. -- Lao Tsu signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/4] libavdevice/avfoundation: add framerate and video size options
On Sat, Mar 21, 2015 at 4:51 PM, Thilo Borgmann thilo.borgm...@mail.de wrote: [...] +/* + * Configure the video device using a run-time approach to access properties + * since formats, activeFormat are available since iOS = 7.0 or OSX = 10.7 + * and activeVideoMaxFrameDuration is available since i0S = 7.0 and OSX = 10.9 + * + * The NSUndefinedKeyException must be handled by the caller of this function. + * + */ Please make it a short doxygen comment: /** Updated in attached patch. +static int configure_video_device(AVFormatContext *s, AVCaptureDevice *video_device) +{ +AVFContext *ctx = (AVFContext*)s-priv_data; + +double framerate = av_q2d(ctx-framerate); +NSObject *format = nil, *range = nil; +NSObject *selected_format = nil, *selected_range = nil; Nit: Please split these in 4 lines. Updated in attached patch. +for (format in [video_device valueForKey:@formats]) { +CMFormatDescriptionRef formatDescription; +CMVideoDimensions dimensions; + +formatDescription = (CMFormatDescriptionRef) [format performSelector:@selector(formatDescription)]; +dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription); + +if ((ctx-width == 0 ctx-height == 0) || +(dimensions.width == ctx-width dimensions.height == ctx-height)) { + +selected_format = format; + +for (range in [format valueForKey:@videoSupportedFrameRateRanges]) { +double max_framerate; + +[[range valueForKey:@maxFrameRate] getValue:max_framerate]; +if (abs (framerate - max_framerate) 0.1) { + Unneeded blank line. Updated in attached patch. +selected_range = range; +break; +} +} +} +} + +if (!selected_format) { +av_log(s, AV_LOG_ERROR, Selected video size (%dx%d) is not supported by the device\n, +ctx-width, ctx-height); +return AVERROR(EINVAL); +} + +if (!selected_range) { +av_log(s, AV_LOG_ERROR, Selected framerate (%f) is not supported by the device\n, +framerate); +return AVERROR(EINVAL); +} In case of an unsupported format/rate, please print a list of supported formats, like the pixel format test does. Updated in attached patch. I've also replaced the wrong usage of abs with fabs. + +if ([video_device lockForConfiguration:NULL] == YES) { +NSValue *min_frame_duration = [selected_range valueForKey:@minFrameDuration]; + +[video_device setValue:selected_format forKey:@activeFormat]; +[video_device setValue:min_frame_duration forKey:@activeVideoMinFrameDuration]; +[video_device setValue:min_frame_duration forKey:@activeVideoMaxFrameDuration]; ^^^ Should be max_frame_duration in the third line. IIRC there is functionality in the API to check if setting min/max_frame_duration is available for the device, isn't it? Please check, in case there it is not, there is an alternative way to set the framerate (IIRC). It is purely intentionnal to use the min_frame_duration for the activeVideoMaxFrameDuration to acheive a better consistant framerate. There is no way to check if the range is accepted by the device but as stated by the documentation, applied range values that does not come from ranges returned by the API will throw an exception. There is an alternative way to set the framerate using AVCaptureConnection.setVideo(Min|Max)FrameDuration but it has been deprecated in iOS 7 and I do not intend to support it. +} else { +av_log(s, AV_LOG_ERROR, Could not lock device for configuration); +return AVERROR(EINVAL); +} + +return 0; +} + static int add_video_device(AVFormatContext *s, AVCaptureDevice *video_device) { AVFContext *ctx = (AVFContext*)s-priv_data; +int ret; NSError *error = nil; AVCaptureInput* capture_input = nil; struct AVFPixelFormatSpec pxl_fmt_spec; @@ -300,6 +372,18 @@ static int add_video_device(AVFormatContext *s, AVCaptureDevice *video_device) return 1; } +// Configure device framerate and video size +@try { +if ((ret = configure_video_device(s, video_device)) 0) { +return ret; +} +} @catch (NSException *exception) { +if (![[exception name] isEqualToString:NSUndefinedKeyException]) { + av_log (s, AV_LOG_ERROR, An error occured: %s, [exception.reason UTF8String]); + return AVERROR_EXTERNAL; +} +} + // select pixel format pxl_fmt_spec.ff_id = AV_PIX_FMT_NONE; @@ -549,6 +633,7 @@ static int get_audio_config(AVFormatContext *s) static int avf_read_header(AVFormatContext *s) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +int
Re: [FFmpeg-devel] [PATCH 1/4] libavdevice/avfoundation: add framerate and video size options
Am 18.03.15 um 09:36 schrieb Matthieu Bouron: On Sat, Mar 14, 2015 at 11:09 AM, Matthieu Bouron matthieu.bou...@gmail.com wrote: On Sat, Mar 14, 2015 at 11:01 AM, Matthieu Bouron matthieu.bou...@gmail.com wrote: On Sat, Mar 14, 2015 at 8:31 AM, Carl Eugen Hoyos ceho...@ag.or.at wrote: matthieu.bouron at gmail.com writes: +for (NSObject *format in You may ignore this but I just changed the code to not mix declarations and statements to silence warnings when compiling with old gcc compilers... I don't have access to an older version of OSX which uses gcc. I've updated the patch locally to separate declarations and statements. +if (framerate == 0.0 Just asking: Does this really work? Nope it doesn't, it's just a glitch i forget to remove when i was not using the AV_OPT_TYPE_IMAGE_SIZE for the framerate option (and the value was defaulting to 0). I've removed it locally. New patch attached. ping Am 18.03.15 um 09:36 schrieb Matthieu Bouron: On Sat, Mar 14, 2015 at 11:11 AM, Matthieu Bouron matthieu.bou...@gmail.com wrote: On Sat, Mar 14, 2015 at 10:50 AM, Matthieu Bouron matthieu.bou...@gmail.com wrote: On Sat, Mar 14, 2015 at 8:29 AM, Carl Eugen Hoyos ceho...@ag.or.at wrote: matthieu.bouron at gmail.com writes: +#if __MAC_OS_X_VERSION_MIN_REQUIRED = 1080 Please make this #if !TARGET_OS_IPHONE ... to avoid warnings when compiling for iOS. Carl Eugen ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel Hello Carl, Both code blocks are already contained in the following blocks: #if !TARGET_OS_IPHONE __MAC_OS_X_VERSION_MIN_REQUIRED = 1070 [...] #endif Do you still want the #if !TARGET_OS_IPHONE for consistency ? New patch attached with the #if !TARGET_OS_IPHONE condition. ping From d581aaea69145a0fdd2ebc14dc11e0929e7f5252 Mon Sep 17 00:00:00 2001 From: Matthieu Bouron matthieu.bou...@gmail.com Date: Sat, 7 Mar 2015 21:26:52 +0100 Subject: [PATCH 1/4] libavdevice/avfoundation: add framerate and video size options Support framerate ands video size options on AVCaptureDevices for OSX = 10.7 and iOS = 7.0. For screen captures, only the framerate option is taken into account. --- libavdevice/avfoundation.m | 104 + 1 file changed, 104 insertions(+) diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m index e00cc3b..86e6578 100644 --- a/libavdevice/avfoundation.m +++ b/libavdevice/avfoundation.m @@ -33,6 +33,7 @@ #include libavutil/avstring.h #include libavformat/internal.h #include libavutil/internal.h +#include libavutil/parseutils.h #include libavutil/time.h #include avdevice.h @@ -90,6 +91,9 @@ typedef struct id avf_delegate; id avf_audio_delegate; +AVRational framerate; +int width, height; + int list_devices; int video_device_index; int video_stream_index; @@ -263,9 +267,77 @@ static void parse_device_name(AVFormatContext *s) } } +/* + * Configure the video device using a run-time approach to access properties + * since formats, activeFormat are available since iOS = 7.0 or OSX = 10.7 + * and activeVideoMaxFrameDuration is available since i0S = 7.0 and OSX = 10.9 + * + * The NSUndefinedKeyException must be handled by the caller of this function. + * + */ Please make it a short doxygen comment: /** +static int configure_video_device(AVFormatContext *s, AVCaptureDevice *video_device) +{ +AVFContext *ctx = (AVFContext*)s-priv_data; + +double framerate = av_q2d(ctx-framerate); +NSObject *format = nil, *range = nil; +NSObject *selected_format = nil, *selected_range = nil; Nit: Please split these in 4 lines. +for (format in [video_device valueForKey:@formats]) { +CMFormatDescriptionRef formatDescription; +CMVideoDimensions dimensions; + +formatDescription = (CMFormatDescriptionRef) [format performSelector:@selector(formatDescription)]; +dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription); + +if ((ctx-width == 0 ctx-height == 0) || +(dimensions.width == ctx-width dimensions.height == ctx-height)) { + +selected_format = format; + +for (range in [format valueForKey:@videoSupportedFrameRateRanges]) { +double max_framerate; + +[[range valueForKey:@maxFrameRate] getValue:max_framerate]; +if (abs (framerate - max_framerate) 0.1) { + Unneeded blank line. +selected_range = range; +break; +} +} +} +} + +if (!selected_format) { +av_log(s, AV_LOG_ERROR, Selected video size (%dx%d) is not supported by the device\n, +ctx-width, ctx-height); +return
Re: [FFmpeg-devel] [PATCH 1/4] libavdevice/avfoundation: add framerate and video size options
On Sat, Mar 14, 2015 at 11:09 AM, Matthieu Bouron matthieu.bou...@gmail.com wrote: On Sat, Mar 14, 2015 at 11:01 AM, Matthieu Bouron matthieu.bou...@gmail.com wrote: On Sat, Mar 14, 2015 at 8:31 AM, Carl Eugen Hoyos ceho...@ag.or.at wrote: matthieu.bouron at gmail.com writes: +for (NSObject *format in You may ignore this but I just changed the code to not mix declarations and statements to silence warnings when compiling with old gcc compilers... I don't have access to an older version of OSX which uses gcc. I've updated the patch locally to separate declarations and statements. +if (framerate == 0.0 Just asking: Does this really work? Nope it doesn't, it's just a glitch i forget to remove when i was not using the AV_OPT_TYPE_IMAGE_SIZE for the framerate option (and the value was defaulting to 0). I've removed it locally. New patch attached. ping ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/4] libavdevice/avfoundation: add framerate and video size options
Matthieu Bouron matthieu.bouron at gmail.com writes: +for (NSObject *format in You may ignore this but I just changed the code to not mix declarations and statements to silence warnings when compiling with old gcc compilers... I don't have access to an older version of OSX which uses gcc. As said, this isn't so important but you can install old XCode on current OSX. I've updated the patch locally to separate declarations and statements. Thank you, Carl Eugen ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/4] libavdevice/avfoundation: add framerate and video size options
On Sat, Mar 14, 2015 at 8:31 AM, Carl Eugen Hoyos ceho...@ag.or.at wrote: matthieu.bouron at gmail.com writes: +for (NSObject *format in You may ignore this but I just changed the code to not mix declarations and statements to silence warnings when compiling with old gcc compilers... I don't have access to an older version of OSX which uses gcc. I've updated the patch locally to separate declarations and statements. +if (framerate == 0.0 Just asking: Does this really work? Nope it doesn't, it's just a glitch i forget to remove when i was not using the AV_OPT_TYPE_IMAGE_SIZE for the framerate option (and the value was defaulting to 0). I've removed it locally. Matthieu ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/4] libavdevice/avfoundation: add framerate and video size options
On Sat, Mar 14, 2015 at 11:01 AM, Matthieu Bouron matthieu.bou...@gmail.com wrote: On Sat, Mar 14, 2015 at 8:31 AM, Carl Eugen Hoyos ceho...@ag.or.at wrote: matthieu.bouron at gmail.com writes: +for (NSObject *format in You may ignore this but I just changed the code to not mix declarations and statements to silence warnings when compiling with old gcc compilers... I don't have access to an older version of OSX which uses gcc. I've updated the patch locally to separate declarations and statements. +if (framerate == 0.0 Just asking: Does this really work? Nope it doesn't, it's just a glitch i forget to remove when i was not using the AV_OPT_TYPE_IMAGE_SIZE for the framerate option (and the value was defaulting to 0). I've removed it locally. New patch attached. 0001-libavdevice-avfoundation-add-framerate-and-video-siz.patch Description: Binary data ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/4] libavdevice/avfoundation: add framerate and video size options
matthieu.bouron at gmail.com writes: +for (NSObject *format in You may ignore this but I just changed the code to not mix declarations and statements to silence warnings when compiling with old gcc compilers... +if (framerate == 0.0 Just asking: Does this really work? Carl Eugen ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/4] libavdevice/avfoundation: add framerate and video size options
From: Matthieu Bouron matthieu.bou...@gmail.com Support framerate ands video size options on AVCaptureDevices for OSX = 10.7 and iOS = 7.0. For screen captures, only the framerate option is taken into account. --- libavdevice/avfoundation.m | 103 + 1 file changed, 103 insertions(+) diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m index e00cc3b..41fe9c3 100644 --- a/libavdevice/avfoundation.m +++ b/libavdevice/avfoundation.m @@ -33,6 +33,7 @@ #include libavutil/avstring.h #include libavformat/internal.h #include libavutil/internal.h +#include libavutil/parseutils.h #include libavutil/time.h #include avdevice.h @@ -90,6 +91,9 @@ typedef struct id avf_delegate; id avf_audio_delegate; +AVRational framerate; +int width, height; + int list_devices; int video_device_index; int video_stream_index; @@ -263,9 +267,76 @@ static void parse_device_name(AVFormatContext *s) } } +/* + * Configure the video device using a run-time approach to access properties + * since formats, activeFormat are available since iOS = 7.0 or OSX = 10.7 + * and activeVideoMaxFrameDuration is available since i0S = 7.0 and OSX = 10.9 + * + * The NSUndefinedKeyException must be handled by the caller of this function. + * + */ +static int configure_video_device(AVFormatContext *s, AVCaptureDevice *video_device) +{ +AVFContext *ctx = (AVFContext*)s-priv_data; + +double framerate = av_q2d(ctx-framerate); +NSObject *selected_format = nil, *selected_range = nil; + +for (NSObject *format in [video_device valueForKey:@formats]) { +CMFormatDescriptionRef formatDescription; +CMVideoDimensions dimensions; + +formatDescription = (CMFormatDescriptionRef) [format performSelector:@selector(formatDescription)]; +dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription); + +if ((ctx-width == 0 ctx-height == 0) || +(dimensions.width == ctx-width dimensions.height == ctx-height)) { + +selected_format = format; + +for (NSObject *range in [format valueForKey:@videoSupportedFrameRateRanges]) { +double max_framerate; + +[[range valueForKey:@maxFrameRate] getValue:max_framerate]; +if (framerate == 0.0 || abs (framerate - max_framerate) 0.1) { + +selected_range = range; +break; +} +} +} +} + +if (!selected_format) { +av_log(s, AV_LOG_ERROR, Selected video size (%dx%d) is not supported by the device\n, +ctx-width, ctx-height); +return AVERROR(EINVAL); +} + +if (!selected_range) { +av_log(s, AV_LOG_ERROR, Selected framerate (%f) is not supported by the device\n, +framerate); +return AVERROR(EINVAL); +} + +if ([video_device lockForConfiguration:NULL] == YES) { +NSValue *min_frame_duration = [selected_range valueForKey:@minFrameDuration]; + +[video_device setValue:selected_format forKey:@activeFormat]; +[video_device setValue:min_frame_duration forKey:@activeVideoMinFrameDuration]; +[video_device setValue:min_frame_duration forKey:@activeVideoMaxFrameDuration]; +} else { +av_log(s, AV_LOG_ERROR, Could not lock device for configuration); +return AVERROR(EINVAL); +} + +return 0; +} + static int add_video_device(AVFormatContext *s, AVCaptureDevice *video_device) { AVFContext *ctx = (AVFContext*)s-priv_data; +int ret; NSError *error = nil; AVCaptureInput* capture_input = nil; struct AVFPixelFormatSpec pxl_fmt_spec; @@ -300,6 +371,18 @@ static int add_video_device(AVFormatContext *s, AVCaptureDevice *video_device) return 1; } +// Configure device framerate and video size +@try { +if ((ret = configure_video_device(s, video_device)) 0) { +return ret; +} +} @catch (NSException *exception) { +if (![[exception name] isEqualToString:NSUndefinedKeyException]) { + av_log (s, AV_LOG_ERROR, An error occured: %s, [exception.reason UTF8String]); + return AVERROR_EXTERNAL; +} +} + // select pixel format pxl_fmt_spec.ff_id = AV_PIX_FMT_NONE; @@ -549,6 +632,7 @@ static int get_audio_config(AVFormatContext *s) static int avf_read_header(AVFormatContext *s) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +int capture_screen = 0; uint32_t num_screens= 0; AVFContext *ctx = (AVFContext*)s-priv_data; AVCaptureDevice *video_device = nil; @@ -616,7 +700,13 @@ static int avf_read_header(AVFormatContext *s) CGDirectDisplayID screens[num_screens]; CGGetActiveDisplayList(num_screens, screens, num_screens);