Between calls to avformat_alloc_output_context2() and avcodec_find_encoder() I think you need to call: avio_open2(&formatContext->pb, url, AVIO_FLAG_WRITE, NULL, NULL); Otherwise pb is NULL when the AVFormatContext trys to write the data.