user3177342
user3177342

Reputation: 55

Libav and web cam capturing

Trying to open web cam using ffmpeg (ffplay -f video4linux2 /dev/video0 works

    pFormatCtx = NULL;
    av_register_all();
    avcodec_register_all();
    avformat_network_init();


    const char      device[]     = "/dev/video0";
    const char      formatName[] = "video4linux";

if (!(pFormat = av_find_input_format(formatName))) {
     printf("can't find input format %s\n", formatName);
     return ;
}

if (avformat_open_input(&pFormatCtx, device, pFormat,  NULL)!=0) {
     printf("can't find open input file %s\n", device);
     return ;
}

but pFormat is always 0;

Update: And how to get mjpeg from web cam?

Upvotes: 1

Views: 1034

Answers (1)

user2219675
user2219675

Reputation: 11

You should call avdevice_register_all() at the beginning.

pFormatCtx = NULL;
av_register_all();
avdevice_register_all();
avcodec_register_all();
avformat_network_init();

const char      device[]     = "/dev/video0";
const char      formatName[] = "video4linux";

if (!(pFormat = av_find_input_format(formatName))) {
  printf("can't find input format %s\n", formatName);
  return ;
}

if (avformat_open_input(&pFormatCtx, device, pFormat,  NULL)!=0) {
  printf("can't find open input file %s\n", device);
  return ;
}

Upvotes: 1

Related Questions