Opened 5 years ago

Closed 3 years ago

#6629 closed defect (fixed)

Assertion failed when specifying h264 format on v4l2 device that does NOT support h264

Reported by: Mr-Dave Owned by:
Priority: important Component: avdevice
Version: git-master Keywords: v4l2 crash abort
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


Summary of the bug:
When opening the format context to a v4l2 device and have specified a format which the device does NOT support, the avformat_open_input assertion fails.

How to reproduce:
Sample code using a device that does NOT support h264

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <libavformat/avformat.h>
#include <libavdevice/avdevice.h>
#include <libavutil/avutil.h>

int main (int argc, const char **argv) {

    AVFormatContext *format_context;
    AVDictionary *opts = 0;

    int  retcd;
    char errstr[128];
    char optfmt[8];


    format_context = avformat_alloc_context();
    format_context->iformat = av_find_input_format("video4linux2");

    sprintf(optfmt, "%s","h264");
    av_dict_set(&opts, "input_format", optfmt, 0);

    retcd = avformat_open_input(&format_context, "/dev/video0", NULL, &opts);
    fprintf(stderr,"Format context is open: \n");
    if (retcd < 0){
        av_strerror(retcd, errstr, sizeof(errstr));
        fprintf(stderr,"error opening file: %s \n",errstr);
        return -1;

    fprintf(stderr,"Device is open: \n");


    return 0;


[video4linux2,v4l2 @ 0x3d4a420] Cannot find a proper format for codec 'h264' (id 28), pixel format 'none' (id -1)
Assertion *codec_id != AV_CODEC_ID_NONE failed at libavdevice/v4l2.c:808
Aborted (core dumped)

Expected result:

avformat_open_input would return a error code.

ffmpeg version:

ffmpeg version 3.3 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: --prefix=/home/dave/ffmpeg_33 --pkg-config-flags=--static --extra-cflags=-I/home/dave/ffmpeg_33/include --extra-ldflags=-L/home/dave/ffmpeg_33/lib --bindir=/home/dave/ffmpeg_33/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Change History (2)

comment:1 by Carl Eugen Hoyos, 5 years ago

Keywords: crash abort added; avdevice input_format removed
Priority: normalimportant

comment:2 by Carl Eugen Hoyos, 3 years ago

Resolution: fixed
Status: newclosed

Should be fixed by Andriy Gelman in 7b2ce27e56cfb4c55490035283a687251061bb50, thank you for the report!

Note: See TracTickets for help on using tickets.