まず、入力内のストリームの数を確認します。あなたはストリームを注文するかわからないので入って来、あなたもあるでしょう
ptrFormatContext = avformat_alloc_context();
if(avformat_open_input(&ptrFormatContext, filename, NULL, NULL) != 0)
{
qDebug("Error opening the input");
exit(-1);
}
if(av_find_stream_info(ptrFormatContext) < 0)
{
qDebug("Could not find any stream info");
exit(-2);
}
dump_format(ptrFormatContext, 0, filename, (int) NULL);
for(i=0; i<ptrFormatContext->nb_streams; i++)
{
switch(ptrFormatContext->streams[i]->codec->codec_type)
{
case AVMEDIA_TYPE_VIDEO:
{
if(videoStream < 0) videoStream = i;
break;
}
case AVMEDIA_TYPE_AUDIO:
{
if(audioStream < 0) audioStream = i;
}
}
}
if(audioStream == -1)
{
qDebug("Could not find any audio stream");
exit(-3);
}
if(videoStream == -1)
{
qDebug("Could not find any video stream");
exit(-4);
}
次に、あなたは(私の場合、私は唯一の2つのストリームを持っているが、あなたは簡単にそれを拡張することができます)いくつかのバッファにそれらを書きますコーデックの名前を確認するにはptrFormatContext->streams[i]->codec->codec_name
を入力し、関連するtarget_formatのインデックスを保存します。 は、次に、あなただけの指定されたインデックスを通じてストリームにアクセスすることができます
while(av_read_frame(ptrFormatContext,&ptrPacket) >= 0)
{
if(ptrPacket.stream_index == videoStream)
{
//decode the video stream to raw format
if(avcodec_decode_video2(ptrCodecCtxt, ptrFrame, &frameFinished, &ptrPacket) < 0)
{
qDebug("Error decoding the Videostream");
exit(-13);
}
if(frameFinished)
{
printf("%s\n", (char*) ptrPacket.data);
//encode the video stream to target format
// av_free_packet(&ptrPacket);
}
}
else if (ptrPacket.stream_index == audioStream)
{
//decode the audio stream to raw format
// if(avcodec_decode_audio3(aCodecCtx, , ,&ptrPacket) < 0)
// {
// qDebug("Error decoding the Audiostream");
// exit(-14);
// }
//encode the audio stream to target format
}
}
は、私はちょうど私のプログラムからいくつかの抽出物をコピーしたが、これはうまくいけば、あなたが入力からのストリームを選択する方法を理解するのに役立ちます。 私は完全なコードを掲載していません。抜粋のみですので、いくつかの初期化などを自分で行う必要がありますが、ご質問がありましたら喜んでお手伝いします!