How to open avfoundation via C

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to open avfoundation via C

Jeroen Ooms
I would like to capture the screen in MacOS. This works via the command line:

  Command line: ffmpeg -f avfoundation -i "1" -pix_fmt yuv420p -r 25
-t 5 out.mov

However I can't figure out how to do this in C. I tried the following,
but it gives an error "Device selection unsupported.".

  AVBufferRef *capture;
  AVDictionary *opts = NULL;
  av_dict_set(&opts, "video_device_index", "1", 0);
  av_dict_set(&opts, "audio_device_index", "none", 0);
  av_hwdevice_ctx_create(&capture, AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
                                 "avfoundation", opts, 0);
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to open avfoundation via C

Carl Eugen Hoyos-2
2018-10-09 1:03 GMT+02:00, Jeroen Ooms <[hidden email]>:

> I would like to capture the screen in MacOS. This works via the command
> line:
>
>   Command line: ffmpeg -f avfoundation -i "1" -pix_fmt yuv420p -r 25
> -t 5 out.mov
>
> However I can't figure out how to do this in C. I tried the following,
> but it gives an error "Device selection unsupported.".
>
>   AVBufferRef *capture;
>   AVDictionary *opts = NULL;
>   av_dict_set(&opts, "video_device_index", "1", 0);
>   av_dict_set(&opts, "audio_device_index", "none", 0);
>   av_hwdevice_ctx_create(&capture, AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
>                                  "avfoundation", opts, 0);

From the command line above, avfoundation
is a device / format, not a hwdevice.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to open avfoundation via C

Jeroen Ooms
On Tue, Oct 9, 2018 at 2:36 AM Carl Eugen Hoyos <[hidden email]> wrote:

>
> 2018-10-09 1:03 GMT+02:00, Jeroen Ooms <[hidden email]>:
> > I would like to capture the screen in MacOS. This works via the command
> > line:
> >
> >   Command line: ffmpeg -f avfoundation -i "1" -pix_fmt yuv420p -r 25
> > -t 5 out.mov
> >
> > However I can't figure out how to do this in C. I tried the following,
> > but it gives an error "Device selection unsupported.".
> >
> >   AVBufferRef *capture;
> >   AVDictionary *opts = NULL;
> >   av_dict_set(&opts, "video_device_index", "1", 0);
> >   av_dict_set(&opts, "audio_device_index", "none", 0);
> >   av_hwdevice_ctx_create(&capture, AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
> >                                  "avfoundation", opts, 0);
>
> From the command line above, avfoundation
> is a device / format, not a hwdevice.

I don't understand, it is listed as a video device in
av_input_video_device_next(). Which API is used to read from such an
input then? I can only find command line examples for avfoundation, it
is unclear to me how to capture the camera/screen in C.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to open avfoundation via C

Jeroen Ooms
On Tue, Oct 9, 2018 at 11:55 AM Jeroen Ooms <[hidden email]> wrote:

>
> On Tue, Oct 9, 2018 at 2:36 AM Carl Eugen Hoyos <[hidden email]> wrote:
> >
> > 2018-10-09 1:03 GMT+02:00, Jeroen Ooms <[hidden email]>:
> > > I would like to capture the screen in MacOS. This works via the command
> > > line:
> > >
> > >   Command line: ffmpeg -f avfoundation -i "1" -pix_fmt yuv420p -r 25
> > > -t 5 out.mov
> > >
> > > However I can't figure out how to do this in C. I tried the following,
> > > but it gives an error "Device selection unsupported.".
> > >
> > >   AVBufferRef *capture;
> > >   AVDictionary *opts = NULL;
> > >   av_dict_set(&opts, "video_device_index", "1", 0);
> > >   av_dict_set(&opts, "audio_device_index", "none", 0);
> > >   av_hwdevice_ctx_create(&capture, AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
> > >                                  "avfoundation", opts, 0);
> >
> > From the command line above, avfoundation
> > is a device / format, not a hwdevice.
>
> I don't understand, it is listed as a video device in
> av_input_video_device_next(). Which API is used to read from such an
> input then? I can only find command line examples for avfoundation, it
> is unclear to me how to capture the camera/screen in C.

Talking to myself here, but I figured it out sort of. After calling
avdevice_register_all() the "avfoundation" device will magically
appear as a regular demuxer format:

  avdevice_register_all();
  AVInputFormat *input = av_find_input_format("avfoundation");
  AVFormatContext *demuxer = NULL;
  avformat_open_input(&demuxer, "1", input, NULL)
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".