Opened 3 weeks ago

Last modified 3 weeks ago

#6629 new defect

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

Description

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];

    av_register_all();
    avcodec_register_all();
    avformat_network_init();
    avdevice_register_all();

    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);
        av_dict_free(&opts);
        return -1;
    }

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

    avformat_close_input(&format_context);

    return 0;
}

Output:

./sample
[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:

/home/dave/ffmpeg_33/bin/ffmpeg
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 (1)

comment:1 Changed 3 weeks ago by cehoyos

  • Keywords crash abort added; avdevice input_format removed
  • Priority changed from normal to important
Note: See TracTickets for help on using tickets.