Message ID | 20210204191005.48190-48-jamrial@gmail.com |
---|---|
State | Superseded |
Headers | show |
Series | deprecate av_init_packet() and sizeof(AVPacket) as part of the ABI | expand |
Context | Check | Description |
---|---|---|
andriy/x86_make | success | Make finished |
andriy/x86_make_fate | success | Make fate finished |
andriy/PPC64_make | success | Make finished |
andriy/PPC64_make_fate | success | Make fate finished |
On Thu, Feb 04, 2021 at 04:10:02PM -0300, James Almer wrote: > Signed-off-by: James Almer <jamrial@gmail.com> > --- > doc/examples/vaapi_transcode.c | 45 ++++++++++++++++++++-------------- > 1 file changed, 26 insertions(+), 19 deletions(-) maybe i forgot something but this breaks build here make -j32 doc/examples/vaapi_transcode.o CC doc/examples/vaapi_transcode.o doc/examples/vaapi_transcode.c: In function ‘main’: doc/examples/vaapi_transcode.c:296:21: warning: passing argument 1 of ‘av_packet_unref’ from incompatible pointer type [-Wincompatible-pointer-types] av_packet_unref(&dec_pkt); ^ In file included from ./libavcodec/bsf.h:30:0, from ./libavcodec/avcodec.h:44, from doc/examples/vaapi_transcode.c:38: ./libavcodec/packet.h:682:6: note: expected ‘AVPacket * {aka struct AVPacket *}’ but argument is of type ‘AVPacket ** {aka struct AVPacket **}’ void av_packet_unref(AVPacket *pkt); ^~~~~~~~~~~~~~~ doc/examples/vaapi_transcode.c:300:11: error: too few arguments to function ‘encode_write’ ret = encode_write(NULL); ^~~~~~~~~~~~ doc/examples/vaapi_transcode.c:112:12: note: declared here static int encode_write(AVPacket *enc_pkt, AVFrame *frame) ^~~~~~~~~~~~ ffbuild/common.mak:67: recipe for target 'doc/examples/vaapi_transcode.o' failed make: *** [doc/examples/vaapi_transcode.o] Error 1 [...]
On 2/5/2021 1:49 PM, Michael Niedermayer wrote: > On Thu, Feb 04, 2021 at 04:10:02PM -0300, James Almer wrote: >> Signed-off-by: James Almer <jamrial@gmail.com> >> --- >> doc/examples/vaapi_transcode.c | 45 ++++++++++++++++++++-------------- >> 1 file changed, 26 insertions(+), 19 deletions(-) > > maybe i forgot something but this No, you didn't. This is one of the patches i couldn't test, but since it's an example i figured it was important to ensure it's adapted alongside the deprecation, so i wrote it blind. Will try again, but otherwise someone with a vaapi enabled system will have to give it a try. > breaks build here > > make -j32 doc/examples/vaapi_transcode.o > CC doc/examples/vaapi_transcode.o > doc/examples/vaapi_transcode.c: In function ‘main’: > doc/examples/vaapi_transcode.c:296:21: warning: passing argument 1 of ‘av_packet_unref’ from incompatible pointer type [-Wincompatible-pointer-types] > av_packet_unref(&dec_pkt); > ^ > In file included from ./libavcodec/bsf.h:30:0, > from ./libavcodec/avcodec.h:44, > from doc/examples/vaapi_transcode.c:38: > ./libavcodec/packet.h:682:6: note: expected ‘AVPacket * {aka struct AVPacket *}’ but argument is of type ‘AVPacket ** {aka struct AVPacket **}’ > void av_packet_unref(AVPacket *pkt); > ^~~~~~~~~~~~~~~ > doc/examples/vaapi_transcode.c:300:11: error: too few arguments to function ‘encode_write’ > ret = encode_write(NULL); > ^~~~~~~~~~~~ > doc/examples/vaapi_transcode.c:112:12: note: declared here > static int encode_write(AVPacket *enc_pkt, AVFrame *frame) > ^~~~~~~~~~~~ > ffbuild/common.mak:67: recipe for target 'doc/examples/vaapi_transcode.o' failed > make: *** [doc/examples/vaapi_transcode.o] Error 1 > > > [...] > > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". >
diff --git a/doc/examples/vaapi_transcode.c b/doc/examples/vaapi_transcode.c index 279d20f636..5fc09dd1d3 100644 --- a/doc/examples/vaapi_transcode.c +++ b/doc/examples/vaapi_transcode.c @@ -109,28 +109,23 @@ static int open_input_file(const char *filename) return ret; } -static int encode_write(AVFrame *frame) +static int encode_write(AVPacket *enc_pkt, AVFrame *frame) { int ret = 0; - AVPacket enc_pkt; - - av_init_packet(&enc_pkt); - enc_pkt.data = NULL; - enc_pkt.size = 0; if ((ret = avcodec_send_frame(encoder_ctx, frame)) < 0) { fprintf(stderr, "Error during encoding. Error code: %s\n", av_err2str(ret)); goto end; } while (1) { - ret = avcodec_receive_packet(encoder_ctx, &enc_pkt); + ret = avcodec_receive_packet(encoder_ctx, enc_pkt); if (ret) break; - enc_pkt.stream_index = 0; - av_packet_rescale_ts(&enc_pkt, ifmt_ctx->streams[video_stream]->time_base, + enc_pkt->stream_index = 0; + av_packet_rescale_ts(enc_pkt, ifmt_ctx->streams[video_stream]->time_base, ofmt_ctx->streams[0]->time_base); - ret = av_interleaved_write_frame(ofmt_ctx, &enc_pkt); + ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt); if (ret < 0) { fprintf(stderr, "Error during writing data to output file. " "Error code: %s\n", av_err2str(ret)); @@ -148,6 +143,7 @@ end: static int dec_enc(AVPacket *pkt, AVCodec *enc_codec) { AVFrame *frame; + AVPacket *enc_pkt; int ret = 0; ret = avcodec_send_packet(decoder_ctx, pkt); @@ -159,10 +155,15 @@ static int dec_enc(AVPacket *pkt, AVCodec *enc_codec) while (ret >= 0) { if (!(frame = av_frame_alloc())) return AVERROR(ENOMEM); + if (!(enc_pkt = av_packet_alloc())) { + av_frame_free(&frame); + return AVERROR(ENOMEM); + } ret = avcodec_receive_frame(decoder_ctx, frame); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { av_frame_free(&frame); + av_packet_free(&enc_pkt); return 0; } else if (ret < 0) { fprintf(stderr, "Error while decoding. Error code: %s\n", av_err2str(ret)); @@ -216,11 +217,12 @@ static int dec_enc(AVPacket *pkt, AVCodec *enc_codec) initialized = 1; } - if ((ret = encode_write(frame)) < 0) + if ((ret = encode_write(enc_pkt, frame)) < 0) fprintf(stderr, "Error during encoding and writing.\n"); fail: av_frame_free(&frame); + av_packet_free(&enc_pkt); if (ret < 0) return ret; } @@ -230,7 +232,7 @@ fail: int main(int argc, char **argv) { int ret = 0; - AVPacket dec_pkt; + AVPacket *dec_pkt; AVCodec *enc_codec; if (argc != 4) { @@ -246,6 +248,12 @@ int main(int argc, char **argv) return -1; } + dec_pkt = av_packet_alloc(); + if (!dec_pkt) { + fprintf(stderr, "Failed to allocate decode packet\n"); + goto end; + } + if ((ret = open_input_file(argv[1])) < 0) goto end; @@ -275,20 +283,18 @@ int main(int argc, char **argv) /* read all packets and only transcoding video */ while (ret >= 0) { - if ((ret = av_read_frame(ifmt_ctx, &dec_pkt)) < 0) + if ((ret = av_read_frame(ifmt_ctx, dec_pkt)) < 0) break; - if (video_stream == dec_pkt.stream_index) - ret = dec_enc(&dec_pkt, enc_codec); + if (video_stream == dec_pkt->stream_index) + ret = dec_enc(dec_pkt, enc_codec); - av_packet_unref(&dec_pkt); + av_packet_unref(dec_pkt); } /* flush decoder */ - dec_pkt.data = NULL; - dec_pkt.size = 0; - ret = dec_enc(&dec_pkt, enc_codec); av_packet_unref(&dec_pkt); + ret = dec_enc(dec_pkt, enc_codec); /* flush encoder */ ret = encode_write(NULL); @@ -302,5 +308,6 @@ end: avcodec_free_context(&decoder_ctx); avcodec_free_context(&encoder_ctx); av_buffer_unref(&hw_device_ctx); + av_packet_free(&dec_pkt); return ret; }
Signed-off-by: James Almer <jamrial@gmail.com> --- doc/examples/vaapi_transcode.c | 45 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-)