19,468
社区成员
发帖
与我相关
我的任务
分享
while (av_read_frame(ic, &packet) >= 0) {
if (packet.stream_index == videoindex + 111) {
} else if (packet.stream_index == audioindex) {
int ret = 0;
while (packet.size > 0) {
out_buf = NULL;
if (packet.size > 0)
samples = (short *) av_fast_realloc(samples, &samples_size,
FFMAX(packet.size*sizeof
(*samples),2000));
LOGI("LOGI----------------19 ");
ret = avcodec_decode_audio4(aCodecCtx, oAFrame, &frameFinished2,
&packet);
// ret = avcodec_decode_audio3(aCodecCtx,samples,&out_size,&packet);//若为音频包,解码该音频包
LOGI("retretret:%d", ret);
if (ret < 0) {
LOGI("while decode audio failure\n");
exit(0);
}
packet.data += ret;
packet.size -= ret;
av_fifo_generic_write(fifo,oAFrame->data[0],oAFrame->linesize[0],NULL);
if (frameFinished2) {
out_buf = (uint8_t *) samples;
AVPacket pkt;
av_init_packet(&pkt);
pkt.data = NULL;
pkt.size = 0;
ret1 = avcodec_encode_audio2(oAcc, &pkt, oAFrame,
&got_output);
if (ret1 < 0) {
fprintf(stderr, "Error encoding audio frame\n");
exit(1);
}
if (got_output) {
if (oAcc->coded_frame&& oAcc->coded_frame->pts != AV_NOPTS_VALUE) {
pkt.pts= av_rescale_q(oAcc->coded_frame->pts, oAcc->time_base, audio_st->time_base);
}
pkt.flags |= AV_PKT_FLAG_KEY;
pkt.stream_index = audioindex;
av_write_frame(oc, &pkt);
av_free_packet(&pkt);
m_nAudioTimeStamp++;
}
}
}
}
av_free_packet(&packet);
}