aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-09-03 22:48:45 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-10-03 20:50:49 +0200
commit53f374c08d5cc97158c17ea34b1c8ee0116c0578 (patch)
tree2af825fc3bdefee4c7f275958256c8e652e15dbb /doc
parent78426da3f41bd88cc8ba02971a3a5be389fbead7 (diff)
downloadffmpeg-53f374c08d5cc97158c17ea34b1c8ee0116c0578.tar.gz
examples/remuxing: Don't use stack packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/examples/remuxing.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/doc/examples/remuxing.c b/doc/examples/remuxing.c
index 3697e488a8..9ffffded91 100644
--- a/doc/examples/remuxing.c
+++ b/doc/examples/remuxing.c
@@ -47,7 +47,7 @@ int main(int argc, char **argv)
{
const AVOutputFormat *ofmt = NULL;
AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
- AVPacket pkt;
+ AVPacket *pkt = NULL;
const char *in_filename, *out_filename;
int ret, i;
int stream_index = 0;
@@ -65,6 +65,12 @@ int main(int argc, char **argv)
in_filename = argv[1];
out_filename = argv[2];
+ pkt = av_packet_alloc();
+ if (!pkt) {
+ fprintf(stderr, "Could not allocate AVPacket\n");
+ goto end;
+ }
+
if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) {
fprintf(stderr, "Could not open input file '%s'", in_filename);
goto end;
@@ -140,27 +146,27 @@ int main(int argc, char **argv)
while (1) {
AVStream *in_stream, *out_stream;
- ret = av_read_frame(ifmt_ctx, &pkt);
+ ret = av_read_frame(ifmt_ctx, pkt);
if (ret < 0)
break;
- in_stream = ifmt_ctx->streams[pkt.stream_index];
- if (pkt.stream_index >= stream_mapping_size ||
- stream_mapping[pkt.stream_index] < 0) {
- av_packet_unref(&pkt);
+ in_stream = ifmt_ctx->streams[pkt->stream_index];
+ if (pkt->stream_index >= stream_mapping_size ||
+ stream_mapping[pkt->stream_index] < 0) {
+ av_packet_unref(pkt);
continue;
}
- pkt.stream_index = stream_mapping[pkt.stream_index];
- out_stream = ofmt_ctx->streams[pkt.stream_index];
- log_packet(ifmt_ctx, &pkt, "in");
+ pkt->stream_index = stream_mapping[pkt->stream_index];
+ out_stream = ofmt_ctx->streams[pkt->stream_index];
+ log_packet(ifmt_ctx, pkt, "in");
/* copy packet */
- av_packet_rescale_ts(&pkt, in_stream->time_base, out_stream->time_base);
- pkt.pos = -1;
- log_packet(ofmt_ctx, &pkt, "out");
+ av_packet_rescale_ts(pkt, in_stream->time_base, out_stream->time_base);
+ pkt->pos = -1;
+ log_packet(ofmt_ctx, pkt, "out");
- ret = av_interleaved_write_frame(ofmt_ctx, &pkt);
+ ret = av_interleaved_write_frame(ofmt_ctx, pkt);
/* pkt is now blank (av_interleaved_write_frame() takes ownership of
* its contents and resets pkt), so that no unreferencing is necessary.
* This would be different if one used av_write_frame(). */
@@ -172,6 +178,7 @@ int main(int argc, char **argv)
av_write_trailer(ofmt_ctx);
end:
+ av_packet_free(&pkt);
avformat_close_input(&ifmt_ctx);