[FFmpeg-devel] [PATCH 1/2] Revert "lavfi/atempo: avoid false triggering an assertion failure"
From: Pavel Koshevoy This reverts commit 4240e5b047379b29c33dd3f4438bc4e610527b83. --- libavfilter/af_atempo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c index 944df1dd32..9eee8a63a8 100644 --- a/libavfilter/af_atempo.c +++ b/libavfilter/af_atempo.c @@ -914,8 +914,8 @@ static int yae_flush(ATempoContext *atempo, atempo->state = YAE_FLUSH_OUTPUT; -if (atempo->position[0] >= frag->position[0] + frag->nsamples && -atempo->position[1] >= frag->position[1] + frag->nsamples) { +if (atempo->position[0] == frag->position[0] + frag->nsamples && +atempo->position[1] == frag->position[1] + frag->nsamples) { // the current fragment is already flushed: return 0; } -- 2.13.5 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/2] lavfi/atempo: Avoid false triggering an assertion failure
From: Pavel Koshevoy Steps to reproduce: 1. revert 4240e5b047379b29c33dd3f4438bc4e610527b83 2. ./ffmpeg -f lavfi -i sine=d=1 -af aselect=e=0,atempo=0.5 -y atempo.wav --- libavfilter/af_atempo.c | 5 + 1 file changed, 5 insertions(+) diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c index 9eee8a63a8..41c8c0382a 100644 --- a/libavfilter/af_atempo.c +++ b/libavfilter/af_atempo.c @@ -914,6 +914,11 @@ static int yae_flush(ATempoContext *atempo, atempo->state = YAE_FLUSH_OUTPUT; +if (!atempo->nfrag) { + // there is nothing to flush: + return 0; +} + if (atempo->position[0] == frag->position[0] + frag->nsamples && atempo->position[1] == frag->position[1] + frag->nsamples) { // the current fragment is already flushed: -- 2.13.5 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] lavc: Fix ticket 6024
From: Pavel Koshevoy --- libavcodec/utils.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 44ecc09..2ad96e4 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -2788,8 +2788,6 @@ static int do_decode(AVCodecContext *avctx, AVPacket *pkt) if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { ret = avcodec_decode_video2(avctx, avctx->internal->buffer_frame, &got_frame, pkt); -if (ret >= 0) -ret = pkt->size; } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { ret = avcodec_decode_audio4(avctx, avctx->internal->buffer_frame, &got_frame, pkt); -- 2.6.6 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] lavc: Fix ticket 6024 (v2)
From: Pavel Koshevoy --- libavcodec/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 44ecc09..be50459 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -2788,7 +2788,7 @@ static int do_decode(AVCodecContext *avctx, AVPacket *pkt) if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { ret = avcodec_decode_video2(avctx, avctx->internal->buffer_frame, &got_frame, pkt); -if (ret >= 0) +if (ret >= 0 && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED)) ret = pkt->size; } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { ret = avcodec_decode_audio4(avctx, avctx->internal->buffer_frame, -- 2.6.6 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] lavc: Fix ticket 6024, truncated mode decoding
From: Pavel Koshevoy The assumption that avcodec_send_packet makes regarding decoders consuming the entire packet is not true if the codec supports truncated decoding mode and the truncated flag is turned on. Steps to reproduce: ./ffmpeg_g -flags truncated \ -i "http://samples.ffmpeg.org/MPEG2/test-ebu-422.4.pakets.ts"; \ -c:v ffv1 -c:a copy -y /tmp/truncated.nut --- libavcodec/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 44ecc09..be50459 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -2788,7 +2788,7 @@ static int do_decode(AVCodecContext *avctx, AVPacket *pkt) if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { ret = avcodec_decode_video2(avctx, avctx->internal->buffer_frame, &got_frame, pkt); -if (ret >= 0) +if (ret >= 0 && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED)) ret = pkt->size; } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { ret = avcodec_decode_audio4(avctx, avctx->internal->buffer_frame, -- 2.6.6 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] Add fate test for ticket 6024, truncated decoding mode
From: Pavel Koshevoy --- tests/fate/video.mak| 3 +++ tests/ref/fate/mpeg2-ticket6024 | 27 +++ 2 files changed, 30 insertions(+) create mode 100644 tests/ref/fate/mpeg2-ticket6024 diff --git a/tests/fate/video.mak b/tests/fate/video.mak index f893688..b939185 100644 --- a/tests/fate/video.mak +++ b/tests/fate/video.mak @@ -239,6 +239,9 @@ FATE_VIDEO-$(call DEMDEC, MPEGTS, MPEG2VIDEO) += fate-mpeg2-field-enc fate-mpeg2 fate-mpeg2-field-enc: CMD = framecrc -flags +bitexact -idct simple -i $(TARGET_SAMPLES)/mpeg2/mpeg2_field_encoding.ts -an -vframes 30 fate-mpeg2-ticket186: CMD = framecrc -flags +bitexact -idct simple -i $(TARGET_SAMPLES)/mpeg2/t.mpg -an +FATE_VIDEO-$(call DEMDEC, MPEGPS, MPEG2VIDEO) += fate-mpeg2-ticket6024 +fate-mpeg2-ticket6024: CMD = framecrc -flags truncated -i $(TARGET_SAMPLES)/mpeg2/matrixbench_mpeg2.lq1.mpg -an + FATE_VIDEO-$(call DEMDEC, MV, MVC1) += fate-mv-mvc1 fate-mv-mvc1: CMD = framecrc -i $(TARGET_SAMPLES)/mv/posture.mv -an -frames 25 -pix_fmt rgb555le diff --git a/tests/ref/fate/mpeg2-ticket6024 b/tests/ref/fate/mpeg2-ticket6024 new file mode 100644 index 000..bd41624 --- /dev/null +++ b/tests/ref/fate/mpeg2-ticket6024 @@ -0,0 +1,27 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 716x236 +#sar 0: 1/1 +0, 2, 2,1, 253464, 0xc51a46f9 +0, 4, 4,1, 253464, 0xd0661651 +0, 5, 5,1, 253464, 0x38a213b3 +0, 6, 6,1, 253464, 0x038a5118 +0, 7, 7,1, 253464, 0xebd8de64 +0, 8, 8,1, 253464, 0x0b319ee0 +0, 9, 9,1, 253464, 0x37b03a45 +0, 10, 10,1, 253464, 0x5f9c89ae +0, 11, 11,1, 253464, 0x88ad9c08 +0, 12, 12,1, 253464, 0x387198bc +0, 13, 13,1, 253464, 0xf3933eb6 +0, 14, 14,1, 253464, 0x9bd27b98 +0, 15, 15,1, 253464, 0x9442c538 +0, 16, 16,1, 253464, 0x330be2a4 +0, 17, 17,1, 253464, 0xb4b8c1df +0, 18, 18,1, 253464, 0xc97ded34 +0, 19, 19,1, 253464, 0xcad936e0 +0, 20, 20,1, 253464, 0x11a2850d +0, 21, 21,1, 253464, 0x2545ad23 +0, 22, 22,1, 253464, 0xa5e17c47 +0, 23, 23,1, 253464, 0x39452689 +0, 24, 24,1, 253464, 0x1daefd72 -- 2.6.6 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] lavfi/atempo: Avoid false triggering an assertion failure
From: Pavel Koshevoy Steps to reproduce: ./ffmpeg_g -f s16be -i /dev/null -af atempo=0.5 -y /tmp/atempo.wav --- libavfilter/af_atempo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c index 59b08ec..a487882 100644 --- a/libavfilter/af_atempo.c +++ b/libavfilter/af_atempo.c @@ -914,8 +914,8 @@ static int yae_flush(ATempoContext *atempo, atempo->state = YAE_FLUSH_OUTPUT; -if (atempo->position[0] == frag->position[0] + frag->nsamples && -atempo->position[1] == frag->position[1] + frag->nsamples) { +if (atempo->position[0] >= frag->position[0] + frag->nsamples && +atempo->position[1] >= frag->position[1] + frag->nsamples) { // the current fragment is already flushed: return 0; } -- 2.6.6 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] Add fate test for ticket 6024, truncated decoding mode (v2)
From: Pavel Koshevoy --- tests/fate/video.mak| 3 +++ tests/ref/fate/mpeg2-ticket6024 | 27 +++ 2 files changed, 30 insertions(+) create mode 100644 tests/ref/fate/mpeg2-ticket6024 diff --git a/tests/fate/video.mak b/tests/fate/video.mak index f893688..7636ab2 100644 --- a/tests/fate/video.mak +++ b/tests/fate/video.mak @@ -239,6 +239,9 @@ FATE_VIDEO-$(call DEMDEC, MPEGTS, MPEG2VIDEO) += fate-mpeg2-field-enc fate-mpeg2 fate-mpeg2-field-enc: CMD = framecrc -flags +bitexact -idct simple -i $(TARGET_SAMPLES)/mpeg2/mpeg2_field_encoding.ts -an -vframes 30 fate-mpeg2-ticket186: CMD = framecrc -flags +bitexact -idct simple -i $(TARGET_SAMPLES)/mpeg2/t.mpg -an +FATE_VIDEO-$(call DEMDEC, MPEGPS, MPEG2VIDEO) += fate-mpeg2-ticket6024 +fate-mpeg2-ticket6024: CMD = framecrc -flags +bitexact -idct simple -flags +truncated -i $(TARGET_SAMPLES)/mpeg2/matrixbench_mpeg2.lq1.mpg -an + FATE_VIDEO-$(call DEMDEC, MV, MVC1) += fate-mv-mvc1 fate-mv-mvc1: CMD = framecrc -i $(TARGET_SAMPLES)/mv/posture.mv -an -frames 25 -pix_fmt rgb555le diff --git a/tests/ref/fate/mpeg2-ticket6024 b/tests/ref/fate/mpeg2-ticket6024 new file mode 100644 index 000..bd41624 --- /dev/null +++ b/tests/ref/fate/mpeg2-ticket6024 @@ -0,0 +1,27 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 716x236 +#sar 0: 1/1 +0, 2, 2,1, 253464, 0xc51a46f9 +0, 4, 4,1, 253464, 0xd0661651 +0, 5, 5,1, 253464, 0x38a213b3 +0, 6, 6,1, 253464, 0x038a5118 +0, 7, 7,1, 253464, 0xebd8de64 +0, 8, 8,1, 253464, 0x0b319ee0 +0, 9, 9,1, 253464, 0x37b03a45 +0, 10, 10,1, 253464, 0x5f9c89ae +0, 11, 11,1, 253464, 0x88ad9c08 +0, 12, 12,1, 253464, 0x387198bc +0, 13, 13,1, 253464, 0xf3933eb6 +0, 14, 14,1, 253464, 0x9bd27b98 +0, 15, 15,1, 253464, 0x9442c538 +0, 16, 16,1, 253464, 0x330be2a4 +0, 17, 17,1, 253464, 0xb4b8c1df +0, 18, 18,1, 253464, 0xc97ded34 +0, 19, 19,1, 253464, 0xcad936e0 +0, 20, 20,1, 253464, 0x11a2850d +0, 21, 21,1, 253464, 0x2545ad23 +0, 22, 22,1, 253464, 0xa5e17c47 +0, 23, 23,1, 253464, 0x39452689 +0, 24, 24,1, 253464, 0x1daefd72 -- 2.6.6 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] Restore compatibility with powerpc-apple-darwin9-gcc-4.2.1
From: Pavel Koshevoy ... and attempt to preserve compatibility with clang that was introduced in 311a953c76081fca99b872629d248f9d69ebc0c3 (untested) --- libavcodec/ppc/asm.S | 8 +++- libavcodec/ppc/fft_altivec.S | 26 +++--- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/libavcodec/ppc/asm.S b/libavcodec/ppc/asm.S index 700aa0d..6222b8b 100644 --- a/libavcodec/ppc/asm.S +++ b/libavcodec/ppc/asm.S @@ -24,6 +24,12 @@ #define JOIN(a, b) GLUE(a, b) #define X(s) JOIN(EXTERN_ASM, s) +#if __APPLE__ +#define R(n) r ## n +#else +#define R(n) n +#endif + #if ARCH_PPC64 #define PTR .quad @@ -53,7 +59,7 @@ L(\name): .endm .macro movrel rd, sym, gp -ld \rd, \sym@got(2) +ld \rd, \sym@got(R(2)) .endm .macro get_got rd diff --git a/libavcodec/ppc/fft_altivec.S b/libavcodec/ppc/fft_altivec.S index e0149a4..8cd68d6 100644 --- a/libavcodec/ppc/fft_altivec.S +++ b/libavcodec/ppc/fft_altivec.S @@ -354,14 +354,18 @@ fft_data: .macro fft_calc interleave extfunc ff_fft_calc\interleave\()_altivec mflrr0 -stp r0, 2*PS(1) -stpur1, -(160+16*PS)(1) +stp r0, 2*PS(R(1)) +stpur1, -(160+16*PS)(R(1)) get_got r11 addir6, r1, 16*PS stvmr6, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29 mfvrsave r0 -stw r0, 15*PS(1) -li r6, -4 #0xfffc +stw r0, 15*PS(R(1)) +#if __APPLE__ +li r6, 0xfffc +#else +li r6, -4 +#endif mtvrsave r6 movrel r6, fft_data, r11 @@ -372,7 +376,7 @@ extfunc ff_fft_calc\interleave\()_altivec movrel r12, X(ff_cos_tabs), r11 movrel r6, fft_dispatch_tab\interleave\()_altivec, r11 -lwz r3, 0(3) +lwz r3, 0(R(3)) subir3, r3, 2 slwir3, r3, 2+ARCH_PPC64 lpx r3, r3, r6 @@ -382,10 +386,10 @@ extfunc ff_fft_calc\interleave\()_altivec addir6, r1, 16*PS lvm r6, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29 -lwz r6, 15*PS(1) +lwz r6, 15*PS(R(1)) mtvrsave r6 -lp r1, 0(1) -lp r0, 2*PS(1) +lp r1, 0(R(1)) +lp r0, 2*PS(R(1)) mtlrr0 blr .endm @@ -393,15 +397,15 @@ extfunc ff_fft_calc\interleave\()_altivec .macro DECL_FFT suffix, bits, n, n2, n4 fft\n\suffix\()_altivec: mflr r0 -stp r0,PS*(\bits-3)(1) +stp r0,PS*(\bits-3)(R(1)) blfft\n2\()_altivec addi2 r3,\n*4 blfft\n4\()_altivec addi2 r3,\n*2 blfft\n4\()_altivec addi2 r3,\n*-6 -lpr0,PS*(\bits-3)(1) -lpr4,\bits*PS(12) +lpr0,PS*(\bits-3)(R(1)) +lpr4,\bits*PS(R(12)) mtlr r0 lir5,\n/16 b fft_pass\suffix\()_altivec -- 2.6.6 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] lavc/cuvid: fail early if GPU can't handle given video resolution
From: Pavel Koshevoy NVDEC (CUVID) does not support unlimited video resolutions, so if the resolution of the source is known it can be used during avcodec_open2 call to fail early, rather than failing later during avcodec_send_packet call. This problem surfaced when trying to decode 5120x2700 h246 video on Geforce GT 730 -- avcodec_open2 succeeded but decoding failed. --- libavcodec/cuvid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/cuvid.c b/libavcodec/cuvid.c index 8fc713d..2e70b62 100644 --- a/libavcodec/cuvid.c +++ b/libavcodec/cuvid.c @@ -625,8 +625,8 @@ static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cu cuinfo.ChromaFormat = cudaVideoChromaFormat_420; cuinfo.OutputFormat = cudaVideoSurfaceFormat_NV12; -cuinfo.ulWidth = 1280; -cuinfo.ulHeight = 720; +cuinfo.ulWidth = avctx->coded_width ? avctx->coded_width : 1280; +cuinfo.ulHeight = avctx->coded_height ? avctx->coded_height : 720; cuinfo.ulTargetWidth = cuinfo.ulWidth; cuinfo.ulTargetHeight = cuinfo.ulHeight; -- 2.9.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] lavc/cuvid: fail early if GPU can't handle given video parameters
From: Pavel Koshevoy Evidently CUVID doesn't support decoding 422 or 444 chroma formats, and only a limited set of resolutions per codec are supported. Given that stream resolution and pixel format are typically known as a result of probing it is better to use this info during avcodec_open2 call and fail early in case the video parameters are not supported, rather than failing later during avcodec_send_packet calls. This problem surfaced when trying to decode 5120x2700 h246 video on Geforce GT 730, or when decoding 422 mpeg2 stream on same GPU -- avcodec_open2 succeeded but decoding failed. --- libavcodec/cuvid.c | 58 +- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/libavcodec/cuvid.c b/libavcodec/cuvid.c index 8fc713d..febdd71 100644 --- a/libavcodec/cuvid.c +++ b/libavcodec/cuvid.c @@ -612,7 +612,11 @@ static av_cold int cuvid_decode_end(AVCodecContext *avctx) return 0; } -static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cuparseinfo) +static int cuvid_test_dummy_decoder(AVCodecContext *avctx, +const CUVIDPARSERPARAMS *cuparseinfo, +cudaVideoChromaFormat probed_chroma_format, +int probed_width, +int probed_height) { CuvidContext *ctx = avctx->priv_data; CUVIDDECODECREATEINFO cuinfo; @@ -622,11 +626,11 @@ static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cu memset(&cuinfo, 0, sizeof(cuinfo)); cuinfo.CodecType = cuparseinfo->CodecType; -cuinfo.ChromaFormat = cudaVideoChromaFormat_420; +cuinfo.ChromaFormat = probed_chroma_format; cuinfo.OutputFormat = cudaVideoSurfaceFormat_NV12; -cuinfo.ulWidth = 1280; -cuinfo.ulHeight = 720; +cuinfo.ulWidth = probed_width; +cuinfo.ulHeight = probed_height; cuinfo.ulTargetWidth = cuinfo.ulWidth; cuinfo.ulTargetHeight = cuinfo.ulHeight; @@ -653,6 +657,36 @@ static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cu return 0; } +static int convert_to_cuda_video_chroma_format(enum AVPixelFormat pix_fmt, + cudaVideoChromaFormat *out) +{ +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); +if (!(out && desc && + (desc->nb_components == 1 || desc->nb_components == 3) && + (desc->log2_chroma_w < 2 && desc->log2_chroma_h < 2))) +{ +return AVERROR(EINVAL); +} + +if (desc->nb_components == 1) +{ +*out = cudaVideoChromaFormat_Monochrome; +} +else if (desc->flags == AV_PIX_FMT_FLAG_PLANAR) +{ +*out = ((desc->log2_chroma_w == 0) ? cudaVideoChromaFormat_444 : +(desc->log2_chroma_h == 0) ? cudaVideoChromaFormat_422 : +cudaVideoChromaFormat_420); +} +else +{ +return AVERROR(EINVAL); +} + +// unfortunately, 420 is the only one that works: +return (*out == cudaVideoChromaFormat_420) ? 0 : AVERROR_EXTERNAL; +} + static av_cold int cuvid_decode_init(AVCodecContext *avctx) { CuvidContext *ctx = avctx->priv_data; @@ -663,12 +697,23 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) CUcontext cuda_ctx = NULL; CUcontext dummy; const AVBitStreamFilter *bsf; +cudaVideoChromaFormat probed_chroma_format; +int probed_width; +int probed_height; int ret = 0; enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12, AV_PIX_FMT_NONE }; +ret = convert_to_cuda_video_chroma_format(avctx->pix_fmt, &probed_chroma_format); +if (ret < 0) { +// pixel format is not supported: +return ret; +} +probed_width = avctx->coded_width ? avctx->coded_width : 1280; +probed_height = avctx->coded_height ? avctx->coded_height : 720; + // Accelerated transcoding scenarios with 'ffmpeg' require that the // pix_fmt be set to AV_PIX_FMT_CUDA early. The sw_pix_fmt, and the // pix_fmt for non-accelerated transcoding, do not need to be correct @@ -824,7 +869,10 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) if (ret < 0) goto error; -ret = cuvid_test_dummy_decoder(avctx, &ctx->cuparseinfo); +ret = cuvid_test_dummy_decoder(avctx, &ctx->cuparseinfo, + probed_chroma_format, + probed_width, + probed_height); if (ret < 0) goto error; -- 2.9.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] lavc/cuvid: fail early if GPU can't handle video parameters
From: Pavel Koshevoy Evidently CUVID doesn't support decoding 422 or 444 chroma formats, and only a limited set of resolutions per codec are supported. Given that stream resolution and pixel format are typically known as a result of probing it is better to use this info during avcodec_open2 call and fail early in case the video parameters are not supported, rather than failing later during avcodec_send_packet calls. This problem surfaced when trying to decode 5120x2700 h246 video on GeForce GT 730, or when decoding 422 mpeg2/h264 streams on same GPU - avcodec_open2 succeeds but decoding fails. --- libavcodec/cuvid.c | 62 +- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/libavcodec/cuvid.c b/libavcodec/cuvid.c index 8fc713d..ed21f94 100644 --- a/libavcodec/cuvid.c +++ b/libavcodec/cuvid.c @@ -612,7 +612,11 @@ static av_cold int cuvid_decode_end(AVCodecContext *avctx) return 0; } -static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cuparseinfo) +static int cuvid_test_dummy_decoder(AVCodecContext *avctx, +const CUVIDPARSERPARAMS *cuparseinfo, +cudaVideoChromaFormat probed_chroma_format, +int probed_width, +int probed_height) { CuvidContext *ctx = avctx->priv_data; CUVIDDECODECREATEINFO cuinfo; @@ -622,11 +626,11 @@ static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cu memset(&cuinfo, 0, sizeof(cuinfo)); cuinfo.CodecType = cuparseinfo->CodecType; -cuinfo.ChromaFormat = cudaVideoChromaFormat_420; +cuinfo.ChromaFormat = probed_chroma_format; cuinfo.OutputFormat = cudaVideoSurfaceFormat_NV12; -cuinfo.ulWidth = 1280; -cuinfo.ulHeight = 720; +cuinfo.ulWidth = probed_width; +cuinfo.ulHeight = probed_height; cuinfo.ulTargetWidth = cuinfo.ulWidth; cuinfo.ulTargetHeight = cuinfo.ulHeight; @@ -653,6 +657,36 @@ static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cu return 0; } +static int convert_to_cuda_video_chroma_format(enum AVPixelFormat pix_fmt, + cudaVideoChromaFormat *out) +{ +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); +if (!(out && desc && + (desc->nb_components == 1 || desc->nb_components == 3) && + (desc->log2_chroma_w < 2 && desc->log2_chroma_h < 2))) +{ +return AVERROR(EINVAL); +} + +if (desc->nb_components == 1) +{ +*out = cudaVideoChromaFormat_Monochrome; +} +else if (desc->flags == AV_PIX_FMT_FLAG_PLANAR) +{ +*out = ((desc->log2_chroma_w == 0) ? cudaVideoChromaFormat_444 : +(desc->log2_chroma_h == 0) ? cudaVideoChromaFormat_422 : +cudaVideoChromaFormat_420); +} +else +{ +return AVERROR(EINVAL); +} + +// unfortunately, 420 is the only one that works: +return (*out == cudaVideoChromaFormat_420) ? 0 : AVERROR_EXTERNAL; +} + static av_cold int cuvid_decode_init(AVCodecContext *avctx) { CuvidContext *ctx = avctx->priv_data; @@ -663,12 +697,27 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) CUcontext cuda_ctx = NULL; CUcontext dummy; const AVBitStreamFilter *bsf; +cudaVideoChromaFormat probed_chroma_format; +int probed_width; +int probed_height; int ret = 0; enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12, AV_PIX_FMT_NONE }; +enum AVPixelFormat probed_pix_fmt = (avctx->pix_fmt < 0 ? + AV_PIX_FMT_YUV420P : + avctx->pix_fmt); + +ret = convert_to_cuda_video_chroma_format(probed_pix_fmt, &probed_chroma_format); +if (ret < 0) { +// pixel format is not supported: +return ret; +} +probed_width = avctx->coded_width ? avctx->coded_width : 1280; +probed_height = avctx->coded_height ? avctx->coded_height : 720; + // Accelerated transcoding scenarios with 'ffmpeg' require that the // pix_fmt be set to AV_PIX_FMT_CUDA early. The sw_pix_fmt, and the // pix_fmt for non-accelerated transcoding, do not need to be correct @@ -824,7 +873,10 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) if (ret < 0) goto error; -ret = cuvid_test_dummy_decoder(avctx, &ctx->cuparseinfo); +ret = cuvid_test_dummy_decoder(avctx, &ctx->cuparseinfo, + probed_chroma_format, + probed_width, + probed_height); if (ret < 0) goto error; -- 2.6.6 ___ ffmpeg-devel mailing list ffmpeg-deve
[FFmpeg-devel] [PATCH] lavc/cuvid: fail early if GPU can't handle video parameters
From: Pavel Koshevoy Evidently CUVID doesn't support decoding 422 or 444 chroma formats, and only a limited set of resolutions per codec are supported. Unfortunately CUVID silently drops packets for video of unsupported resolution. However, it will error-out at cuvidCreateDecoder call if the indicated video resolution is not supported. Given that stream resolution and pixel format are typically known as a result of probing it is better to use this information during avcodec_open2 call to fail immediately, rather than proceeding to decode and never receiving any frames from the decoder nor receiving any indication of decode failure. --- libavcodec/cuvid.c | 62 +- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/libavcodec/cuvid.c b/libavcodec/cuvid.c index 8fc713d..f9c29a1 100644 --- a/libavcodec/cuvid.c +++ b/libavcodec/cuvid.c @@ -612,7 +612,11 @@ static av_cold int cuvid_decode_end(AVCodecContext *avctx) return 0; } -static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cuparseinfo) +static int cuvid_test_dummy_decoder(AVCodecContext *avctx, +const CUVIDPARSERPARAMS *cuparseinfo, +cudaVideoChromaFormat probed_chroma_format, +int probed_width, +int probed_height) { CuvidContext *ctx = avctx->priv_data; CUVIDDECODECREATEINFO cuinfo; @@ -622,11 +626,11 @@ static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cu memset(&cuinfo, 0, sizeof(cuinfo)); cuinfo.CodecType = cuparseinfo->CodecType; -cuinfo.ChromaFormat = cudaVideoChromaFormat_420; +cuinfo.ChromaFormat = probed_chroma_format; cuinfo.OutputFormat = cudaVideoSurfaceFormat_NV12; -cuinfo.ulWidth = 1280; -cuinfo.ulHeight = 720; +cuinfo.ulWidth = probed_width; +cuinfo.ulHeight = probed_height; cuinfo.ulTargetWidth = cuinfo.ulWidth; cuinfo.ulTargetHeight = cuinfo.ulHeight; @@ -653,6 +657,36 @@ static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cu return 0; } +static int convert_to_cuda_video_chroma_format(enum AVPixelFormat pix_fmt, + cudaVideoChromaFormat *out) +{ +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); +if (!(out && desc && + (desc->nb_components == 1 || desc->nb_components == 3) && + (desc->log2_chroma_w < 2 && desc->log2_chroma_h < 2))) +{ +return AVERROR(EINVAL); +} + +if (desc->nb_components == 1) +{ +*out = cudaVideoChromaFormat_Monochrome; +} +else if (desc->flags == AV_PIX_FMT_FLAG_PLANAR) +{ +*out = ((desc->log2_chroma_w == 0) ? cudaVideoChromaFormat_444 : +(desc->log2_chroma_h == 0) ? cudaVideoChromaFormat_422 : +cudaVideoChromaFormat_420); +} +else +{ +return AVERROR(EINVAL); +} + +// unfortunately, 420 is the only one that works: +return (*out == cudaVideoChromaFormat_420) ? 0 : AVERROR_EXTERNAL; +} + static av_cold int cuvid_decode_init(AVCodecContext *avctx) { CuvidContext *ctx = avctx->priv_data; @@ -663,12 +697,27 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) CUcontext cuda_ctx = NULL; CUcontext dummy; const AVBitStreamFilter *bsf; +cudaVideoChromaFormat probed_chroma_format; +int probed_width; +int probed_height; int ret = 0; enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12, AV_PIX_FMT_NONE }; +enum AVPixelFormat probed_pix_fmt = (avctx->pix_fmt <= 0 ? + AV_PIX_FMT_YUV420P : + avctx->pix_fmt); + +ret = convert_to_cuda_video_chroma_format(probed_pix_fmt, &probed_chroma_format); +if (ret < 0) { +// pixel format is not supported: +return ret; +} +probed_width = avctx->coded_width ? avctx->coded_width : 1280; +probed_height = avctx->coded_height ? avctx->coded_height : 720; + // Accelerated transcoding scenarios with 'ffmpeg' require that the // pix_fmt be set to AV_PIX_FMT_CUDA early. The sw_pix_fmt, and the // pix_fmt for non-accelerated transcoding, do not need to be correct @@ -824,7 +873,10 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) if (ret < 0) goto error; -ret = cuvid_test_dummy_decoder(avctx, &ctx->cuparseinfo); +ret = cuvid_test_dummy_decoder(avctx, &ctx->cuparseinfo, + probed_chroma_format, + probed_width, + probed_height); if (ret < 0) goto error; -- 2.9.2
[FFmpeg-devel] [PATCH] lavc/cuvid: fail early if GPU can't handle video parameters (v4)
From: Pavel Koshevoy Evidently CUVID doesn't support decoding 422 or 444 chroma formats, and only a limited set of resolutions per codec are supported. Unfortunately CUVID silently drops packets for video of unsupported resolution. However, it will error-out at cuvidCreateDecoder call if the indicated video resolution is not supported. Given that stream resolution and pixel format are typically known as a result of probing it is better to use this information during avcodec_open2 call to fail immediately, rather than proceeding to decode and never receiving any frames from the decoder nor receiving any indication of decode failure. --- libavcodec/cuvid.c | 64 +- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/libavcodec/cuvid.c b/libavcodec/cuvid.c index 8fc713d..adaf75e 100644 --- a/libavcodec/cuvid.c +++ b/libavcodec/cuvid.c @@ -612,7 +612,11 @@ static av_cold int cuvid_decode_end(AVCodecContext *avctx) return 0; } -static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cuparseinfo) +static int cuvid_test_dummy_decoder(AVCodecContext *avctx, +const CUVIDPARSERPARAMS *cuparseinfo, +cudaVideoChromaFormat probed_chroma_format, +int probed_width, +int probed_height) { CuvidContext *ctx = avctx->priv_data; CUVIDDECODECREATEINFO cuinfo; @@ -622,11 +626,11 @@ static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cu memset(&cuinfo, 0, sizeof(cuinfo)); cuinfo.CodecType = cuparseinfo->CodecType; -cuinfo.ChromaFormat = cudaVideoChromaFormat_420; +cuinfo.ChromaFormat = probed_chroma_format; cuinfo.OutputFormat = cudaVideoSurfaceFormat_NV12; -cuinfo.ulWidth = 1280; -cuinfo.ulHeight = 720; +cuinfo.ulWidth = probed_width; +cuinfo.ulHeight = probed_height; cuinfo.ulTargetWidth = cuinfo.ulWidth; cuinfo.ulTargetHeight = cuinfo.ulHeight; @@ -653,6 +657,36 @@ static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cu return 0; } +static int convert_to_cuda_video_chroma_format(enum AVPixelFormat pix_fmt, + cudaVideoChromaFormat *out) +{ +const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); +if (!(out && desc && + (desc->nb_components == 1 || desc->nb_components == 3) && + (desc->log2_chroma_w < 2 && desc->log2_chroma_h < 2))) +{ +return AVERROR(EINVAL); +} + +if (desc->nb_components == 1) +{ +*out = cudaVideoChromaFormat_Monochrome; +} +else if (desc->flags == AV_PIX_FMT_FLAG_PLANAR) +{ +*out = ((desc->log2_chroma_w == 0) ? cudaVideoChromaFormat_444 : +(desc->log2_chroma_h == 0) ? cudaVideoChromaFormat_422 : +cudaVideoChromaFormat_420); +} +else +{ +return AVERROR(EINVAL); +} + +// unfortunately, 420 is the only one that works: +return (*out == cudaVideoChromaFormat_420) ? 0 : AVERROR_EXTERNAL; +} + static av_cold int cuvid_decode_init(AVCodecContext *avctx) { CuvidContext *ctx = avctx->priv_data; @@ -663,12 +697,29 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) CUcontext cuda_ctx = NULL; CUcontext dummy; const AVBitStreamFilter *bsf; +cudaVideoChromaFormat probed_chroma_format; +int probed_width; +int probed_height; int ret = 0; enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12, AV_PIX_FMT_NONE }; +enum AVPixelFormat probed_pix_fmt = (avctx->pix_fmt <= 0 ? + AV_PIX_FMT_YUV420P : + avctx->pix_fmt); + +ret = convert_to_cuda_video_chroma_format(probed_pix_fmt, &probed_chroma_format); +if (ret < 0) { +const char * pix_fmt_name = av_get_pix_fmt_name(probed_pix_fmt); +pix_fmt_name || (pix_fmt_name = "unknown"); +av_log(avctx, AV_LOG_ERROR, "pixel format is not supported: %s\n", pix_fmt_name); +return ret; +} +probed_width = avctx->coded_width ? avctx->coded_width : 1280; +probed_height = avctx->coded_height ? avctx->coded_height : 720; + // Accelerated transcoding scenarios with 'ffmpeg' require that the // pix_fmt be set to AV_PIX_FMT_CUDA early. The sw_pix_fmt, and the // pix_fmt for non-accelerated transcoding, do not need to be correct @@ -824,7 +875,10 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) if (ret < 0) goto error; -ret = cuvid_test_dummy_decoder(avctx, &ctx->cuparseinfo); +ret = cuvid_test_dummy_decoder(avctx, &ctx->cuparseinfo, + probed_chroma_format, +
[FFmpeg-devel] [PATCH] lavc/cuvid: fail early if GPU can't handle video resolution (v5)
From: Pavel Koshevoy CUVID on GeForce GT 730 and GeForce GTX 1060 does not report any when decoding 8K h264 packets. However, it does return an error during cuvidCreateDecoder call if the indicated video resolution is not supported. Given that stream resolution is typically known as a result of probing it is better to use this information during avcodec_open2 call to fail immediately, rather than proceeding to decode and never receiving any frames from the decoder nor receiving any indication of decode failure. --- libavcodec/cuvid.c | 16 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libavcodec/cuvid.c b/libavcodec/cuvid.c index 8fc713d..9b35476 100644 --- a/libavcodec/cuvid.c +++ b/libavcodec/cuvid.c @@ -612,7 +612,10 @@ static av_cold int cuvid_decode_end(AVCodecContext *avctx) return 0; } -static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cuparseinfo) +static int cuvid_test_dummy_decoder(AVCodecContext *avctx, +const CUVIDPARSERPARAMS *cuparseinfo, +int probed_width, +int probed_height) { CuvidContext *ctx = avctx->priv_data; CUVIDDECODECREATEINFO cuinfo; @@ -625,8 +628,8 @@ static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cu cuinfo.ChromaFormat = cudaVideoChromaFormat_420; cuinfo.OutputFormat = cudaVideoSurfaceFormat_NV12; -cuinfo.ulWidth = 1280; -cuinfo.ulHeight = 720; +cuinfo.ulWidth = probed_width; +cuinfo.ulHeight = probed_height; cuinfo.ulTargetWidth = cuinfo.ulWidth; cuinfo.ulTargetHeight = cuinfo.ulHeight; @@ -669,6 +672,9 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) AV_PIX_FMT_NV12, AV_PIX_FMT_NONE }; +int probed_width = avctx->coded_width ? avctx->coded_width : 1280; +int probed_height = avctx->coded_height ? avctx->coded_height : 720; + // Accelerated transcoding scenarios with 'ffmpeg' require that the // pix_fmt be set to AV_PIX_FMT_CUDA early. The sw_pix_fmt, and the // pix_fmt for non-accelerated transcoding, do not need to be correct @@ -824,7 +830,9 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx) if (ret < 0) goto error; -ret = cuvid_test_dummy_decoder(avctx, &ctx->cuparseinfo); +ret = cuvid_test_dummy_decoder(avctx, &ctx->cuparseinfo, + probed_width, + probed_height); if (ret < 0) goto error; -- 2.6.6 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] lavc/vda_h264_dec.c Fix NULL pointer dereference
From: Pavel Koshevoy ps.sps_list entries may be NULL, so check before dereferencing --- libavcodec/vda_h264_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/vda_h264_dec.c b/libavcodec/vda_h264_dec.c index 92839e2..972bd6b 100644 --- a/libavcodec/vda_h264_dec.c +++ b/libavcodec/vda_h264_dec.c @@ -226,7 +226,7 @@ static av_cold int vdadec_init(AVCodecContext *avctx) ctx->h264_initialized = 1; for (i = 0; i < MAX_SPS_COUNT; i++) { -const SPS *sps = (const SPS*)ctx->h264ctx.ps.sps_list[i]->data; +const SPS *sps = ctx->h264ctx.ps.sps_list[i] ? (const SPS*)ctx->h264ctx.ps.sps_list[i]->data : NULL; if (sps && (sps->bit_depth_luma != 8 || sps->chroma_format_idc == 2 || sps->chroma_format_idc == 3)) { -- 2.6.6 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] avfilter/af_atempo: fix drift calculation, ticket #6157
From: Pavel Koshevoy --- libavfilter/af_atempo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c index a487882..eb62656 100644 --- a/libavfilter/af_atempo.c +++ b/libavfilter/af_atempo.c @@ -697,11 +697,11 @@ static int yae_adjust_position(ATempoContext *atempo) AudioFragment *frag = yae_curr_frag(atempo); const double prev_output_position = -(double)(prev->position[1] - atempo->origin[1] + atempo->window / 2); +(double)(prev->position[1] - atempo->origin[1] + atempo->window / 2) * +atempo->tempo; const double ideal_output_position = -(double)(prev->position[0] - atempo->origin[0] + atempo->window / 2) / -atempo->tempo; +(double)(prev->position[0] - atempo->origin[0] + atempo->window / 2); const int drift = (int)(prev_output_position - ideal_output_position); -- 2.6.6 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel