You didn't show how do you initialize contexts. You probably miss avformat_find_stream_info() call, or/and somewhat wrongly or incompletely copy file and codecs contexts settings (look at avcodec_copy_context()) -- Andrey Utkin