doc/examples/filtering_audio: switch to new decoding API
This commit is contained in:
parent
afd257b43f
commit
03372d0a90
@ -216,10 +216,9 @@ static void print_frame(const AVFrame *frame)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
AVPacket packet0, packet;
|
AVPacket packet;
|
||||||
AVFrame *frame = av_frame_alloc();
|
AVFrame *frame = av_frame_alloc();
|
||||||
AVFrame *filt_frame = av_frame_alloc();
|
AVFrame *filt_frame = av_frame_alloc();
|
||||||
int got_frame;
|
|
||||||
|
|
||||||
if (!frame || !filt_frame) {
|
if (!frame || !filt_frame) {
|
||||||
perror("Could not allocate frame");
|
perror("Could not allocate frame");
|
||||||
@ -239,50 +238,48 @@ int main(int argc, char **argv)
|
|||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
/* read all packets */
|
/* read all packets */
|
||||||
packet0.data = NULL;
|
|
||||||
packet.data = NULL;
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!packet0.data) {
|
if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
|
||||||
if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
|
break;
|
||||||
break;
|
|
||||||
packet0 = packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packet.stream_index == audio_stream_index) {
|
if (packet.stream_index == audio_stream_index) {
|
||||||
got_frame = 0;
|
ret = avcodec_send_packet(dec_ctx, &packet);
|
||||||
ret = avcodec_decode_audio4(dec_ctx, frame, &got_frame, &packet);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
av_log(NULL, AV_LOG_ERROR, "Error decoding audio\n");
|
av_log(NULL, AV_LOG_ERROR, "Error while sending a packet to the decoder\n");
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
packet.size -= ret;
|
|
||||||
packet.data += ret;
|
|
||||||
|
|
||||||
if (got_frame) {
|
while (ret >= 0) {
|
||||||
/* push the audio data from decoded frame into the filtergraph */
|
ret = avcodec_receive_frame(dec_ctx, frame);
|
||||||
if (av_buffersrc_add_frame_flags(buffersrc_ctx, frame, 0) < 0) {
|
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
|
||||||
av_log(NULL, AV_LOG_ERROR, "Error while feeding the audio filtergraph\n");
|
|
||||||
break;
|
break;
|
||||||
|
} else if (ret < 0) {
|
||||||
|
av_log(NULL, AV_LOG_ERROR, "Error while receiving a frame from the decoder\n");
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pull filtered audio from the filtergraph */
|
if (ret >= 0) {
|
||||||
while (1) {
|
/* push the audio data from decoded frame into the filtergraph */
|
||||||
ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
|
if (av_buffersrc_add_frame_flags(buffersrc_ctx, frame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0) {
|
||||||
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
|
av_log(NULL, AV_LOG_ERROR, "Error while feeding the audio filtergraph\n");
|
||||||
break;
|
break;
|
||||||
if (ret < 0)
|
}
|
||||||
goto end;
|
|
||||||
print_frame(filt_frame);
|
/* pull filtered audio from the filtergraph */
|
||||||
av_frame_unref(filt_frame);
|
while (1) {
|
||||||
|
ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
|
||||||
|
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
|
||||||
|
break;
|
||||||
|
if (ret < 0)
|
||||||
|
goto end;
|
||||||
|
print_frame(filt_frame);
|
||||||
|
av_frame_unref(filt_frame);
|
||||||
|
}
|
||||||
|
av_frame_unref(frame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet.size <= 0)
|
|
||||||
av_packet_unref(&packet0);
|
|
||||||
} else {
|
|
||||||
/* discard non-wanted packets */
|
|
||||||
av_packet_unref(&packet0);
|
|
||||||
}
|
}
|
||||||
|
av_packet_unref(&packet);
|
||||||
}
|
}
|
||||||
end:
|
end:
|
||||||
avfilter_graph_free(&filter_graph);
|
avfilter_graph_free(&filter_graph);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user