mirror of https://git.ffmpeg.org/ffmpeg.git
examples/remuxing: Don't use stack packet
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
78426da3f4
commit
53f374c08d
|
@ -47,7 +47,7 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const AVOutputFormat *ofmt = NULL;
|
const AVOutputFormat *ofmt = NULL;
|
||||||
AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
|
AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
|
||||||
AVPacket pkt;
|
AVPacket *pkt = NULL;
|
||||||
const char *in_filename, *out_filename;
|
const char *in_filename, *out_filename;
|
||||||
int ret, i;
|
int ret, i;
|
||||||
int stream_index = 0;
|
int stream_index = 0;
|
||||||
|
@ -65,6 +65,12 @@ int main(int argc, char **argv)
|
||||||
in_filename = argv[1];
|
in_filename = argv[1];
|
||||||
out_filename = argv[2];
|
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) {
|
if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) {
|
||||||
fprintf(stderr, "Could not open input file '%s'", in_filename);
|
fprintf(stderr, "Could not open input file '%s'", in_filename);
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -140,27 +146,27 @@ int main(int argc, char **argv)
|
||||||
while (1) {
|
while (1) {
|
||||||
AVStream *in_stream, *out_stream;
|
AVStream *in_stream, *out_stream;
|
||||||
|
|
||||||
ret = av_read_frame(ifmt_ctx, &pkt);
|
ret = av_read_frame(ifmt_ctx, pkt);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
in_stream = ifmt_ctx->streams[pkt.stream_index];
|
in_stream = ifmt_ctx->streams[pkt->stream_index];
|
||||||
if (pkt.stream_index >= stream_mapping_size ||
|
if (pkt->stream_index >= stream_mapping_size ||
|
||||||
stream_mapping[pkt.stream_index] < 0) {
|
stream_mapping[pkt->stream_index] < 0) {
|
||||||
av_packet_unref(&pkt);
|
av_packet_unref(pkt);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pkt.stream_index = stream_mapping[pkt.stream_index];
|
pkt->stream_index = stream_mapping[pkt->stream_index];
|
||||||
out_stream = ofmt_ctx->streams[pkt.stream_index];
|
out_stream = ofmt_ctx->streams[pkt->stream_index];
|
||||||
log_packet(ifmt_ctx, &pkt, "in");
|
log_packet(ifmt_ctx, pkt, "in");
|
||||||
|
|
||||||
/* copy packet */
|
/* copy packet */
|
||||||
av_packet_rescale_ts(&pkt, in_stream->time_base, out_stream->time_base);
|
av_packet_rescale_ts(pkt, in_stream->time_base, out_stream->time_base);
|
||||||
pkt.pos = -1;
|
pkt->pos = -1;
|
||||||
log_packet(ofmt_ctx, &pkt, "out");
|
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
|
/* pkt is now blank (av_interleaved_write_frame() takes ownership of
|
||||||
* its contents and resets pkt), so that no unreferencing is necessary.
|
* its contents and resets pkt), so that no unreferencing is necessary.
|
||||||
* This would be different if one used av_write_frame(). */
|
* 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);
|
av_write_trailer(ofmt_ctx);
|
||||||
end:
|
end:
|
||||||
|
av_packet_free(&pkt);
|
||||||
|
|
||||||
avformat_close_input(&ifmt_ctx);
|
avformat_close_input(&ifmt_ctx);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue