[FFmpeg-devel] [PATCH] Correct space color when using libopenjpeg

2023-03-11 Thread Wang Chuan

When decoding jp2 with palette, [color space] is determined when calling
[opj_decode]. Because of this, [pix_fmt] should be set after decoding.
Otherwise, [pix_fmt] will be set to AV_PIX_FMT_GRAY8 and output an wrong
image.

Signed-off-by: Wang Chuan 
---
 libavcodec/libopenjpegdec.c | 35 ++-
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c
index 206db07ec7..1a8d599840 100644
--- a/libavcodec/libopenjpegdec.c
+++ b/libavcodec/libopenjpegdec.c
@@ -399,6 +399,23 @@ static int libopenjpeg_decode_frame(AVCodecContext 
*avctx, AVFrame *picture,

 if (ret < 0)
 goto done;
 +ret = !opj_decode(dec, stream, image);
+
+if (ret) {
+av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n");
+ret = AVERROR_EXTERNAL;
+goto done;
+}
+
+for (i = 0; i < image->numcomps; i++) {
+if (!image->comps[i].data) {
+av_log(avctx, AV_LOG_ERROR,
+   "Image component %d contains no data.\n", i);
+ret = AVERROR_INVALIDDATA;
+goto done;
+}
+}
+
 if (avctx->pix_fmt != AV_PIX_FMT_NONE)
 if (!libopenjpeg_matches_pix_fmt(image, avctx->pix_fmt))
 avctx->pix_fmt = AV_PIX_FMT_NONE;
@@ -411,6 +428,7 @@ static int libopenjpeg_decode_frame(AVCodecContext 
*avctx, AVFrame *picture,

 ret = AVERROR_UNKNOWN;
 goto done;
 }
+
 for (i = 0; i < image->numcomps; i++)
 if (image->comps[i].prec > avctx->bits_per_raw_sample)
 avctx->bits_per_raw_sample = image->comps[i].prec;
@@ -418,23 +436,6 @@ static int libopenjpeg_decode_frame(AVCodecContext 
*avctx, AVFrame *picture,

 if ((ret = ff_thread_get_buffer(avctx, picture, 0)) < 0)
 goto done;
 -ret = !opj_decode(dec, stream, image);
-
-if (ret) {
-av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n");
-ret = AVERROR_EXTERNAL;
-goto done;
-}
-
-for (i = 0; i < image->numcomps; i++) {
-if (!image->comps[i].data) {
-av_log(avctx, AV_LOG_ERROR,
-   "Image component %d contains no data.\n", i);
-ret = AVERROR_INVALIDDATA;
-goto done;
-}
-}
-
 desc   = av_pix_fmt_desc_get(avctx->pix_fmt);
 pixel_size = desc->comp[0].step;
 ispacked   = libopenjpeg_ispacked(avctx->pix_fmt);
--
2.37.1 (Apple Git-137.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] d3d11va: let user can create SRV from output

2022-03-08 Thread Wang Chuan

Starting from Windows 8, users can create SRV from video resource
and bind it to shaders directly. This can avoid unnecessary memcpy
(ID3D11DeviceContext::CopyResource, etc), so create texture with
[D3D11_BIND_SHADER_RESOURCE] as decoder's output if possible.

Signed-off-by: Wang Chuan 
---
 libavcodec/dxva2.c|  2 +-
 libavutil/hwcontext_d3d11va.c | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
index 568d686f39..15b25d793c 100644
--- a/libavcodec/dxva2.c
+++ b/libavcodec/dxva2.c
@@ -645,7 +645,7 @@ int ff_dxva2_common_frame_params(AVCodecContext *avctx,
 if (frames_ctx->format == AV_PIX_FMT_D3D11) {
 AVD3D11VAFramesContext *frames_hwctx = frames_ctx->hwctx;
 -frames_hwctx->BindFlags |= D3D11_BIND_DECODER;
+frames_hwctx->BindFlags |= (D3D11_BIND_DECODER | 
D3D11_BIND_SHADER_RESOURCE);

 }
 #endif
 diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
index 8ab96bad25..97ffd745bd 100644
--- a/libavutil/hwcontext_d3d11va.c
+++ b/libavutil/hwcontext_d3d11va.c
@@ -203,6 +203,11 @@ static AVBufferRef 
*d3d11va_alloc_single(AVHWFramesContext *ctx)

 };
  hr = ID3D11Device_CreateTexture2D(device_hwctx->device, , 
NULL, );

+if (FAILED(hr) && (texDesc.BindFlags & D3D11_BIND_SHADER_RESOURCE)) {
+av_log(ctx, AV_LOG_ERROR, "Could not create the texture with 
[D3D11_BIND_SHADER_RESOURCE] flag");

+texDesc.BindFlags &= ~D3D11_BIND_SHADER_RESOURCE;
+hr = ID3D11Device_CreateTexture2D(device_hwctx->device, 
, NULL, );

+}
 if (FAILED(hr)) {
 av_log(ctx, AV_LOG_ERROR, "Could not create the texture 
(%lx)\n", (long)hr);

 return NULL;
@@ -278,6 +283,11 @@ static int d3d11va_frames_init(AVHWFramesContext *ctx)
 }
 } else if (!(texDesc.BindFlags & D3D11_BIND_RENDER_TARGET) && 
texDesc.ArraySize > 0) {
 hr = ID3D11Device_CreateTexture2D(device_hwctx->device, 
, NULL, >texture);
+if (FAILED(hr) && (texDesc.BindFlags & 
D3D11_BIND_SHADER_RESOURCE)) {
+av_log(ctx, AV_LOG_ERROR, "Could not create the texture 
with [D3D11_BIND_SHADER_RESOURCE] flag");

+texDesc.BindFlags &= ~D3D11_BIND_SHADER_RESOURCE;
+hr = ID3D11Device_CreateTexture2D(device_hwctx->device, 
, NULL, >texture);

+}
 if (FAILED(hr)) {
 av_log(ctx, AV_LOG_ERROR, "Could not create the texture 
(%lx)\n", (long)hr);

 return AVERROR_UNKNOWN;
--
2.35.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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] libavformat/mov: fix udta reading in trak box

2022-02-11 Thread Wang Chuan
On Feb 9, 2022, 7:31 AM +0800, Jan Ekström , wrote:
> On Tue, Feb 8, 2022 at 9:48 AM Wang Chuan  wrote:
> >
> > Any news?
> >
>
> Sorry, was not able to get to this according to the time line I
> expected. Will see if I can find some time for this soon.
>
> The attempt I had done in October was quite similar now that I look at
> it again 
> (https://github.com/jeeb/ffmpeg/commits/enable_writing_udta_metadata_for_tracks),
> although it seems like I missed c->trak_index , will have to check it
> :)
>
> Additionally, when I did the changes a lot of tests had to be updated
> as the test would expect the metadata in the main context, as
> previously the metadata only got applied globally. The changes in my
> commit aren't what's needed as I just committed the changes in test
> results to remind myself which tests would require additional changes
> or at least review.
>
> Looking at the patchwork side for this patch set, it seems like it
> wasn't able to run the tests for you, so you probably did not get any
> messages about failing tests?
> https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=5839
>
> For running tests locally, what I usually do is:
>
> 1. configure and build normally
> 2. `make fate-rsync SAMPLES=../../path/to/fate-suite`
> 3. `make fate SAMPLES=../../path/to/fate-suite`
>
> this is also documented at https://www.ffmpeg.org/fate.html .
Thanks for your reply!

I have tried running tests on my PC, but I didn’t meet any test failure...
But if I use your patch, the tests failed.

The difference between your patch and my is that you use [s->nb_streams - 1]
but I use [c->trak_index].
It seems like [c->trak_index] is a better choice.
(It seems like if we use [s->nb_streams - 1], the metadata we read will all go 
to the
last)
Can you check this again?

Thanks
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] libavformat/mov: fix udta reading in trak box

2022-02-07 Thread Wang Chuan

Any news?

On 2022/2/4 19:10, Jan Ekström wrote:

On Fri, Feb 4, 2022 at 5:24 AM Wang Chuan  wrote:

Ping?
On Jan 28, 2022, 11:24 AM +0800, Wang Chuan , wrote:

if we are reading udta in trak box, the data should go to metadata
of current stream.

Signed-off-by: Wang Chuan 
---
libavformat/mov.c | 5 -
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 1437d160f8..cb983defb3 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -522,7 +522,10 @@ retry:
str[str_size] = 0;
}
c->fc->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
- av_dict_set(>fc->metadata, key, str, 0);
+ if (c->trak_index != -1)
+ av_dict_set(>fc->streams[c->trak_index]->metadata, key,
str, 0);
+ else
+ av_dict_set(>fc->metadata, key, str, 0);
if (*language && strcmp(language, "und")) {
snprintf(key2, sizeof(key2), "%s-%s", key, language);
av_dict_set(>fc->metadata, key2, str, 0);
--
2.29.2

I recall having some patches on my github regarding something related,
will attempt to check this during the week-end.

Jan
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] libavformat/mov: fix udta reading in trak box

2022-02-03 Thread Wang Chuan
Ping?
On Jan 28, 2022, 11:24 AM +0800, Wang Chuan , wrote:
> if we are reading udta in trak box, the data should go to metadata
> of current stream.
>
> Signed-off-by: Wang Chuan 
> ---
> libavformat/mov.c | 5 -
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 1437d160f8..cb983defb3 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -522,7 +522,10 @@ retry:
> str[str_size] = 0;
> }
> c->fc->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
> - av_dict_set(>fc->metadata, key, str, 0);
> + if (c->trak_index != -1)
> + av_dict_set(>fc->streams[c->trak_index]->metadata, key,
> str, 0);
> + else
> + av_dict_set(>fc->metadata, key, str, 0);
> if (*language && strcmp(language, "und")) {
> snprintf(key2, sizeof(key2), "%s-%s", key, language);
> av_dict_set(>fc->metadata, key2, str, 0);
> --
> 2.29.2
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/2] libavformat/mov: fix udta reading in trak box

2022-01-27 Thread Wang Chuan

if we are reading udta in trak box, the data should go to metadata
of current stream.

Signed-off-by: Wang Chuan 
---
 libavformat/mov.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 1437d160f8..cb983defb3 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -522,7 +522,10 @@ retry:
 str[str_size] = 0;
 }
 c->fc->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
-av_dict_set(>fc->metadata, key, str, 0);
+if (c->trak_index != -1)
+av_dict_set(>fc->streams[c->trak_index]->metadata, key, 
str, 0);

+else
+av_dict_set(>fc->metadata, key, str, 0);
 if (*language && strcmp(language, "und")) {
 snprintf(key2, sizeof(key2), "%s-%s", key, language);
 av_dict_set(>fc->metadata, key2, str, 0);
--
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/2] avformat/movenc: fix type of 'Title of the content' in udta box

2022-01-27 Thread Wang Chuan

The type of 'Title of the content' should be "\xa9nam"(type begin with
\xa9 means the following text is defined to be international text) not
"name"(which means 'Name of object').
And when we try to decode mov header, we recognize "\xa9nam" as title
in mov_read_udta_string(mov.c)

Signed-off-by: Wang Chuan 
---
 libavformat/movenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 4c868919ae..c4dcb41fbb 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -3375,7 +3375,7 @@ static int mov_write_track_udta_tag(AVIOContext 
*pb, MOVMuxContext *mov,

 return ret;
  if (mov->mode & (MODE_MP4|MODE_MOV))
-mov_write_track_metadata(pb_buf, st, "name", "title");
+mov_write_track_metadata(pb_buf, st, "\xa9nam", "title");
  if (mov->mode & MODE_MP4) {
 if ((ret = mov_write_track_kinds(pb_buf, st)) < 0)
--
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avformat/aviobuf: let avio_read can retry when timeout

2022-01-13 Thread Wang Chuan

I just try to use avio to read stream by http protocol.

But if the server responds too late, avio_read will return timeout, and 
the only way I can do is close it and reopen.


Of course I can set a large timeout, but it's hard to decide which 
timeout value is large enough.


On 2022/1/14 11:21, "zhilizhao(赵志立)" wrote:



On Jan 14, 2022, at 10:42 AM, Wang Chuan  wrote:

If we meet timeout when reading network resource, avio_read will set
[eof_reached] to 1. And this prevent caller to retry since avio_read
do nothing and just return if eof_reached == 1.

If timeout was triggered by a small ‘timeout’ setting from user, just
change the ‘timeout' configuration. If it was triggered by a system call,
it’s likely to be in a state of not recoverable. Could you share more
details about the issue this patch trying to solve?


Signed-off-by: Wang Chuan 
---
libavformat/aviobuf.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 29d4bd7510..38cb21debf 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -580,8 +580,9 @@ static void fill_buffer(AVIOContext *s)
be done without rereading data */
 s->eof_reached = 1;
 } else if (len < 0) {
-s->eof_reached = 1;
-s->error= len;
+s->error = len;
+if (s->error != AVERROR(ETIMEDOUT))
+s->eof_reached = 1;
 } else {
 s->pos += len;
 s->buf_ptr = dst;
--
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] avformat/aviobuf: let avio_read can retry when timeout

2022-01-13 Thread Wang Chuan

If we meet timeout when reading network resource, avio_read will set
[eof_reached] to 1. And this prevent caller to retry since avio_read
do nothing and just return if eof_reached == 1.

Signed-off-by: Wang Chuan 
---
 libavformat/aviobuf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 29d4bd7510..38cb21debf 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -580,8 +580,9 @@ static void fill_buffer(AVIOContext *s)
be done without rereading data */
 s->eof_reached = 1;
 } else if (len < 0) {
-s->eof_reached = 1;
-s->error= len;
+s->error = len;
+if (s->error != AVERROR(ETIMEDOUT))
+s->eof_reached = 1;
 } else {
 s->pos += len;
 s->buf_ptr = dst;
--
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavcodec/videotoolbox: let VideoToolbox choose a decoder for us

2020-08-01 Thread Wang Chuan
If we fail to create a decoder specified by ourself, then try to
let VideoToolbox pick a proper one for us.

Signed-off-by: Wang Chuan 
---
 libavcodec/videotoolbox.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 8773de3393..9077647e25 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -837,6 +837,10 @@ static int videotoolbox_start(AVCodecContext *avctx)
   _cb,   // 
outputCallback
   >session);   // 
decompressionSessionOut
 
+// if we cannot create a decode session specified by ourself, then that 
videotoolbox pick one for us
+if (status == kVTVideoDecoderNotAvailableNowErr)
+status = VTDecompressionSessionCreate(NULL, videotoolbox->cm_fmt_desc, 
NULL, buf_attr, _cb, >session);
+
 if (decoder_spec)
 CFRelease(decoder_spec);
 if (buf_attr)
-- 
2.27.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".