I already copied your solution :)
Still need the check for type unknown. This ok?

  if(m_pFormatContext->streams[idx]->codec->codec_type == AVMEDIA_TYPE_UNKNOWN)
     continue;