FFmpeg build with V4L2

6,558

I had the configure option --disable-indevs and had missed the option --enable-indev=v4l2. Adding the latter allows my build to access my webcam.

Share:
6,558

Related videos on Youtube

Jon G
Author by

Jon G

Updated on September 18, 2022

Comments

  • Jon G
    Jon G over 1 year

    I want to use ffmpeg to access my webcam. I tried:

    ffmpeg -f v4l2 -i /dev/video0 output.mp4
    

    but I am getting an error:

    Unknown input format: 'v4l2'
    

    Similarly with video4linux2 instead of v4l2. I therefore assume my build of ffmpeg is missing v4l2. I see that there is a configure option --enable-libv4l2 (https://ffmpeg.org/ffmpeg-all.html#video4linux2_002c-v4l2). I added this to my configuration, but running configure I get:

    ERROR: "libv4l2 not found using pkg-config"
    

    How do I add this to my build? I am following the guide at https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu with some modifications to include specific decoders etc.

    I understand that libv4l2 may come with the Ubuntu package libv4l-dev. Installing it with:

    sudo apt-get install libv4l-dev
    

    doesn't seem to affect my issue though. I can see /usr/lib/x86_64-linux-gnu/pkgconfig/libv4l2.pc, which I guess is the file I need. Maybe I just need to point ffmpeg / pkg-config to it in the configure options? Something like:

    PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig" ./configure ...
    

    ? (Doesn't work). Modifying --extra-cflags or --extra-ldflags to point to include / libs? Couldn't get that to work either. The FFmpeg build guide linked keeps all packages in a ffmpeg_build directory in my home folder. Should I install libv4l-dev there somehow?

    Tail of config.log:

    END /tmp/ffconf.5wdQhyZ1.c
    gcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -I/home/jon/ffmpeg_build/include -std=c99 -fomit-frame-pointer -pthread -c -o /tmp/ffconf.LGU7tq3n.o /tmp/ffconf.5wdQhyZ1.c
    gcc -L/home/jon/ffmpeg_build/lib -Wl,--as-needed -Wl,-z,noexecstack -o /tmp/ffconf.Fhn6FivT /tmp/ffconf.LGU7tq3n.o -lv4l2 -lpthread -lv4lconvert -lrt -lm -ljpeg -lmp3lame -lfdk-aac -lm -lz -pthread
    /usr/bin/ld: cannot find -ljpeg
    collect2: error: ld returned 1 exit status
    ERROR: libv4l2 not found using pkg-config
    

    Seems like it is missing a jpeg library:

    sudo apt-get install libjpeg-dev
    

    and it compiles OK, but I am returned to the original error of:

    Unknown input format: 'v4l2'
    

    On running the first command.