summaryrefslogtreecommitdiff
path: root/doc/examples/filtering_video.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-09-03 23:18:14 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-10-03 20:50:49 +0200
commit86ec1093ebb488b3c07b0ba5a2e5962f4612477e (patch)
treea5898d619256d41a67c97fcc0758122e107e8c76 /doc/examples/filtering_video.c
parenta75f518b657be15c0ed74b24e1353d117210ac53 (diff)
examples/filtering_video: Don't use stack packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'doc/examples/filtering_video.c')
-rw-r--r--doc/examples/filtering_video.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/doc/examples/filtering_video.c b/doc/examples/filtering_video.c
index 88394530ab..7b3e16c40c 100644
--- a/doc/examples/filtering_video.c
+++ b/doc/examples/filtering_video.c
@@ -210,7 +210,7 @@ static void display_frame(const AVFrame *frame, AVRational time_base)
int main(int argc, char **argv)
{
int ret;
- AVPacket packet;
+ AVPacket *packet;
AVFrame *frame;
AVFrame *filt_frame;
@@ -221,8 +221,9 @@ int main(int argc, char **argv)
frame = av_frame_alloc();
filt_frame = av_frame_alloc();
- if (!frame || !filt_frame) {
- perror("Could not allocate frame");
+ packet = av_packet_alloc();
+ if (!frame || !filt_frame || !packet) {
+ fprintf(stderr, "Could not allocate frame or packet\n");
exit(1);
}
@@ -233,11 +234,11 @@ int main(int argc, char **argv)
/* read all packets */
while (1) {
- if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
+ if ((ret = av_read_frame(fmt_ctx, packet)) < 0)
break;
- if (packet.stream_index == video_stream_index) {
- ret = avcodec_send_packet(dec_ctx, &packet);
+ if (packet->stream_index == video_stream_index) {
+ ret = avcodec_send_packet(dec_ctx, packet);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Error while sending a packet to the decoder\n");
break;
@@ -273,7 +274,7 @@ int main(int argc, char **argv)
av_frame_unref(frame);
}
}
- av_packet_unref(&packet);
+ av_packet_unref(packet);
}
end:
avfilter_graph_free(&filter_graph);
@@ -281,6 +282,7 @@ end:
avformat_close_input(&fmt_ctx);
av_frame_free(&frame);
av_frame_free(&filt_frame);
+ av_packet_free(&packet);
if (ret < 0 && ret != AVERROR_EOF) {
fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));