[libav-devel] libav avformat_open_input fails with signal 11 (Segmentation fault) when opening headerless raw mulaw file

Hans Wright wright.hans at gmail.com
Thu Dec 26 18:56:43 CET 2019


I posted question for help in stackoverflow with NO response for weeks
any example that I found enters into the process by using
avformat_open_input
I tried everything possible .. with info and codec .. just plain passing in
the file like in example0.c
Nothing helped.  Do you see anything ?
https://stackoverflow.com/questions/59365351/libav-avformat-open-input-fails-with-signal-11-segmentation-fault-when-opening

I tried converting a raw headerless mulaw file with libav. The goal is to
create a mp3 file. The ffmpeg command line works fine .. *ffmpeg -f mulaw
-ar 8000 -ac 1 -i raw_ULaw_8000Hz_1CH.raw output.mp3* So I created a c file
and compiled with gcc

    printf("open_input_file-avformat_open_input\n");
    AVCodec* pCodec;
    AVCodecContext* pContext;

    avcodec_register_all();

    pCodec = avcodec_find_encoder(AV_CODEC_ID_PCM_MULAW);
    if (!pCodec)
    {
        av_log(NULL, AV_LOG_ERROR, "Cannot find encoder
AV_CODEC_ID_PCM_MULAW\n");
        abort();
    }

    pContext = avcodec_alloc_context3(pCodec);
    if(pContext == NULL)
    {
        av_log(NULL, AV_LOG_ERROR, "Cannot allocate context
avcodec_alloc_context3(..)\n");
        abort();
    }

    pContext->channels = 1;
    pContext->bit_rate = 64000;
    pContext->sample_fmt = AV_SAMPLE_FMT_S16;//AV_SAMPLE_FMT_U8;
    pContext->channel_layout = AV_CH_LAYOUT_MONO;
    pContext->sample_rate=8;

    if(avcodec_open2(&pContext, &pCodec, NULL) < 0)
    {
        av_log(NULL, AV_LOG_ERROR, "Cannot open context(..)\n");
        abort();
    }

    printf("context bitrate:%d\n",pContext->bit_rate);

   AVDictionary *options = NULL;
   av_dict_set(&options, "f", "mulaw", 0);// TODO: must find what the
mulaw options are

    if (avformat_open_input(&pContext, "raw_ULaw_8000Hz_1CH.raw",
"raw", &options) < 0){rmat_open_input(&pContext,
"raw_ULaw_8000Hz_1CH.raw", NULL, NULL) < 0){
         av_log(NULL, AV_LOG_ERROR, "Cannot open input file %s ,
return code: %s \n", filename, av_err2str(ret));
        abort();
    }

output after execution

./rawtomp3.libav raw_ULaw_8000Hz_1CH.raw  output.mp3
open_input_file-avformat_open_input
context bitrate:64000
signal 11 (Segmentation fault), address is 0x100000010 from
0x7f2f85f17a25[bt]: (1)
/usr/lib/x86_64-linux-gnu/libavformat.so.57(avformat_open_input+0x485)
[0x7f2f85f17a25][bt]: (2)
/usr/lib/x86_64-linux-gnu/libavformat.so.57(avformat_open_input+0x485)
[0x7f2f85f17a25][bt]: (3) ./rawtomp3.libav(+0x172a)
[0x5576ec8f272a][bt]: (4) ./rawtomp3.libav(main+0x104)
[0x5576ec8f294a][bt]: (5)
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)
[0x7f2f854e8b97][bt]: (6) ./rawtomp3.libav(_start+0x2a)
[0x5576ec8f20ea]

I tried with passing context prefilled and without .. what needs to change ?

-- 

Thank You

Hans Wright
ph:  (502) 233 1048


More information about the libav-devel mailing list