Re: [FFmpeg-devel] [PATCH v10 0/6] Support enhanced flv in FFmpeg

2023-05-31 Thread Tristan Matthews
> you can publish hevc, av1 or vp9 codec stream to Youtube over rtmp.

Were you able to push av1 or vp9 to Youtube with this patchset alone?

Best,
-t

On Wed, May 31, 2023 at 8:03 PM Steven Liu  wrote:
>
> Neal Gompa  于2023年5月31日周三 13:47写道:
> >
> > On Mon, May 15, 2023 at 10:41 PM Neal Gompa  wrote:
> > >
> > > On Mon, May 15, 2023 at 4:32 AM Steven Liu  wrote:
> > > >
> > > > Reference file: 
> > > > https://github.com/veovera/enhanced-rtmp/blob/main/enhanced-rtmp-v1.pdf
> > > > The Enhanced flv has been supported by OBS, Simple Realtime Server, 
> > > > mpegts.js.
> > > > you can publish hevc, av1 or vp9 codec stream to Youtube over rtmp.
> > > > The enhanced flv documentation contributors include
> > > > Jean-Baptiste Kempf (FFmpeg, VideoLAN).
> > > > So this should be support by ffmpeg too.
> > > >
> > > > v8:
> > > > Support vp9 codec according to enhanced flv.
> > > > Support PacketTypeCodedFrames type for hevc in flv.
> > > > v9:
> > > > Add dependency codec object files for flvenc in Makefile.
> > > > Move the hevc,av1,vp9 codec out of FF_COMPLIANCE_UNOFFICIAL.
> > > >
> > > > v10:
> > > > modify first patch comment like the others before commit.
> > > > exheader mode should only happened in video stream this patchset.
> > > >
> > > > Steven Liu (6):
> > > >   avformat/flvenc: support mux hevc in enhanced flv
> > > >   avformat/flvdec: support demux hevc in enhanced flv
> > > >   avformat/flvenc: support mux av1 in enhanced flv
> > > >   avformat/flvdec: support demux av1 in enhanced flv
> > > >   avformat/flvenc: support mux vp9 in enhanced flv
> > > >   avformat/flvdec: support demux vp9 in enhanced flv
> > > >
> > > >  libavformat/Makefile |  2 +-
> > > >  libavformat/flv.h| 15 +
> > > >  libavformat/flvdec.c | 73 +++-
> > > >  libavformat/flvenc.c | 58 +--
> > > >  4 files changed, 130 insertions(+), 18 deletions(-)
> > > >
> > >
> > > This version works for me. Thanks for this work!
> > >
> > > Tested-by: Neal Gompa 
> > > Reviewed-by: Neal Gompa 
> > >
> >
> > Is this patch set going to get pushed to master anytime soon?
>
> Hi Neal,
>
> Waiting for j-b check about the Enhanced-FLV status, i cannot sure if
> this patch can be pushed now.
>
>
>
>
> Thanks
> Steven
> ___
> 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 1/2] avcodec/lcldec: Make PNG filter addressing match the code afterwards

2023-05-31 Thread James Almer




On 5/31/2023 9:26 PM, Michael Niedermayer wrote:

Also update check accordingly

Fixes: tickets/10237/mszh_306_306_yuv422_nocompress.avi
Fixes: tickets/10237/mszh_306_306_yuv411_nocompress.avi

Signed-off-by: Michael Niedermayer 
---
  libavcodec/lcldec.c | 9 ++---
  1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavcodec/lcldec.c b/libavcodec/lcldec.c
index ed78d9d570..1c93378c4c 100644
--- a/libavcodec/lcldec.c
+++ b/libavcodec/lcldec.c
@@ -231,16 +231,19 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
  break;
  case COMP_MSZH_NOCOMP: {
  int bppx2;
+int widtha = width;


nit: aligned_width is clearer, imo.


  switch (c->imgtype) {
  case IMGTYPE_YUV111:
  case IMGTYPE_RGB24:
  bppx2 = 6;
  break;
  case IMGTYPE_YUV422:
+widtha &= ~3;
  case IMGTYPE_YUV211:
  bppx2 = 4;
  break;
  case IMGTYPE_YUV411:
+widtha &= ~3;
  case IMGTYPE_YUV420:
  bppx2 = 3;
  break;
@@ -248,7 +251,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
  bppx2 = 0; // will error out below
  break;
  }
-if (len < ((width * height * bppx2) >> 1))
+if (len < ((widtha * height * bppx2) >> 1))
  return AVERROR_INVALIDDATA;
  break;
  }
@@ -314,8 +317,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
  }
  break;
  case IMGTYPE_YUV422:
+pixel_ptr = 0;
  for (row = 0; row < height; row++) {
-pixel_ptr = row * width * 2;
  yq = uq = vq =0;
  for (col = 0; col < width/4; col++) {
  encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
@@ -331,8 +334,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
  }
  break;
  case IMGTYPE_YUV411:
+pixel_ptr = 0;
  for (row = 0; row < height; row++) {
-pixel_ptr = row * width / 2 * 3;
  yq = uq = vq =0;
  for (col = 0; col < width/4; col++) {
  encoded[pixel_ptr] = yq -= encoded[pixel_ptr];

___
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] tools/target_dec_fuzzer: Adjust threshold for QPEG

2023-05-31 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
59332/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_QPEG_fuzzer-6292824736530432

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 tools/target_dec_fuzzer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
index d8e93f3a21..1dbdad50b6 100644
--- a/tools/target_dec_fuzzer.c
+++ b/tools/target_dec_fuzzer.c
@@ -268,6 +268,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t 
size) {
 case AV_CODEC_ID_OPUS:maxsamples /= 16384; break;
 case AV_CODEC_ID_PNG: maxpixels  /= 128;   break;
 case AV_CODEC_ID_APNG:maxpixels  /= 128;   break;
+case AV_CODEC_ID_QPEG:maxpixels  /= 128;   break;
 case AV_CODEC_ID_QTRLE:   maxpixels  /= 16;break;
 case AV_CODEC_ID_PAF_VIDEO:   maxpixels  /= 16;break;
 case AV_CODEC_ID_PRORES:  maxpixels  /= 256;   break;
-- 
2.17.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 1/2] avcodec/lcldec: Make PNG filter addressing match the code afterwards

2023-05-31 Thread Michael Niedermayer
Also update check accordingly

Fixes: tickets/10237/mszh_306_306_yuv422_nocompress.avi
Fixes: tickets/10237/mszh_306_306_yuv411_nocompress.avi

Signed-off-by: Michael Niedermayer 
---
 libavcodec/lcldec.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavcodec/lcldec.c b/libavcodec/lcldec.c
index ed78d9d570..1c93378c4c 100644
--- a/libavcodec/lcldec.c
+++ b/libavcodec/lcldec.c
@@ -231,16 +231,19 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 break;
 case COMP_MSZH_NOCOMP: {
 int bppx2;
+int widtha = width;
 switch (c->imgtype) {
 case IMGTYPE_YUV111:
 case IMGTYPE_RGB24:
 bppx2 = 6;
 break;
 case IMGTYPE_YUV422:
+widtha &= ~3;
 case IMGTYPE_YUV211:
 bppx2 = 4;
 break;
 case IMGTYPE_YUV411:
+widtha &= ~3;
 case IMGTYPE_YUV420:
 bppx2 = 3;
 break;
@@ -248,7 +251,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 bppx2 = 0; // will error out below
 break;
 }
-if (len < ((width * height * bppx2) >> 1))
+if (len < ((widtha * height * bppx2) >> 1))
 return AVERROR_INVALIDDATA;
 break;
 }
@@ -314,8 +317,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 }
 break;
 case IMGTYPE_YUV422:
+pixel_ptr = 0;
 for (row = 0; row < height; row++) {
-pixel_ptr = row * width * 2;
 yq = uq = vq =0;
 for (col = 0; col < width/4; col++) {
 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
@@ -331,8 +334,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 }
 break;
 case IMGTYPE_YUV411:
+pixel_ptr = 0;
 for (row = 0; row < height; row++) {
-pixel_ptr = row * width / 2 * 3;
 yq = uq = vq =0;
 for (col = 0; col < width/4; col++) {
 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
-- 
2.17.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 v10 0/6] Support enhanced flv in FFmpeg

2023-05-31 Thread Steven Liu
Neal Gompa  于2023年5月31日周三 13:47写道:
>
> On Mon, May 15, 2023 at 10:41 PM Neal Gompa  wrote:
> >
> > On Mon, May 15, 2023 at 4:32 AM Steven Liu  wrote:
> > >
> > > Reference file: 
> > > https://github.com/veovera/enhanced-rtmp/blob/main/enhanced-rtmp-v1.pdf
> > > The Enhanced flv has been supported by OBS, Simple Realtime Server, 
> > > mpegts.js.
> > > you can publish hevc, av1 or vp9 codec stream to Youtube over rtmp.
> > > The enhanced flv documentation contributors include
> > > Jean-Baptiste Kempf (FFmpeg, VideoLAN).
> > > So this should be support by ffmpeg too.
> > >
> > > v8:
> > > Support vp9 codec according to enhanced flv.
> > > Support PacketTypeCodedFrames type for hevc in flv.
> > > v9:
> > > Add dependency codec object files for flvenc in Makefile.
> > > Move the hevc,av1,vp9 codec out of FF_COMPLIANCE_UNOFFICIAL.
> > >
> > > v10:
> > > modify first patch comment like the others before commit.
> > > exheader mode should only happened in video stream this patchset.
> > >
> > > Steven Liu (6):
> > >   avformat/flvenc: support mux hevc in enhanced flv
> > >   avformat/flvdec: support demux hevc in enhanced flv
> > >   avformat/flvenc: support mux av1 in enhanced flv
> > >   avformat/flvdec: support demux av1 in enhanced flv
> > >   avformat/flvenc: support mux vp9 in enhanced flv
> > >   avformat/flvdec: support demux vp9 in enhanced flv
> > >
> > >  libavformat/Makefile |  2 +-
> > >  libavformat/flv.h| 15 +
> > >  libavformat/flvdec.c | 73 +++-
> > >  libavformat/flvenc.c | 58 +--
> > >  4 files changed, 130 insertions(+), 18 deletions(-)
> > >
> >
> > This version works for me. Thanks for this work!
> >
> > Tested-by: Neal Gompa 
> > Reviewed-by: Neal Gompa 
> >
>
> Is this patch set going to get pushed to master anytime soon?

Hi Neal,

Waiting for j-b check about the Enhanced-FLV status, i cannot sure if
this patch can be pushed now.




Thanks
Steven
___
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 19/23] fftools/ffmpeg: stop explicitly closing output streams on input EOF

2023-05-31 Thread Michael Niedermayer
On Wed, May 31, 2023 at 04:54:49PM +0200, Anton Khirnov wrote:
> Sending an empty packet already does that implicitly.
> ---
>  fftools/ffmpeg.c | 1 -
>  1 file changed, 1 deletion(-)

seems to infinite loop this:

ffmpeg -y -threads:a 1 -i 
/home/michael/tickets//1208/702121h264-TTA.mkvtest82.mkv -bitexact -vn 1208.mkv

file seems here: ffmpeg-bugs/trac/ticket1208/702121h264-TTA.mkvtest82.mkv

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato


signature.asc
Description: PGP signature
___
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 v2 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding

2023-05-31 Thread Michael Niedermayer
On Wed, May 31, 2023 at 11:07:15AM +0800, Tong Wu wrote:
> From: Wu Jianhua 
> 
> The implementation is based on:
> https://learn.microsoft.com/en-us/windows/win32/medfound/direct3d-12-video-overview
> 
> With the Direct3D 12 video decoding support, we can render or process
> the decoded images by the pixel shaders or compute shaders directly
> without the extra copy overhead, which is beneficial especially if you
> are trying to render or post-process a 4K or 8K video.
> 
> The command below is how to enable d3d12va:
> ffmpeg -hwaccel d3d12va -i input.mp4 output.mp4
> 
> Signed-off-by: Wu Jianhua 
> Signed-off-by: Tong Wu 
> ---
>  configure   |   2 +
>  libavcodec/Makefile |   3 +
>  libavcodec/d3d11va.h|   3 -
>  libavcodec/d3d12va.c| 552 
>  libavcodec/d3d12va.h| 184 
>  libavcodec/d3d12va_h264.c   | 210 ++
>  libavcodec/dxva2.c  |  24 ++
>  libavcodec/dxva2.h  |   3 -
>  libavcodec/dxva2_h264.c |  12 +-
>  libavcodec/dxva2_internal.h |  69 +++--
>  libavcodec/h264_slice.c |   4 +
>  libavcodec/h264dec.c|   3 +
>  libavcodec/hwaccels.h   |   1 +
>  libavcodec/hwconfig.h   |   2 +
>  14 files changed, 1030 insertions(+), 42 deletions(-)
>  create mode 100644 libavcodec/d3d12va.c
>  create mode 100644 libavcodec/d3d12va.h
>  create mode 100644 libavcodec/d3d12va_h264.c

seems to break build on mingw64 here
 make
CC  libavcodec/dxva2.o
In file included from src/libavcodec/dxva2.c:33:0:
src/libavcodec/dxva2.c: In function ‘ff_dxva2_get_surface_index’:
src/libavcodec/dxva2_internal.h:48:43: error: pasting "." and "surface_count" 
does not give a valid preprocessing token
 #define D3D11VA_VAR(ctx, var) ctx->d3d11va.##var
   ^
src/libavcodec/dxva2_internal.h:123:114: note: in expansion of macro 
‘D3D11VA_VAR’
 #define DXVA2_CONTEXT_VAR(avctx, ctx, var) (avctx->pix_fmt == AV_PIX_FMT_D3D12 
? 0 : (ff_dxva2_is_d3d11(avctx) ? D3D11VA_VAR(ctx, var) :  DXVA2_VAR(ctx, var)))

  ^~~
src/libavcodec/dxva2_internal.h:127:49: note: in expansion of macro 
‘DXVA2_CONTEXT_VAR’
 #define DXVA_CONTEXT_COUNT(avctx, ctx)  DXVA2_CONTEXT_VAR(avctx, ctx, 
surface_count)
 ^
src/libavcodec/dxva2.c:791:21: note: in expansion of macro ‘DXVA_CONTEXT_COUNT’
 for (i = 0; i < DXVA_CONTEXT_COUNT(avctx, ctx); i++) {
 ^
In file included from src/libavcodec/dxva2.c:33:0:
src/libavcodec/dxva2_internal.h:40:39: error: pasting "." and "surface_count" 
does not give a valid preprocessing token
 #define DXVA2_VAR(ctx, var) ctx->dxva2.##var
   ^
src/libavcodec/dxva2_internal.h:123:139: note: in expansion of macro ‘DXVA2_VAR’
 #define DXVA2_CONTEXT_VAR(avctx, ctx, var) (avctx->pix_fmt == AV_PIX_FMT_D3D12 
? 0 : (ff_dxva2_is_d3d11(avctx) ? D3D11VA_VAR(ctx, var) :  DXVA2_VAR(ctx, var)))

   ^
src/libavcodec/dxva2_internal.h:127:49: note: in expansion of macro 
‘DXVA2_CONTEXT_VAR’
 #define DXVA_CONTEXT_COUNT(avctx, ctx)  DXVA2_CONTEXT_VAR(avctx, ctx, 
surface_count)
 ^
src/libavcodec/dxva2.c:791:21: note: in expansion of macro ‘DXVA_CONTEXT_COUNT’
 for (i = 0; i < DXVA_CONTEXT_COUNT(avctx, ctx); i++) {
 ^
src/ffbuild/common.mak:81: recipe for target 'libavcodec/dxva2.o' failed
make: *** [libavcodec/dxva2.o] Error 1

[...]

--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

There will always be a question for which you do not know the correct answer.


signature.asc
Description: PGP signature
___
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/rtcenc: Add WHIP muxer support for subsecond latency streaming

2023-05-31 Thread Derek Buitenhuis
Hello, quick skim below, followe by some waffling at the end.

I have not bothere to mention any code style nits, to keep it technical.

On 5/29/2023 12:50 PM, Steven Liu wrote:
> @@ -3483,6 +3483,7 @@ ogg_demuxer_select="dirac_parse"
>  ogv_muxer_select="ogg_muxer"
>  opus_muxer_select="ogg_muxer"
>  psp_muxer_select="mov_muxer"
> +rtc_muxer_deps_any="openssl"

Given we support a bunch of SSL libraries, how exactly does this work with 
that? Can
it be abstracted out? OpenSSL poses licensing issues for many.

Further, I think this is missing a bunch of dependencies like HTTP and AVC?
> +#ifndef CONFIG_OPENSSL
> +#error "DTLS is not supported, please enable openssl"
> +#else
> +#include 
> +#include 
> +#if OPENSSL_VERSION_NUMBER < 0x1010102fL
> +#error "OpenSSL version 1.1.1b or newer is required"
> +#endif
> +#endif

This should be in configure.

> +/*
> + * Supported DTLS cipher suites for FFmpeg as a DTLS client.
> + * These cipher suites are used to negotiate with DTLS servers.
> + *
> + * It is advisable to use a limited number of cipher suites to reduce
> + * the size of DTLS UDP packets.
> + */
> +#define DTLS_CIPHER_SUTES "ECDHE-ECDSA-AES128-GCM-SHA256"\
> +":ECDHE-RSA-AES128-GCM-SHA256"\
> +":ECDHE-ECDSA-AES128-SHA"\
> +":ECDHE-RSA-AES128-SHA"\
> +":ECDHE-ECDSA-AES256-SHA"\
> +":ECDHE-RSA-AES256-SHA"

The reason for this specific subset should be documented.

> +/**
> + * STAP-A stands for Single-Time Aggregation Packet.
> + * The NALU type for STAP-A is 24 (0x18).
> + */
> +#define NALU_TYPE_STAP_A 24

Why is a NALU type being defined in a protocol implementation file?

> +/**
> + * Wait for a small timeout in milliseconds to allow for the server to 
> process
> + * the Interactive Connectivity Establishment (ICE) request. If we 
> immediately
> + * read the response after sending the request, we may receive nothing and 
> need
> + * to immediately retry. To lessen the likelihood of retries, we can send the
> + * request and wait for a small amount of time for the server to process it
> + * before reading the response.
> + */
> +#define ICE_PROCESSING_TIMEOUT 10

Are we really hardcoding sleeps? Surely a better way exists. What do other 
implementations
do here?

> +/**
> + * Wait for a short timeout in milliseconds to allow the server to process
> + * the Datagram Transport Layer Security (DTLS) request. If we immediately
> + * read the response after sending the request, we may receive nothing and
> + * need to immediately retry. To reduce the likelihood of retries, we can
> + * send the request and wait a short amount of time for the server to
> + * process it before attempting to read the response.
> + */
> +#define DTLS_PROCESSING_TIMEOUT 30

Same comment as above.

> +/**
> + * The maximum number of retries for Datagram Transport Layer Security 
> (DTLS) EAGAIN errors.
> + * When we send a DTLS request and receive no response, we may encounter an 
> EAGAIN error.
> + * In this situation, we wait briefly and attempt to read the response again.
> + * We limit the maximum number of times we retry this loop.
> + */
> +#define DTLS_EAGAIN_RETRIES_MAX 5

Should this be an option?

> +/**
> + * The DTLS timer's base timeout in microseconds. Its purpose is to minimize 
> the unnecessary
> + * retransmission of ClientHello.
> + */
> +#define DTLS_SSL_TIMER_BASE 400 * 1000

Is this from a spec or arbitrary?

> +typedef struct DTLSContext {
> +/* For av_log to write log to this category. */
> +void *log_avcl;

Why is this void *?

> +/**
> + * This represents the material used to build the SRTP master key. It is
> + * generated by DTLS and has the following layout:
> + *  16B 16B 14B 14B
> + *  client_key | server_key | client_salt | server_salt
> + */
> +uint8_t dtls_srtp_material[DTLS_SRTP_MASTER_KEY_LEN * 2];

*2?

> +/**
> + * Generate a self-signed certificate and private key for DTLS.
> + */

Does WHIP allow use of arbitrary certs (i.e. non-self-signed)?

> +static av_cold int dtls_context_init(DTLSContext *ctx)
> +{
> +int ret = 0, serial, expire_day, i, n = 0;
> +AVBPrint fingerprint;
> +unsigned char md[EVP_MAX_MD_SIZE];
> +const char *aor = "ffmpeg.org", *curve = NULL;

I am not sure the the FFmpeg community wants to advertise itself as a CN.

Mayb lavf?

> +curve = "prime256v1";

For this and all other occurrences: They should be intialized at declaration
time, like the rest of the codebase.

> +ctx->dtls_pkey = dtls_pkey = EVP_EC_gen(curve);
> +if (!dtls_pkey) {
> +av_log(s1, AV_LOG_ERROR, "DTLS: EVP_EC_gen curve=%s failed\n", 
> curve);

For this and all ther logs: Something more descriptive than "function_name 
failed:"
should be used.

> +serial = (int)av_get_random_seed();

For all uses of av_get_random_seed: Why are we using a seed and not a PRNG?

> +if (!av_bprint_is_complete()) {
> +av_log(s1, AV_LOG_ERROR, "Fingerprint %d exceed max 

Re: [FFmpeg-devel] [PATCH v2 3/5] aarch64: Add Linux runtime cpu feature detection using getauxval(AT_HWCAP)

2023-05-31 Thread Martin Storsjö

On Wed, 31 May 2023, Rémi Denis-Courmont wrote:


Le tiistaina 30. toukokuuta 2023, 15.30.41 EEST Martin Storsjö a écrit :

Based partially on code by Janne Grunau.

---
Updated to use both the direct HWCAP* macros and HWCAP_CPUID. A
not unreasonably old distribution like Ubuntu 20.04 does have
HWCAP_CPUID but not HWCAP2_I8MM in the distribution provided headers.

Alternatively I guess we could carry our own fallback hardcoded values
for the HWCAP* values we use and skip HWCAP_CPUID.
---
 configure   |  2 ++
 libavutil/aarch64/cpu.c | 63 +
 2 files changed, 65 insertions(+)

diff --git a/configure b/configure
index 50eb27ba0e..b39de74de5 100755
--- a/configure
+++ b/configure
@@ -2209,6 +2209,7 @@ HAVE_LIST_PUB="

 HEADERS_LIST="
 arpa_inet_h
+asm_hwcap_h
 asm_types_h
 cdio_paranoia_h
 cdio_paranoia_paranoia_h
@@ -6432,6 +6433,7 @@ check_headers io.h
 enabled libdrm &&
 check_headers linux/dma-buf.h

+check_headers asm/hwcap.h
 check_headers linux/perf_event.h
 check_headers libcrystalhd/libcrystalhd_if.h
 check_headers malloc.h
diff --git a/libavutil/aarch64/cpu.c b/libavutil/aarch64/cpu.c
index 0c76f5ad15..4563959ffd 100644
--- a/libavutil/aarch64/cpu.c
+++ b/libavutil/aarch64/cpu.c
@@ -20,6 +20,67 @@
 #include "libavutil/cpu_internal.h"
 #include "config.h"

+#if (defined(__linux__) || defined(__ANDROID__)) && HAVE_GETAUXVAL &&
HAVE_ASM_HWCAP_H +#include 
+#include 
+#include 
+
+#define get_cpu_feature_reg(reg, val) \
+__asm__("mrs %0, " #reg : "=r" (val))
+
+static int detect_flags(void)
+{
+int flags = 0;
+unsigned long hwcap, hwcap2;
+
+// Check for support using direct individual HWCAPs
+hwcap = getauxval(AT_HWCAP);
+#ifdef HWCAP_ASIMDDP
+if (hwcap & HWCAP_ASIMDDP)
+flags |= AV_CPU_FLAG_DOTPROD;
+#endif
+
+#ifdef AT_HWCAP2
+hwcap2 = getauxval(AT_HWCAP2);
+#ifdef HWCAP2_I8MM
+if (hwcap2 & HWCAP2_I8MM)
+flags |= AV_CPU_FLAG_I8MM;
+#endif
+#endif
+
+// Silence warnings if none of the hwcaps to check are known.
+(void)hwcap;
+(void)hwcap2;
+
+#if defined(HWCAP_CPUID)
+// The HWCAP_* defines for individual extensions may become available
late, as
+// they require updates to userland headers. As a fallback, see if we 

can access

+// the CPUID registers (trapped via the kernel).
+// See 
https://www.kernel.org/doc/html/latest/arm64/cpu-feature-registers.html


I don't actually care which method is used and whether to hard-code the 
missing constants or not. But doing both methods is weird. If you are going to 
trigger the TID3 traps anyway, there is no point checking the auxillary 
vectors before, AFAICT.


Yeah, that's true.

You *could* check the auxillary vectors as a run-time fallback if HWCAP_CPUID 
is *not* set, but that only really makes for HWCAP_FP and HWCAP_ASIMD, not for 
HWCAP_ASIMDDP (Linux 4.15) and HWCAP2_I8MM (Linux 5.6) which are more recent 
than HWCAP_CPUID (Linux 4.11). And then, that would be only in the corner case 
that FP and/or AdvSIMD were explicitly disabled since they are on by default 
for all AArch64 targets.


Yeah - I guess there's no potential configuration where a kernel does know 
about HWCAP_CPUID and newer HWCAPs but has decided to set HWCAP_CPUID to 0 
and not handle the trapping?


I considered falling back on the trapping CPUID codepath only if the 
individual HWCAPs weren't detected/supported, but that soon becomes quite 
a mess if we're adding more than a couple extensions.


So I guess after all that it's simplest to just go with CPUID, possibly 
with a code comment that we could go with individual HWCAPs at some point 
in the future if we want to simplify things and don't care about older 
systems/toolchains.


// Martin
___
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] Web/Index: add post for new Vulkan decoding support

2023-05-31 Thread Lynne
May 31, 2023, 19:59 by phil...@overt.org:

> On Wed, 31 May 2023 19:55:19 +0200 (CEST)
> Lynne  wrote:
>
>> +  May 31st, 2023, Vulkan decoding
>> +  
>> +    Recently, Vulkan-powered decoding hardware acceleration code was
>> merged into the codebase.
>> +    This is the first vendor-generic and platform-generic decode
>> acceleration API, enabling the
>> +    same code to be used on multiple platforms, with very minimal
>> overhead.
>> +    This is also the first multi-threaded hardware decoding API, and
>> our code makes full use of this,
>> +    saturating all available decode engines the hardware exposes.
>> +  
>> +  
>> +    Those wishing to test the code can consult our
>> +    > href="https://trac.ffmpeg.org/wiki/HWAccelIntro#Vulkan;>documentation
>> page.
>> +    For those who would like to integrate FFmpeg's Vulkan code to
>> demux, parse, decode, and receive
>> +    a VkImage to present or manipulate, documentation and examples
>> are available in our source tree.
>> +  
>> +  
>> +    As this is also the first practical implementation of the
>> specifications, bugs may be present,
>> +    particularly in drivers, and, although passing verification, the
>> implementation itself.
>> +  
>>
>> Patch attached.
>>
>
> LGTM
>

Pushed, 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 1/3] doc/examples/transcode: set packet timebase for decoding

2023-05-31 Thread James Almer

On 5/31/2023 12:32 PM, Anton Khirnov wrote:

It is recommended for callers to set it, though not required.


Add this comment to the file. It's meant to be an example for library 
users to refer to for their implementations, after all.



---
  doc/examples/transcode.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 805a028ed7..7110816fe6 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -97,6 +97,9 @@ static int open_input_file(const char *filename)
 "for stream #%u\n", i);
  return ret;
  }
+
+codec_ctx->pkt_timebase = stream->time_base;
+
  /* Reencode video & audio and remux subtitles etc. */
  if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO
  || codec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {

___
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] Web/Index: add post for new Vulkan decoding support

2023-05-31 Thread Philip Langdale
On Wed, 31 May 2023 19:55:19 +0200 (CEST)
Lynne  wrote:

> +  May 31st, 2023, Vulkan decoding
> +  
> +    Recently, Vulkan-powered decoding hardware acceleration code was
> merged into the codebase.
> +    This is the first vendor-generic and platform-generic decode
> acceleration API, enabling the
> +    same code to be used on multiple platforms, with very minimal
> overhead.
> +    This is also the first multi-threaded hardware decoding API, and
> our code makes full use of this,
> +    saturating all available decode engines the hardware exposes.
> +  
> +  
> +    Those wishing to test the code can consult our
> +     href="https://trac.ffmpeg.org/wiki/HWAccelIntro#Vulkan;>documentation
> page.
> +    For those who would like to integrate FFmpeg's Vulkan code to
> demux, parse, decode, and receive
> +    a VkImage to present or manipulate, documentation and examples
> are available in our source tree.
> +  
> +  
> +    As this is also the first practical implementation of the
> specifications, bugs may be present,
> +    particularly in drivers, and, although passing verification, the
> implementation itself.
> +  
> 
> Patch attached.
> 

LGTM


--phil
___
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] Web/Index: add post for new Vulkan decoding support

2023-05-31 Thread Lynne
+  May 31st, 2023, Vulkan decoding
+  
+    Recently, Vulkan-powered decoding hardware acceleration code was merged 
into the codebase.
+    This is the first vendor-generic and platform-generic decode acceleration 
API, enabling the
+    same code to be used on multiple platforms, with very minimal overhead.
+    This is also the first multi-threaded hardware decoding API, and our code 
makes full use of this,
+    saturating all available decode engines the hardware exposes.
+  
+  
+    Those wishing to test the code can consult our
+    https://trac.ffmpeg.org/wiki/HWAccelIntro#Vulkan;>documentation 
page.
+    For those who would like to integrate FFmpeg's Vulkan code to demux, 
parse, decode, and receive
+    a VkImage to present or manipulate, documentation and examples are 
available in our source tree.
+  
+  
+    As this is also the first practical implementation of the specifications, 
bugs may be present,
+    particularly in drivers, and, although passing verification, the 
implementation itself.
+  

Patch attached.

>From 0709836e8a41e22aede7bd0f033a746b8b5b05bd Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Wed, 31 May 2023 19:46:16 +0200
Subject: [PATCH] Index: add post for new Vulkan decoding support

Requested by Khronos. I don't really care, but w/e.
---
 src/index | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/src/index b/src/index
index 4e6498a..95a9ec8 100644
--- a/src/index
+++ b/src/index
@@ -35,6 +35,25 @@
 News
   
 
+  May 31st, 2023, Vulkan decoding
+  
+Recently, Vulkan-powered decoding hardware acceleration code was merged into the codebase.
+This is the first vendor-generic and platform-generic decode acceleration API, enabling the
+same code to be used on multiple platforms, with very minimal overhead.
+This is also the first multi-threaded hardware decoding API, and our code makes full use of this,
+saturating all available decode engines the hardware exposes.
+  
+  
+Those wishing to test the code can consult our
+https://trac.ffmpeg.org/wiki/HWAccelIntro#Vulkan;>documentation page.
+For those who would like to integrate FFmpeg's Vulkan code to demux, parse, decode, and receive
+a VkImage to present or manipulate, documentation and examples are available in our source tree.
+  
+  
+As this is also the first practical implementation of the specifications, bugs may be present,
+particularly in drivers, and, although passing verification, the implementation itself.
+  
+
   February 28th, 2023, FFmpeg 6.0 "Von Neumann"
   
 A new major release, FFmpeg 6.0 "Von Neumann",
-- 
2.40.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] fftools/ffmpeg: rework setting sub2video parameters

2023-05-31 Thread Michael Niedermayer
On Mon, May 29, 2023 at 02:49:55PM +0200, Anton Khirnov wrote:
> Set them in ifilter_parameters_from_dec(), similarly to audio/video
> streams. This reduces the extent to which sub2video filters need to be
> treated specially.
> ---
> You can also get the updated tree from ffmpeg_sub2video in my repo
> ---
>  fftools/ffmpeg.c|  6 ++---
>  fftools/ffmpeg_demux.c  | 21 +++
>  fftools/ffmpeg_filter.c | 58 -
>  3 files changed, 41 insertions(+), 44 deletions(-)

breaks (looks like wrong width/height) after the change from ffmpeg_sub2video
corresponding to this patch

 ./ffmpeg -i ~/tickets/4752/dump_dvbsubtitles.mp4 -y  -ss 5 -t 1 
-filter_complex '[0:v][0:s]overlay' /tmp/file4752.ts && ffplay /tmp/file4752.ts

seems to be in ffmpeg-bugs/trac/ticket4752/dump_dvbsubtitles.mp4

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire


signature.asc
Description: PGP signature
___
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 v2 3/5] aarch64: Add Linux runtime cpu feature detection using getauxval(AT_HWCAP)

2023-05-31 Thread Rémi Denis-Courmont
Le tiistaina 30. toukokuuta 2023, 15.30.41 EEST Martin Storsjö a écrit :
> Based partially on code by Janne Grunau.
> 
> ---
> Updated to use both the direct HWCAP* macros and HWCAP_CPUID. A
> not unreasonably old distribution like Ubuntu 20.04 does have
> HWCAP_CPUID but not HWCAP2_I8MM in the distribution provided headers.
> 
> Alternatively I guess we could carry our own fallback hardcoded values
> for the HWCAP* values we use and skip HWCAP_CPUID.
> ---
>  configure   |  2 ++
>  libavutil/aarch64/cpu.c | 63 +
>  2 files changed, 65 insertions(+)
> 
> diff --git a/configure b/configure
> index 50eb27ba0e..b39de74de5 100755
> --- a/configure
> +++ b/configure
> @@ -2209,6 +2209,7 @@ HAVE_LIST_PUB="
> 
>  HEADERS_LIST="
>  arpa_inet_h
> +asm_hwcap_h
>  asm_types_h
>  cdio_paranoia_h
>  cdio_paranoia_paranoia_h
> @@ -6432,6 +6433,7 @@ check_headers io.h
>  enabled libdrm &&
>  check_headers linux/dma-buf.h
> 
> +check_headers asm/hwcap.h
>  check_headers linux/perf_event.h
>  check_headers libcrystalhd/libcrystalhd_if.h
>  check_headers malloc.h
> diff --git a/libavutil/aarch64/cpu.c b/libavutil/aarch64/cpu.c
> index 0c76f5ad15..4563959ffd 100644
> --- a/libavutil/aarch64/cpu.c
> +++ b/libavutil/aarch64/cpu.c
> @@ -20,6 +20,67 @@
>  #include "libavutil/cpu_internal.h"
>  #include "config.h"
> 
> +#if (defined(__linux__) || defined(__ANDROID__)) && HAVE_GETAUXVAL &&
> HAVE_ASM_HWCAP_H +#include 
> +#include 
> +#include 
> +
> +#define get_cpu_feature_reg(reg, val) \
> +__asm__("mrs %0, " #reg : "=r" (val))
> +
> +static int detect_flags(void)
> +{
> +int flags = 0;
> +unsigned long hwcap, hwcap2;
> +
> +// Check for support using direct individual HWCAPs
> +hwcap = getauxval(AT_HWCAP);
> +#ifdef HWCAP_ASIMDDP
> +if (hwcap & HWCAP_ASIMDDP)
> +flags |= AV_CPU_FLAG_DOTPROD;
> +#endif
> +
> +#ifdef AT_HWCAP2
> +hwcap2 = getauxval(AT_HWCAP2);
> +#ifdef HWCAP2_I8MM
> +if (hwcap2 & HWCAP2_I8MM)
> +flags |= AV_CPU_FLAG_I8MM;
> +#endif
> +#endif
> +
> +// Silence warnings if none of the hwcaps to check are known.
> +(void)hwcap;
> +(void)hwcap2;
> +
> +#if defined(HWCAP_CPUID)
> +// The HWCAP_* defines for individual extensions may become available
> late, as
> +// they require updates to userland headers. As a fallback, see if we 
can access
> +// the CPUID registers (trapped via the kernel).
> +// See 
> https://www.kernel.org/doc/html/latest/arm64/cpu-feature-registers.html

I don't actually care which method is used and whether to hard-code the 
missing constants or not. But doing both methods is weird. If you are going to 
trigger the TID3 traps anyway, there is no point checking the auxillary 
vectors before, AFAICT.

You *could* check the auxillary vectors as a run-time fallback if HWCAP_CPUID 
is *not* set, but that only really makes for HWCAP_FP and HWCAP_ASIMD, not for 
HWCAP_ASIMDDP (Linux 4.15) and HWCAP2_I8MM (Linux 5.6) which are more recent 
than HWCAP_CPUID (Linux 4.11). And then, that would be only in the corner case 
that FP and/or AdvSIMD were explicitly disabled since they are on by default 
for all AArch64 targets.

-- 
Реми Дёни-Курмон
http://www.remlab.net/



___
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 1/4] configure: aarch64: Support assembling the dotprod and i8mm arch extensions

2023-05-31 Thread Rémi Denis-Courmont
Le tiistaina 30. toukokuuta 2023, 15.25.25 EEST Martin Storsjö a écrit :
> On Sun, 28 May 2023, Rémi Denis-Courmont wrote:
> > Le sunnuntaina 28. toukokuuta 2023, 0.34.15 EEST Martin Storsjö a écrit :
> >> I guess the alternative would be to just try to set .arch
> >> . I was worried that support for
> >> e.g. armv8.6-a appeared later in toolchains than support for the
> >> individual extension i8mm, but at least from a quick browse in binutils
> >> history, they seem to have been added at the same time, so there's
> >> probably no such drawback.
> >> 
> >> Or what's the situation with e.g. SVE2 - was ".arch_extension sve2"
> >> supported significantly earlier than ".arch armv9-a"?
> > 
> > I have not tested SVE on LLVM. AFAIK, SVE and SVE2 are optional from 8.2
> > and 9.0 onward respectively, and not mandatory in any version, so if your
> > toolchain supports neither .arch with plus sign, nor .arch_extension, it
> > is game over.
> 
> I didn't meant specifically whether LLVM supports it here, just in general
> wrt binutils and how to enable the feature.
> 
> FWIW it seems like SVE2 is a mandatory part of 9.0

Yes and no. SVE requires ARMv8.2, and SVE2 requires ARMv9.0, but neither are 
ever required by any existing ARM version. DDI0487 is abundantly clear that 
SVE2 is OPTIONAL: "[The Scalable Vector Extension version 2 (SVE2)] feature is 
supported in AArch64 state only. This feature is OPTIONAL in an Armv9.0 
implementation,"

However it adds that "standard Armv9-A software platforms support FEAT_SVE2."

> - assembling SVE2 instructions can be done with ".arch armv9-a".

Presumably binutils targets "standard Armv9-A software platforms" by default, 
as opposed to just any "Armv9.0 implementation". I guess that means that any 
Cortex, Neoverse or other proper ARM design will include SVE2, but big-ass 
architecture licensees such as APPL and NVDA are not required to include SVE2 
in their own designs.

> But there are about 2 years
> worth of deployed binutils based toolchains that do recognize ".arch
> armv8.2-a; .arch_extension sve2" but don't recognize ".arch armv9-a".

This is not entirely surprising, since SVE is much older than ARMv9, even if 
SVE2 requires ARMv9.

-- 
レミ・デニ-クールモン
http://www.remlab.net/



___
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 3/3] doc/examples/transcode: convert timestamps between filtering and encoding

2023-05-31 Thread Paul B Mahol
LGTM
___
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/3] doc/examples/transcode: stop using decoder's AVCodecContext.time_base

2023-05-31 Thread Paul B Mahol
LGTM
___
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 1/3] doc/examples/transcode: set packet timebase for decoding

2023-05-31 Thread Paul B Mahol
LGTM
___
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 3/3] doc/examples/transcode: convert timestamps between filtering and encoding

2023-05-31 Thread Anton Khirnov
The timebases do not have to match.
---
 doc/examples/transcode.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 2e1491f432..ebe5ad2a42 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -439,6 +439,10 @@ static int encode_write_frame(unsigned int stream_index, 
int flush)
 /* encode filtered frame */
 av_packet_unref(enc_pkt);
 
+if (filt_frame && filt_frame->pts != AV_NOPTS_VALUE)
+filt_frame->pts = av_rescale_q(filt_frame->pts, filt_frame->time_base,
+   stream->enc_ctx->time_base);
+
 ret = avcodec_send_frame(stream->enc_ctx, filt_frame);
 
 if (ret < 0)
@@ -493,6 +497,7 @@ static int filter_encode_write_frame(AVFrame *frame, 
unsigned int stream_index)
 break;
 }
 
+filter->filtered_frame->time_base = 
av_buffersink_get_time_base(filter->buffersink_ctx);;
 filter->filtered_frame->pict_type = AV_PICTURE_TYPE_NONE;
 ret = encode_write_frame(stream_index, 0);
 av_frame_unref(filter->filtered_frame);
-- 
2.40.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 1/3] doc/examples/transcode: set packet timebase for decoding

2023-05-31 Thread Anton Khirnov
It is recommended for callers to set it, though not required.
---
 doc/examples/transcode.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 805a028ed7..7110816fe6 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -97,6 +97,9 @@ static int open_input_file(const char *filename)
"for stream #%u\n", i);
 return ret;
 }
+
+codec_ctx->pkt_timebase = stream->time_base;
+
 /* Reencode video & audio and remux subtitles etc. */
 if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO
 || codec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
-- 
2.40.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 2/3] doc/examples/transcode: stop using decoder's AVCodecContext.time_base

2023-05-31 Thread Anton Khirnov
The contents of this field are not defined for decoding. Use
pkt_timebase, which is the timebase of demuxed packets.

Drop a tautological av_packet_rescale_ts() call, as the stream and
decoder timebases are the same.
---
 doc/examples/transcode.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 7110816fe6..2e1491f432 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -269,7 +269,7 @@ static int init_filter(FilteringContext* fctx, 
AVCodecContext *dec_ctx,
 snprintf(args, sizeof(args),
 
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
 dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
-dec_ctx->time_base.num, dec_ctx->time_base.den,
+dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den,
 dec_ctx->sample_aspect_ratio.num,
 dec_ctx->sample_aspect_ratio.den);
 
@@ -309,7 +309,7 @@ static int init_filter(FilteringContext* fctx, 
AVCodecContext *dec_ctx,
 av_channel_layout_describe(_ctx->ch_layout, buf, sizeof(buf));
 snprintf(args, sizeof(args),
 
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=%s",
-dec_ctx->time_base.num, dec_ctx->time_base.den, 
dec_ctx->sample_rate,
+dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den, 
dec_ctx->sample_rate,
 av_get_sample_fmt_name(dec_ctx->sample_fmt),
 buf);
 ret = avfilter_graph_create_filter(_ctx, buffersrc, "in",
@@ -547,9 +547,6 @@ int main(int argc, char **argv)
 
 av_log(NULL, AV_LOG_DEBUG, "Going to reencode the frame\n");
 
-av_packet_rescale_ts(packet,
- ifmt_ctx->streams[stream_index]->time_base,
- stream->dec_ctx->time_base);
 ret = avcodec_send_packet(stream->dec_ctx, packet);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Decoding failed\n");
-- 
2.40.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 12/23] fftools/ffmpeg_enc: do not guess frame durations from output framerate

2023-05-31 Thread Paul B Mahol
approved
___
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 21/23] fftools/ffmpeg_mux: simplify calling of_output_packet()

2023-05-31 Thread Anton Khirnov
Use NULL packets to signal EOF instead of a separate variable. This is
made possible by the previous commit.
---
 fftools/ffmpeg.c |  2 +-
 fftools/ffmpeg.h | 13 +
 fftools/ffmpeg_enc.c |  6 +++---
 fftools/ffmpeg_mux.c | 14 +++---
 4 files changed, 12 insertions(+), 23 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 462365ed02..79baceb1fc 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1104,7 +1104,7 @@ static int process_input(int file_index)
 for (int oidx = 0; oidx < ist->nb_outputs; oidx++) {
 OutputStream *ost = ist->outputs[oidx];
 OutputFile*of = output_files[ost->file_index];
-of_output_packet(of, ost->pkt, ost, 1);
+of_output_packet(of, ost, NULL);
 }
 }
 
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 49c07ede95..890081edb4 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -844,18 +844,7 @@ void of_close(OutputFile **pof);
 
 void of_enc_stats_close(void);
 
-/*
- * Send a single packet to the output, applying any bitstream filters
- * associated with the output stream.  This may result in any number
- * of packets actually being written, depending on what bitstream
- * filters are applied.  The supplied packet is consumed and will be
- * blank (as if newly-allocated) when this function returns.
- *
- * If eof is set, instead indicate EOF to all bitstream filters and
- * therefore flush any delayed packets to the output.  A blank packet
- * must be supplied in this case.
- */
-void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int 
eof);
+void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt);
 
 /**
  * @param dts predicted packet dts in AV_TIME_BASE_Q
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 1515ca971f..8dd8104cea 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -531,7 +531,7 @@ void enc_subtitle(OutputFile *of, OutputStream *ost, 
AVSubtitle *sub)
 }
 pkt->dts = pkt->pts;
 
-of_output_packet(of, pkt, ost, 0);
+of_output_packet(of, ost, pkt);
 }
 }
 
@@ -718,7 +718,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, 
AVFrame *frame)
 av_assert0(frame); // should never happen during flushing
 return 0;
 } else if (ret == AVERROR_EOF) {
-of_output_packet(of, pkt, ost, 1);
+of_output_packet(of, ost, NULL);
 return ret;
 } else if (ret < 0) {
 av_log(ost, AV_LOG_ERROR, "%s encoding failed\n", type_desc);
@@ -752,7 +752,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, 
AVFrame *frame)
 
 e->packets_encoded++;
 
-of_output_packet(of, pkt, ost, 0);
+of_output_packet(of, ost, pkt);
 }
 
 av_assert0(0);
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 485f499971..879a291ba9 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -324,18 +324,18 @@ static int submit_packet(Muxer *mux, AVPacket *pkt, 
OutputStream *ost)
 return 0;
 }
 
-void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int 
eof)
+void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
 {
 Muxer *mux = mux_from_of(of);
 MuxStream *ms = ms_from_ost(ost);
 const char *err_msg;
 int ret = 0;
 
-if (!eof && pkt->dts != AV_NOPTS_VALUE)
+if (pkt && pkt->dts != AV_NOPTS_VALUE)
 ost->last_mux_dts = av_rescale_q(pkt->dts, pkt->time_base, 
AV_TIME_BASE_Q);
 
 /* rescale timestamps to the muxing timebase */
-if (!eof) {
+if (pkt) {
 av_packet_rescale_ts(pkt, pkt->time_base, ost->mux_timebase);
 pkt->time_base = ost->mux_timebase;
 }
@@ -344,7 +344,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int eof)
 if (ms->bsf_ctx) {
 int bsf_eof = 0;
 
-ret = av_bsf_send_packet(ms->bsf_ctx, eof ? NULL : pkt);
+ret = av_bsf_send_packet(ms->bsf_ctx, pkt);
 if (ret < 0) {
 err_msg = "submitting a packet for bitstream filtering";
 goto fail;
@@ -366,7 +366,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int eof)
 goto mux_fail;
 }
 } else {
-ret = submit_packet(mux, eof ? NULL : pkt, ost);
+ret = submit_packet(mux, pkt, ost);
 if (ret < 0)
 goto mux_fail;
 }
@@ -399,7 +399,7 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, 
int64_t dts)
 
 // EOF: flush output bitstream filters.
 if (!pkt) {
-of_output_packet(of, opkt, ost, 1);
+of_output_packet(of, ost, NULL);
 return;
 }
 
@@ -453,7 +453,7 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, 
int64_t dts)
 }
 }
 
-of_output_packet(of, opkt, ost, 0);
+of_output_packet(of, ost, opkt);
 
 

[FFmpeg-devel] [PATCH 04/23] fftools/ffmpeg_filter: drop a block disabled since 2012

2023-05-31 Thread Anton Khirnov
---
 fftools/ffmpeg_filter.c | 20 
 1 file changed, 20 deletions(-)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 287b1e6f9d..1150f6fc65 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1075,26 +1075,6 @@ static int configure_output_video_filter(FilterGraph 
*fg, OutputFilter *ofilter,
 pad_idx = 0;
 }
 
-if (ost->frame_rate.num && 0) {
-AVFilterContext *fps;
-char args[255];
-
-snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num,
- ost->frame_rate.den);
-snprintf(name, sizeof(name), "fps_out_%d_%d",
- ost->file_index, ost->index);
-ret = avfilter_graph_create_filter(, avfilter_get_by_name("fps"),
-   name, args, NULL, fg->graph);
-if (ret < 0)
-return ret;
-
-ret = avfilter_link(last_filter, pad_idx, fps, 0);
-if (ret < 0)
-return ret;
-last_filter = fps;
-pad_idx = 0;
-}
-
 snprintf(name, sizeof(name), "trim_out_%d_%d",
  ost->file_index, ost->index);
 ret = insert_trim(of->start_time, of->recording_time,
-- 
2.40.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 23/23] fftools/ffmpeg_mux: make OutputStream.pkt private

2023-05-31 Thread Anton Khirnov
It is no longer used outside of muxing code.
---
 fftools/ffmpeg.h  | 1 -
 fftools/ffmpeg_mux.c  | 4 ++--
 fftools/ffmpeg_mux.h  | 2 ++
 fftools/ffmpeg_mux_init.c | 4 ++--
 4 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 890081edb4..88e3516243 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -551,7 +551,6 @@ typedef struct OutputStream {
 
 Encoder *enc;
 AVCodecContext *enc_ctx;
-AVPacket *pkt;
 
 uint64_t nb_frames_dup;
 uint64_t nb_frames_drop;
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 879a291ba9..66b2324bb3 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -389,7 +389,7 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, 
int64_t dts)
 MuxStream  *ms = ms_from_ost(ost);
 int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : 
of->start_time;
 int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, 
ost->mux_timebase);
-AVPacket *opkt = ost->pkt;
+AVPacket *opkt = ms->pkt;
 
 av_packet_unref(opkt);
 
@@ -862,7 +862,7 @@ static void ost_free(OutputStream **post)
 av_bsf_free(>bsf_ctx);
 av_packet_free(>bsf_pkt);
 
-av_packet_free(>pkt);
+av_packet_free(>pkt);
 av_dict_free(>encoder_opts);
 
 av_freep(>kf.pts);
diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h
index ad7b1df8a7..7f34b86548 100644
--- a/fftools/ffmpeg_mux.h
+++ b/fftools/ffmpeg_mux.h
@@ -46,6 +46,8 @@ typedef struct MuxStream {
 AVBSFContext *bsf_ctx;
 AVPacket *bsf_pkt;
 
+AVPacket *pkt;
+
 EncStats stats;
 
 int64_t max_frames;
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index c49f906dc7..a18320fa9b 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1064,8 +1064,8 @@ static OutputStream *ost_add(Muxer *mux, const 
OptionsContext *o,
 else av_assert0(0);
 av_log(ost, AV_LOG_VERBOSE, "\n");
 
-ost->pkt = av_packet_alloc();
-if (!ost->pkt)
+ms->pkt = av_packet_alloc();
+if (!ms->pkt)
 report_and_exit(AVERROR(ENOMEM));
 
 if (ost->enc_ctx) {
-- 
2.40.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 05/23] fftools/ffmpeg_demux: do not set AVCodecContext.framerate

2023-05-31 Thread Anton Khirnov
For decoding, this field is used by the decoder to export information
to the caller; it does not make sense for the caller to set it.
---
 fftools/ffmpeg_demux.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 5c15b8bad3..5e5f106368 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1194,9 +1194,6 @@ static void add_input_streams(const OptionsContext *o, 
Demuxer *d)
 
 switch (par->codec_type) {
 case AVMEDIA_TYPE_VIDEO:
-// avformat_find_stream_info() doesn't set this for us anymore.
-ist->dec_ctx->framerate = st->avg_frame_rate;
-
 MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
 if (framerate && av_parse_video_rate(>framerate,
  framerate) < 0) {
-- 
2.40.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 20/23] fftools/ffmpeg_mux: use a dedicated packet for BSF output

2023-05-31 Thread Anton Khirnov
Currently of_output_packet() reuses the input packet, which requires its
callers to submit blank packets even on EOF, which makes the code more
complex.
---
 fftools/ffmpeg_mux.c | 9 +++--
 fftools/ffmpeg_mux.h | 1 +
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index dc2d189ff0..485f499971 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -351,7 +351,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int eof)
 }
 
 while (!bsf_eof) {
-ret = av_bsf_receive_packet(ms->bsf_ctx, pkt);
+ret = av_bsf_receive_packet(ms->bsf_ctx, ms->bsf_pkt);
 if (ret == AVERROR(EAGAIN))
 return;
 else if (ret == AVERROR_EOF)
@@ -361,7 +361,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int eof)
 goto fail;
 }
 
-ret = submit_packet(mux, bsf_eof ? NULL : pkt, ost);
+ret = submit_packet(mux, bsf_eof ? NULL : ms->bsf_pkt, ost);
 if (ret < 0)
 goto mux_fail;
 }
@@ -656,6 +656,10 @@ static int bsf_init(MuxStream *ms)
 return ret;
 ost->st->time_base = ctx->time_base_out;
 
+ms->bsf_pkt = av_packet_alloc();
+if (!ms->bsf_pkt)
+return AVERROR(ENOMEM);
+
 return 0;
 }
 
@@ -856,6 +860,7 @@ static void ost_free(OutputStream **post)
 avcodec_parameters_free(>par_in);
 
 av_bsf_free(>bsf_ctx);
+av_packet_free(>bsf_pkt);
 
 av_packet_free(>pkt);
 av_dict_free(>encoder_opts);
diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h
index bee7addd6a..ad7b1df8a7 100644
--- a/fftools/ffmpeg_mux.h
+++ b/fftools/ffmpeg_mux.h
@@ -44,6 +44,7 @@ typedef struct MuxStream {
 AVFifo *muxing_queue;
 
 AVBSFContext *bsf_ctx;
+AVPacket *bsf_pkt;
 
 EncStats stats;
 
-- 
2.40.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 18/23] fftools/ffmpeg: simplify handling input -t for streamcopy

2023-05-31 Thread Anton Khirnov
Output stream will be closed implicitly after a NULL packet is sent to
it, there is no need to explicitly call close_output_stream().
---
 fftools/ffmpeg.c | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 9997881572..7d2a25f2bf 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -785,7 +785,6 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 int64_t dts_est = AV_NOPTS_VALUE;
 int ret = 0;
 int eof_reached = 0;
-int duration_exceeded;
 
 if (ist->decoding_needed)
 ret = dec_packet(ist, pkt, no_eof);
@@ -797,7 +796,6 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 dts_est = pd->dts_est;
 }
 
-duration_exceeded = 0;
 if (f->recording_time != INT64_MAX) {
 int64_t start_time = 0;
 if (copy_ts) {
@@ -805,7 +803,7 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 start_time += start_at_zero ? 0 : f->start_time_effective;
 }
 if (dts_est >= f->recording_time + start_time)
-duration_exceeded = 1;
+pkt = NULL;
 }
 
 for (int oidx = 0; oidx < ist->nb_outputs; oidx++) {
@@ -813,11 +811,6 @@ static int process_input_packet(InputStream *ist, const 
AVPacket *pkt, int no_eo
 if (ost->enc || (!pkt && no_eof))
 continue;
 
-if (duration_exceeded) {
-close_output_stream(ost);
-continue;
-}
-
 of_streamcopy(ost, pkt, dts_est);
 }
 
-- 
2.40.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 14/23] fftools/ffmpeg: convert timestamps inside the muxer

2023-05-31 Thread Anton Khirnov
Packets submitted to the muxer now have their timebase attached to them,
so the muxer can do conversion to muxing timebase and avoid exposing it
to callers.
---
 fftools/ffmpeg_enc.c | 17 ++---
 fftools/ffmpeg_mux.c |  6 ++
 2 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 1b0410ae74..f6431b29d1 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -512,8 +512,8 @@ void enc_subtitle(OutputFile *of, OutputStream *ost, 
AVSubtitle *sub)
 }
 
 av_shrink_packet(pkt, subtitle_out_size);
-pkt->time_base = ost->mux_timebase;
-pkt->pts  = av_rescale_q(sub->pts, AV_TIME_BASE_Q, pkt->time_base);
+pkt->time_base = AV_TIME_BASE_Q;
+pkt->pts   = sub->pts;
 pkt->duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 
1000 }, pkt->time_base);
 if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
 /* XXX: the pts correction is handled here. Maybe handling
@@ -735,19 +735,6 @@ static int encode_frame(OutputFile *of, OutputStream *ost, 
AVFrame *frame)
av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, 
>time_base));
 }
 
-av_packet_rescale_ts(pkt, pkt->time_base, ost->mux_timebase);
-pkt->time_base = ost->mux_timebase;
-
-if (debug_ts) {
-av_log(ost, AV_LOG_INFO, "encoder -> type:%s "
-   "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s "
-   "duration:%s duration_time:%s\n",
-   type_desc,
-   av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, 
>time_base),
-   av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, 
>time_base),
-   av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, 
>time_base));
-}
-
 if ((ret = trigger_fix_sub_duration_heartbeat(ost, pkt)) < 0) {
 av_log(NULL, AV_LOG_ERROR,
"Subtitle heartbeat logic failed in %s! (%s)\n",
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 121796a55a..dc2d189ff0 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -334,6 +334,12 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int eof)
 if (!eof && pkt->dts != AV_NOPTS_VALUE)
 ost->last_mux_dts = av_rescale_q(pkt->dts, pkt->time_base, 
AV_TIME_BASE_Q);
 
+/* rescale timestamps to the muxing timebase */
+if (!eof) {
+av_packet_rescale_ts(pkt, pkt->time_base, ost->mux_timebase);
+pkt->time_base = ost->mux_timebase;
+}
+
 /* apply the output bitstream filters */
 if (ms->bsf_ctx) {
 int bsf_eof = 0;
-- 
2.40.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 16/23] fftools/ffmpeg: attach filter framerate to frames

2023-05-31 Thread Anton Khirnov
This way the encoder does not need to reach backward into the filter.
---
 fftools/ffmpeg.h|  2 ++
 fftools/ffmpeg_enc.c| 19 +++
 fftools/ffmpeg_filter.c | 10 ++
 3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 6f71e85658..49c07ede95 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -655,6 +655,8 @@ typedef struct FrameData {
 uint64_t   idx;
 int64_tpts;
 AVRational tb;
+
+AVRational frame_rate_filter;
 } FrameData;
 
 extern InputFile   **input_files;
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index f6431b29d1..cd2faccf4e 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -217,8 +217,10 @@ int enc_open(OutputStream *ost, AVFrame *frame)
 case AVMEDIA_TYPE_VIDEO: {
 AVRational fr = ost->frame_rate;
 
-if (!fr.num)
-fr = av_buffersink_get_frame_rate(ost->filter->filter);
+if (!fr.num && frame) {
+FrameData *fd = frame_data(frame);
+fr = fd->frame_rate_filter;
+}
 if (!fr.num && !ost->max_frame_rate.num) {
 fr = (AVRational){25, 1};
 av_log(ost, AV_LOG_WARNING,
@@ -1024,17 +1026,18 @@ static void do_video_out(OutputFile *of, OutputStream 
*ost, AVFrame *frame)
 int ret;
 Encoder *e = ost->enc;
 AVCodecContext *enc = ost->enc_ctx;
-AVRational frame_rate;
 int64_t nb_frames, nb_frames_prev, i;
 double duration = 0;
-AVFilterContext *filter = ost->filter->filter;
 
-if (frame)
+if (frame) {
+FrameData *fd = frame_data(frame);
+
 duration = lrintf(frame->duration * av_q2d(frame->time_base) / 
av_q2d(enc->time_base));
 
-frame_rate = av_buffersink_get_frame_rate(filter);
-if (duration <= 0 && frame_rate.num > 0 && frame_rate.den > 0)
-duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base));
+if (duration <= 0 &&
+fd->frame_rate_filter.num > 0 && fd->frame_rate_filter.den > 0)
+duration = 1 / (av_q2d(fd->frame_rate_filter) * 
av_q2d(enc->time_base));
+}
 
 video_sync_process(of, ost, frame, duration,
_frames, _frames_prev);
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 1150f6fc65..a2b45a14b8 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1711,6 +1711,16 @@ int reap_filters(int flush)
tb.num, tb.den);
 }
 
+if (ost->type == AVMEDIA_TYPE_VIDEO) {
+FrameData *fd = frame_data(filtered_frame);
+if (!fd) {
+av_frame_unref(filtered_frame);
+report_and_exit(AVERROR(ENOMEM));
+}
+
+fd->frame_rate_filter = av_buffersink_get_frame_rate(filter);
+}
+
 enc_frame(ost, filtered_frame);
 av_frame_unref(filtered_frame);
 }
-- 
2.40.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 09/23] fftools/ffmpeg_mux_init: only process -enc_time_base if the stream is encoded

2023-05-31 Thread Anton Khirnov
It has no effect otherwise.
---
 fftools/ffmpeg_mux_init.c | 23 ---
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index b5295ad445..d0b89cd188 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1073,6 +1073,7 @@ static OutputStream *ost_add(Muxer *mux, const 
OptionsContext *o,
 AVIOContext *s = NULL;
 char *buf = NULL, *arg = NULL, *preset = NULL;
 const char *enc_stats_pre = NULL, *enc_stats_post = NULL, *mux_stats = 
NULL;
+const char *enc_time_base = NULL;
 
 ost->encoder_opts = filter_codec_opts(o->g->codec_opts, enc->codec_id,
   oc, st, enc->codec);
@@ -1139,6 +1140,17 @@ static OutputStream *ost_add(Muxer *mux, const 
OptionsContext *o,
 if (ret < 0)
 exit_program(1);
 }
+
+MATCH_PER_STREAM_OPT(enc_time_bases, str, enc_time_base, oc, st);
+if (enc_time_base) {
+AVRational q;
+if (av_parse_ratio(, enc_time_base, INT_MAX, 0, NULL) < 0 ||
+q.den <= 0) {
+av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", 
enc_time_base);
+exit_program(1);
+}
+ost->enc_timebase = q;
+}
 } else {
 ost->encoder_opts = filter_codec_opts(o->g->codec_opts, 
AV_CODEC_ID_NONE, oc, st, NULL);
 }
@@ -1162,17 +1174,6 @@ static OutputStream *ost_add(Muxer *mux, const 
OptionsContext *o,
 st->time_base = q;
 }
 
-MATCH_PER_STREAM_OPT(enc_time_bases, str, time_base, oc, st);
-if (time_base) {
-AVRational q;
-if (av_parse_ratio(, time_base, INT_MAX, 0, NULL) < 0 ||
-q.den <= 0) {
-av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
-exit_program(1);
-}
-ost->enc_timebase = q;
-}
-
 ms->max_frames = INT64_MAX;
 MATCH_PER_STREAM_OPT(max_frames, i64, ms->max_frames, oc, st);
 for (i = 0; inb_max_frames; i++) {
-- 
2.40.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 12/23] fftools/ffmpeg_enc: do not guess frame durations from output framerate

2023-05-31 Thread Anton Khirnov
There is no reason to expect input frame durations to match output
framerate.
---
 fftools/ffmpeg_enc.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 4a5ae3aa1b..5be6e9332a 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -1042,9 +1042,6 @@ static void do_video_out(OutputFile *of, OutputStream 
*ost, AVFrame *frame)
 if (frame)
 duration = lrintf(frame->duration * av_q2d(frame->time_base) / 
av_q2d(enc->time_base));
 
-if (duration <= 0 && ost->frame_rate.num)
-duration = FFMIN(duration, 1/(av_q2d(ost->frame_rate) * 
av_q2d(enc->time_base)));
-
 frame_rate = av_buffersink_get_frame_rate(filter);
 if (duration <= 0 && frame_rate.num > 0 && frame_rate.den > 0)
 duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base));
-- 
2.40.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 02/23] fftools/ffmpeg_mux: set stream duration after the timebase is certainly known

2023-05-31 Thread Anton Khirnov
Stop assuming the encoder knows the muxing timebase, which does not
always have to hold (e.g. due to bitstream filters).
---
 fftools/ffmpeg_enc.c  |  4 
 fftools/ffmpeg_mux.c  |  5 +
 fftools/ffmpeg_mux.h  |  3 +++
 fftools/ffmpeg_mux_init.c | 10 ++
 4 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index f3e291a9e4..fab71ca0c0 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -445,10 +445,6 @@ int enc_open(OutputStream *ost, AVFrame *frame)
 if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0)
 ost->st->time_base = av_add_q(ost->enc_ctx->time_base, (AVRational){0, 
1});
 
-// copy estimated duration as a hint to the muxer
-if (ost->st->duration <= 0 && ist && ist->st->duration > 0)
-ost->st->duration = av_rescale_q(ist->st->duration, 
ist->st->time_base, ost->st->time_base);
-
 ost->mux_timebase = enc_ctx->time_base;
 
 ret = of_stream_init(of, ost);
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index feb014ca31..121796a55a 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -666,6 +666,11 @@ int of_stream_init(OutputFile *of, OutputStream *ost)
 if (ret < 0)
 return ret;
 
+if (ms->stream_duration) {
+ost->st->duration = av_rescale_q(ms->stream_duration, 
ms->stream_duration_tb,
+ ost->st->time_base);
+}
+
 ost->initialized = 1;
 
 return mux_check_init(mux);
diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h
index 7e0454dfba..bee7addd6a 100644
--- a/fftools/ffmpeg_mux.h
+++ b/fftools/ffmpeg_mux.h
@@ -69,6 +69,9 @@ typedef struct MuxStream {
  * used for making up missing dts values */
 int64_t last_mux_dts;
 
+int64_tstream_duration;
+AVRational stream_duration_tb;
+
 // audio streamcopy - state for av_rescale_delta()
 int64_t ts_rescale_delta_last;
 
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 4fc6f0fb46..33c93e40f2 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -914,10 +914,6 @@ static int streamcopy_init(const Muxer *mux, OutputStream 
*ost)
 ost->st->time_base = 
av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1});
 }
 
-// copy estimated duration as a hint to the muxer
-if (ost->st->duration <= 0 && ist->st->duration > 0)
-ost->st->duration = av_rescale_q(ist->st->duration, 
ist->st->time_base, ost->st->time_base);
-
 if (!ms->copy_prior_start) {
 ms->ts_copy_start = (mux->of.start_time == AV_NOPTS_VALUE) ?
 0 : mux->of.start_time;
@@ -1283,6 +1279,12 @@ static OutputStream *ost_add(Muxer *mux, const 
OptionsContext *o,
 exit_program(1);
 }
 
+// copy estimated duration as a hint to the muxer
+if (ost->ist && ost->ist->st->duration > 0) {
+ms->stream_duration= ist->st->duration;
+ms->stream_duration_tb = ist->st->time_base;
+}
+
 return ost;
 }
 
-- 
2.40.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 03/23] fftools/ffmpeg_filter: drop a write-only variable

2023-05-31 Thread Anton Khirnov
---
 fftools/ffmpeg.h| 1 -
 fftools/ffmpeg_filter.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index cef4b5d000..0e9ad5f9f7 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -296,7 +296,6 @@ typedef struct OutputFilter {
 
 /* desired output stream properties */
 int width, height;
-AVRational frame_rate;
 int format;
 int sample_rate;
 AVChannelLayout ch_layout;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index c3075ef854..287b1e6f9d 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -654,7 +654,6 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream 
*ost)
 
 switch (ost->enc_ctx->codec_type) {
 case AVMEDIA_TYPE_VIDEO:
-ofilter->frame_rate = ost->frame_rate;
 ofilter->width  = ost->enc_ctx->width;
 ofilter->height = ost->enc_ctx->height;
 if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
-- 
2.40.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 17/23] fftools/ffmpeg_enc: stop using OutputStream.initialized

2023-05-31 Thread Anton Khirnov
It is set by the muxing code, which will not be synchronized with
encoding code after upcoming threading changes. Use an encoder-private
variable instead.
---
 fftools/ffmpeg_enc.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index cd2faccf4e..1515ca971f 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -62,6 +62,8 @@ struct Encoder {
 
 // number of packets received from the encoder
 uint64_t packets_encoded;
+
+int opened;
 };
 
 static uint64_t dup_warning = 1000;
@@ -187,7 +189,7 @@ int enc_open(OutputStream *ost, AVFrame *frame)
 OutputFile  *of = output_files[ost->file_index];
 int ret;
 
-if (ost->initialized)
+if (e->opened)
 return 0;
 
 set_encoder_id(output_files[ost->file_index], ost);
@@ -362,6 +364,8 @@ int enc_open(OutputStream *ost, AVFrame *frame)
 return ret;
 }
 
+e->opened = 1;
+
 if (ost->sq_idx_encode >= 0) {
 e->sq_frame = av_frame_alloc();
 if (!e->sq_frame)
@@ -1123,6 +1127,7 @@ void enc_flush(void)
 }
 
 for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
+Encoder  *e = ost->enc;
 AVCodecContext *enc = ost->enc_ctx;
 OutputFile  *of = output_files[ost->file_index];
 
@@ -1131,7 +1136,7 @@ void enc_flush(void)
 
 // Try to enable encoding with no input frames.
 // Maybe we should just let encoding fail instead.
-if (!ost->initialized) {
+if (!e->opened) {
 FilterGraph *fg = ost->filter->graph;
 
 av_log(ost, AV_LOG_WARNING,
-- 
2.40.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 19/23] fftools/ffmpeg: stop explicitly closing output streams on input EOF

2023-05-31 Thread Anton Khirnov
Sending an empty packet already does that implicitly.
---
 fftools/ffmpeg.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 7d2a25f2bf..462365ed02 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1104,7 +1104,6 @@ static int process_input(int file_index)
 for (int oidx = 0; oidx < ist->nb_outputs; oidx++) {
 OutputStream *ost = ist->outputs[oidx];
 OutputFile*of = output_files[ost->file_index];
-close_output_stream(ost);
 of_output_packet(of, ost->pkt, ost, 1);
 }
 }
-- 
2.40.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 15/23] fftools/ffmpeg: factor out attaching FrameData to a frame

2023-05-31 Thread Anton Khirnov
Will be useful in following commits.
---
 fftools/ffmpeg.c | 11 +++
 fftools/ffmpeg.h |  6 ++
 fftools/ffmpeg_dec.c |  5 ++---
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index bcda7570e9..9997881572 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -431,6 +431,17 @@ InputStream *ist_iter(InputStream *prev)
 return NULL;
 }
 
+FrameData *frame_data(AVFrame *frame)
+{
+if (!frame->opaque_ref) {
+frame->opaque_ref = av_buffer_allocz(sizeof(FrameData));
+if (!frame->opaque_ref)
+return NULL;
+}
+
+return (FrameData*)frame->opaque_ref->data;
+}
+
 void remove_avoptions(AVDictionary **a, AVDictionary *b)
 {
 const AVDictionaryEntry *t = NULL;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 0e9ad5f9f7..6f71e85658 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -737,6 +737,12 @@ int init_complex_filtergraph(FilterGraph *fg);
 
 int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src);
 
+/**
+ * Get our axiliary frame data attached to the frame, allocating it
+ * if needed.
+ */
+FrameData *frame_data(AVFrame *frame);
+
 int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int 
keep_reference);
 int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb);
 int ifilter_sub2video(InputFilter *ifilter, const AVSubtitle *sub);
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 30959c64b7..799be63215 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -499,12 +499,11 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int 
no_eof)
 FrameData *fd;
 
 av_assert0(!frame->opaque_ref);
-frame->opaque_ref = av_buffer_allocz(sizeof(*fd));
-if (!frame->opaque_ref) {
+fd  = frame_data(frame);
+if (!fd) {
 av_frame_unref(frame);
 report_and_exit(AVERROR(ENOMEM));
 }
-fd  = (FrameData*)frame->opaque_ref->data;
 fd->pts = frame->pts;
 fd->tb  = dec->pkt_timebase;
 fd->idx = dec->frame_num - 1;
-- 
2.40.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 11/23] fftools/ffmpeg_enc: inline init_encoder_time_base() into its callers

2023-05-31 Thread Anton Khirnov
The function now reduces to a ternary operator, so it is shorter and
clearer to eliminate it.
---
 fftools/ffmpeg_enc.c | 18 --
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 04d2c3c201..4a5ae3aa1b 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -177,18 +177,6 @@ static void set_encoder_id(OutputFile *of, OutputStream 
*ost)
 AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE);
 }
 
-static void init_encoder_time_base(OutputStream *ost, AVRational 
default_time_base)
-{
-AVCodecContext *enc_ctx = ost->enc_ctx;
-
-if (ost->enc_timebase.num > 0) {
-enc_ctx->time_base = ost->enc_timebase;
-return;
-}
-
-enc_ctx->time_base = default_time_base;
-}
-
 int enc_open(OutputStream *ost, AVFrame *frame)
 {
 InputStream *ist = ost->ist;
@@ -222,7 +210,8 @@ int enc_open(OutputStream *ost, AVFrame *frame)
 enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
  
av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3);
 
-init_encoder_time_base(ost, av_make_q(1, enc_ctx->sample_rate));
+enc_ctx->time_base = ost->enc_timebase.num > 0 ? ost->enc_timebase :
+ av_make_q(1, enc_ctx->sample_rate);
 break;
 
 case AVMEDIA_TYPE_VIDEO:
@@ -252,7 +241,8 @@ int enc_open(OutputStream *ost, AVFrame *frame)
   ost->frame_rate.num, ost->frame_rate.den, 65535);
 }
 
-init_encoder_time_base(ost, av_inv_q(ost->frame_rate));
+enc_ctx->time_base = ost->enc_timebase.num > 0 ? ost->enc_timebase :
+ av_inv_q(ost->frame_rate);
 
 if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
 enc_ctx->time_base = 
av_buffersink_get_time_base(ost->filter->filter);
-- 
2.40.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 22/23] fftools/ffmpeg_enc: use a private AVPacket instance for encoding

2023-05-31 Thread Anton Khirnov
The code currently uses OutputStream.pkt, which complicates its
ownership semantics.
---
 fftools/ffmpeg_enc.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 8dd8104cea..2bf4782a9f 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -57,6 +57,9 @@ struct Encoder {
 
 AVFrame *sq_frame;
 
+// packet for receiving encoded output
+AVPacket *pkt;
+
 // combined size of all the packets received from the encoder
 uint64_t data_size;
 
@@ -78,6 +81,8 @@ void enc_free(Encoder **penc)
 av_frame_free(>last_frame);
 av_frame_free(>sq_frame);
 
+av_packet_free(>pkt);
+
 av_freep(penc);
 }
 
@@ -97,6 +102,10 @@ int enc_alloc(Encoder **penc, const AVCodec *codec)
 goto fail;
 }
 
+enc->pkt = av_packet_alloc();
+if (!enc->pkt)
+goto fail;
+
 *penc = enc;
 
 return 0;
@@ -454,10 +463,11 @@ static int check_recording_time(OutputStream *ost, 
int64_t ts, AVRational tb)
 
 void enc_subtitle(OutputFile *of, OutputStream *ost, AVSubtitle *sub)
 {
+Encoder *e = ost->enc;
 int subtitle_out_max_size = 1024 * 1024;
 int subtitle_out_size, nb, i, ret;
 AVCodecContext *enc;
-AVPacket *pkt = ost->pkt;
+AVPacket *pkt = e->pkt;
 int64_t pts;
 
 if (sub->pts == AV_NOPTS_VALUE) {
@@ -669,7 +679,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, 
AVFrame *frame)
 {
 Encoder*e = ost->enc;
 AVCodecContext   *enc = ost->enc_ctx;
-AVPacket *pkt = ost->pkt;
+AVPacket *pkt = e->pkt;
 const char *type_desc = av_get_media_type_string(enc->codec_type);
 const char*action = frame ? "encode" : "flush";
 int ret;
-- 
2.40.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 13/23] fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for encoding

2023-05-31 Thread Anton Khirnov
The values currently written into it are not used after
enc_open(), so it is better to confine them to that function.
---
 fftools/ffmpeg_enc.c | 33 ++---
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 5be6e9332a..1b0410ae74 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -214,11 +214,13 @@ int enc_open(OutputStream *ost, AVFrame *frame)
  av_make_q(1, enc_ctx->sample_rate);
 break;
 
-case AVMEDIA_TYPE_VIDEO:
-if (!ost->frame_rate.num)
-ost->frame_rate = 
av_buffersink_get_frame_rate(ost->filter->filter);
-if (!ost->frame_rate.num && !ost->max_frame_rate.num) {
-ost->frame_rate = (AVRational){25, 1};
+case AVMEDIA_TYPE_VIDEO: {
+AVRational fr = ost->frame_rate;
+
+if (!fr.num)
+fr = av_buffersink_get_frame_rate(ost->filter->filter);
+if (!fr.num && !ost->max_frame_rate.num) {
+fr = (AVRational){25, 1};
 av_log(ost, AV_LOG_WARNING,
"No information "
"about the input framerate is available. Falling "
@@ -227,22 +229,22 @@ int enc_open(OutputStream *ost, AVFrame *frame)
 }
 
 if (ost->max_frame_rate.num &&
-(av_q2d(ost->frame_rate) > av_q2d(ost->max_frame_rate) ||
-!ost->frame_rate.den))
-ost->frame_rate = ost->max_frame_rate;
+(av_q2d(fr) > av_q2d(ost->max_frame_rate) ||
+!fr.den))
+fr = ost->max_frame_rate;
 
 if (enc->supported_framerates && !ost->force_fps) {
-int idx = av_find_nearest_q_idx(ost->frame_rate, 
enc->supported_framerates);
-ost->frame_rate = enc->supported_framerates[idx];
+int idx = av_find_nearest_q_idx(fr, enc->supported_framerates);
+fr = enc->supported_framerates[idx];
 }
 // reduce frame rate for mpeg4 to be within the spec limits
 if (enc_ctx->codec_id == AV_CODEC_ID_MPEG4) {
-av_reduce(>frame_rate.num, >frame_rate.den,
-  ost->frame_rate.num, ost->frame_rate.den, 65535);
+av_reduce(, ,
+  fr.num, fr.den, 65535);
 }
 
 enc_ctx->time_base = ost->enc_timebase.num > 0 ? ost->enc_timebase :
- av_inv_q(ost->frame_rate);
+ av_inv_q(fr);
 
 if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
 enc_ctx->time_base = 
av_buffersink_get_time_base(ost->filter->filter);
@@ -277,9 +279,9 @@ int enc_open(OutputStream *ost, AVFrame *frame)
 enc_ctx->chroma_sample_location = frame->chroma_location;
 }
 
-enc_ctx->framerate = ost->frame_rate;
+enc_ctx->framerate = fr;
 
-ost->st->avg_frame_rate = ost->frame_rate;
+ost->st->avg_frame_rate = fr;
 
 // Field order: autodetection
 if (frame) {
@@ -307,6 +309,7 @@ int enc_open(OutputStream *ost, AVFrame *frame)
 }
 
 break;
+}
 case AVMEDIA_TYPE_SUBTITLE:
 enc_ctx->time_base = AV_TIME_BASE_Q;
 if (!enc_ctx->width) {
-- 
2.40.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 10/23] fftools/ffmpeg: handle -enc_time_base -1 during stream creation

2023-05-31 Thread Anton Khirnov
There is no reason to postpone it until opening the encoder. Also, abort
when the input stream is unknown, rather than disregard an explicit
request from the user.
---
 fftools/ffmpeg_enc.c  | 11 ---
 fftools/ffmpeg_mux_init.c |  9 +
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 07928b3557..04d2c3c201 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -179,7 +179,6 @@ static void set_encoder_id(OutputFile *of, OutputStream 
*ost)
 
 static void init_encoder_time_base(OutputStream *ost, AVRational 
default_time_base)
 {
-InputStream *ist = ost->ist;
 AVCodecContext *enc_ctx = ost->enc_ctx;
 
 if (ost->enc_timebase.num > 0) {
@@ -187,16 +186,6 @@ static void init_encoder_time_base(OutputStream *ost, 
AVRational default_time_ba
 return;
 }
 
-if (ost->enc_timebase.num < 0) {
-if (ist) {
-enc_ctx->time_base = ist->st->time_base;
-return;
-}
-
-av_log(ost, AV_LOG_WARNING,
-   "Input stream data not available, using default time base\n");
-}
-
 enc_ctx->time_base = default_time_base;
 }
 
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index d0b89cd188..c49f906dc7 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1149,6 +1149,15 @@ static OutputStream *ost_add(Muxer *mux, const 
OptionsContext *o,
 av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", 
enc_time_base);
 exit_program(1);
 }
+if (q.num < 0) {
+if (!ost->ist) {
+av_log(ost, AV_LOG_FATAL,
+   "Cannot use input stream timebase for encoding - "
+   "no input stream available\n");
+exit_program(1);
+}
+q = ost->ist->st->time_base;
+}
 ost->enc_timebase = q;
 }
 } else {
-- 
2.40.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 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream

2023-05-31 Thread Anton Khirnov
---
The patchset is also available from branch 'ffmpeg_enc_tb' in
git://git.khirnov.net/libav
---

 fftools/ffmpeg.c | 6 --
 fftools/ffmpeg.h | 6 +++---
 fftools/ffmpeg_enc.c | 8 
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 36b4becaf2..bcda7570e9 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -119,8 +119,6 @@ typedef struct BenchmarkTimeStamps {
 static BenchmarkTimeStamps get_benchmark_time_stamps(void);
 static int64_t getmaxrss(void);
 
-int64_t nb_frames_dup = 0;
-int64_t nb_frames_drop = 0;
 unsigned nb_output_dumped = 0;
 
 static BenchmarkTimeStamps current_time;
@@ -491,6 +489,7 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 int64_t pts = INT64_MIN + 1;
 static int64_t last_time = -1;
 static int first_report = 1;
+uint64_t nb_frames_dup = 0, nb_frames_drop = 0;
 int hours, mins, secs, us;
 const char *hours_sign;
 int ret;
@@ -536,6 +535,9 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 if (is_last_report)
 av_bprintf(, "L");
 
+nb_frames_dup  = ost->nb_frames_dup;
+nb_frames_drop = ost->nb_frames_drop;
+
 vid = 1;
 }
 /* compute min output value */
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 966397270d..cef4b5d000 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -553,6 +553,9 @@ typedef struct OutputStream {
 Encoder *enc;
 AVCodecContext *enc_ctx;
 AVPacket *pkt;
+
+uint64_t nb_frames_dup;
+uint64_t nb_frames_drop;
 int64_t last_dropped;
 
 /* video only */
@@ -707,9 +710,6 @@ extern int recast_media;
 
 extern FILE *vstats_file;
 
-extern int64_t nb_frames_dup;
-extern int64_t nb_frames_drop;
-
 #if FFMPEG_OPT_PSNR
 extern int do_psnr;
 #endif
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 6c9cce252f..f3e291a9e4 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -1078,7 +1078,7 @@ static void do_video_out(OutputFile *of, OutputStream 
*ost, AVFrame *frame)
_frames, _frames_prev);
 
 if (nb_frames_prev == 0 && ost->last_dropped) {
-nb_frames_drop++;
+ost->nb_frames_drop++;
 av_log(ost, AV_LOG_VERBOSE,
"*** dropping frame %"PRId64" at ts %"PRId64"\n",
e->vsync_frame_number, e->last_frame->pts);
@@ -1086,12 +1086,12 @@ static void do_video_out(OutputFile *of, OutputStream 
*ost, AVFrame *frame)
 if (nb_frames > (nb_frames_prev && ost->last_dropped) + (nb_frames > 
nb_frames_prev)) {
 if (nb_frames > dts_error_threshold * 30) {
 av_log(ost, AV_LOG_ERROR, "%"PRId64" frame duplication too large, 
skipping\n", nb_frames - 1);
-nb_frames_drop++;
+ost->nb_frames_drop++;
 return;
 }
-nb_frames_dup += nb_frames - (nb_frames_prev && ost->last_dropped) - 
(nb_frames > nb_frames_prev);
+ost->nb_frames_dup += nb_frames - (nb_frames_prev && 
ost->last_dropped) - (nb_frames > nb_frames_prev);
 av_log(ost, AV_LOG_VERBOSE, "*** %"PRId64" dup!\n", nb_frames - 1);
-if (nb_frames_dup > dup_warning) {
+if (ost->nb_frames_dup > dup_warning) {
 av_log(ost, AV_LOG_WARNING, "More than %"PRIu64" frames 
duplicated\n", dup_warning);
 dup_warning *= 10;
 }
-- 
2.40.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 07/23] fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for streamcopy

2023-05-31 Thread Anton Khirnov
The values currently written into it are not used after
streamcopy_init(), so it is better to confine them to that function.
---
 fftools/ffmpeg_mux_init.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 33c93e40f2..b5295ad445 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -861,6 +861,9 @@ static int streamcopy_init(const Muxer *mux, OutputStream 
*ost)
 
 AVCodecContext  *codec_ctx  = NULL;
 AVDictionary*codec_opts = NULL;
+
+AVRational   fr = ost->frame_rate;
+
 int ret = 0;
 
 codec_ctx = avcodec_alloc_context3(NULL);
@@ -893,11 +896,11 @@ static int streamcopy_init(const Muxer *mux, OutputStream 
*ost)
 
 par->codec_tag = codec_tag;
 
-if (!ost->frame_rate.num)
-ost->frame_rate = ist->framerate;
+if (!fr.num)
+fr = ist->framerate;
 
-if (ost->frame_rate.num)
-ost->st->avg_frame_rate = ost->frame_rate;
+if (fr.num)
+ost->st->avg_frame_rate = fr;
 else
 ost->st->avg_frame_rate = ist->st->avg_frame_rate;
 
@@ -908,8 +911,8 @@ static int streamcopy_init(const Muxer *mux, OutputStream 
*ost)
 
 // copy timebase while removing common factors
 if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) {
-if (ost->frame_rate.num)
-ost->st->time_base = av_inv_q(ost->frame_rate);
+if (fr.num)
+ost->st->time_base = av_inv_q(fr);
 else
 ost->st->time_base = 
av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1});
 }
-- 
2.40.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 08/23] fftools/ffmpeg_enc: merge two adjacent video-specific blocks

2023-05-31 Thread Anton Khirnov
There is no meaningful reason for them to be separated.
---
 fftools/ffmpeg_enc.c | 38 ++
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index d390e384ed..07928b3557 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -219,7 +219,24 @@ int enc_open(OutputStream *ost, AVFrame *frame)
 dec_ctx = ist->dec_ctx;
 }
 
-if (enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
+switch (enc_ctx->codec_type) {
+case AVMEDIA_TYPE_AUDIO:
+enc_ctx->sample_fmt = 
av_buffersink_get_format(ost->filter->filter);
+enc_ctx->sample_rate= 
av_buffersink_get_sample_rate(ost->filter->filter);
+ret = av_buffersink_get_ch_layout(ost->filter->filter, 
_ctx->ch_layout);
+if (ret < 0)
+return ret;
+
+if (ost->bits_per_raw_sample)
+enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample;
+else if (dec_ctx && ost->filter->graph->is_meta)
+enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
+ 
av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3);
+
+init_encoder_time_base(ost, av_make_q(1, enc_ctx->sample_rate));
+break;
+
+case AVMEDIA_TYPE_VIDEO:
 if (!ost->frame_rate.num)
 ost->frame_rate = 
av_buffersink_get_frame_rate(ost->filter->filter);
 if (!ost->frame_rate.num && !ost->max_frame_rate.num) {
@@ -245,26 +262,7 @@ int enc_open(OutputStream *ost, AVFrame *frame)
 av_reduce(>frame_rate.num, >frame_rate.den,
   ost->frame_rate.num, ost->frame_rate.den, 65535);
 }
-}
 
-switch (enc_ctx->codec_type) {
-case AVMEDIA_TYPE_AUDIO:
-enc_ctx->sample_fmt = 
av_buffersink_get_format(ost->filter->filter);
-enc_ctx->sample_rate= 
av_buffersink_get_sample_rate(ost->filter->filter);
-ret = av_buffersink_get_ch_layout(ost->filter->filter, 
_ctx->ch_layout);
-if (ret < 0)
-return ret;
-
-if (ost->bits_per_raw_sample)
-enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample;
-else if (dec_ctx && ost->filter->graph->is_meta)
-enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
- 
av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3);
-
-init_encoder_time_base(ost, av_make_q(1, enc_ctx->sample_rate));
-break;
-
-case AVMEDIA_TYPE_VIDEO:
 init_encoder_time_base(ost, av_inv_q(ost->frame_rate));
 
 if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
-- 
2.40.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 06/23] fftools/ffmpeg_enc: avoid breaking exactly integer timestamps in vsync code

2023-05-31 Thread Anton Khirnov
The code will currently add a small offset to avoid exact midpoints, but
this can cause inexact results when a float timestamp is exactly
representable as an integer.

Fixes off-by-one in the first frame duration in multiple FATE tests.
---
 fftools/ffmpeg_enc.c | 6 --
 tests/ref/fate/apng-osample  | 2 +-
 tests/ref/fate/film-cvid | 2 +-
 tests/ref/fate/filter-concat-vfr | 2 +-
 tests/ref/fate/gif-gray  | 2 +-
 5 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index fab71ca0c0..d390e384ed 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -888,9 +888,11 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile 
*of, OutputStream *ost,
 float_pts = av_rescale_q(frame->pts, filter_tb, tb) -
 av_rescale_q(start_time, AV_TIME_BASE_Q, tb);
 float_pts /= 1 << extra_bits;
-// avoid exact midoints to reduce the chance of rounding differences, this
+// when float_pts is not exactly an integer,
+// avoid exact midpoints to reduce the chance of rounding differences, this
 // can be removed in case the fps code is changed to work with integers
-float_pts += FFSIGN(float_pts) * 1.0 / (1<<17);
+if (float_pts != llrint(float_pts))
+float_pts += FFSIGN(float_pts) * 1.0 / (1<<17);
 
 frame->pts = av_rescale_q(frame->pts, filter_tb, enc->time_base) -
  av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base);
diff --git a/tests/ref/fate/apng-osample b/tests/ref/fate/apng-osample
index c91dd5284d..6cf74a99ee 100644
--- a/tests/ref/fate/apng-osample
+++ b/tests/ref/fate/apng-osample
@@ -3,7 +3,7 @@
 #codec_id 0: rawvideo
 #dimensions 0: 116x135
 #sar 0: 0/1
-0,  0,  0,2,62640, 0x31eb581d
+0,  0,  0,3,62640, 0x31eb581d
 0,  3,  3,3,62640, 0x29e11b82
 0,  6,  6,3,62640, 0x207ed588
 0,  9,  9,3,62640, 0x3845c906
diff --git a/tests/ref/fate/film-cvid b/tests/ref/fate/film-cvid
index 60bbc192d8..428cb6e9f0 100644
--- a/tests/ref/fate/film-cvid
+++ b/tests/ref/fate/film-cvid
@@ -3,7 +3,7 @@
 #codec_id 0: rawvideo
 #dimensions 0: 320x224
 #sar 0: 0/1
-0,  0,  0,1,   215040, 0x067c5362
+0,  0,  0,2,   215040, 0x067c5362
 0,  2,  2,2,   215040, 0xd9eacb98
 0,  4,  4,2,   215040, 0x3c8a4cbd
 0,  6,  6,2,   215040, 0xbdf996e1
diff --git a/tests/ref/fate/filter-concat-vfr b/tests/ref/fate/filter-concat-vfr
index 66e9007da8..3d984a4968 100644
--- a/tests/ref/fate/filter-concat-vfr
+++ b/tests/ref/fate/filter-concat-vfr
@@ -8,7 +8,7 @@
 #codec_id 1: pcm_s16le
 #sample_rate 1: 44100
 #channel_layout_name 1: mono
-0,  0,  0,   19,   230400, 0x88c4d19a
+0,  0,  0,   20,   230400, 0x88c4d19a
 1,  0,  0, 1024, 2048, 0xb3f10192
 1,   1024,   1024, 1024, 2048, 0xb340fe4e
 1,   2048,   2048, 1024, 2048, 0x0a5f0111
diff --git a/tests/ref/fate/gif-gray b/tests/ref/fate/gif-gray
index aa3969212d..c246d8a670 100644
--- a/tests/ref/fate/gif-gray
+++ b/tests/ref/fate/gif-gray
@@ -3,7 +3,7 @@
 #codec_id 0: rawvideo
 #dimensions 0: 480x360
 #sar 0: 0/1
-0,  0,  0,4,   691200, 0xef6c0f3d
+0,  0,  0,5,   691200, 0xef6c0f3d
 0,  5,  5,2,   691200, 0xc18b32de
 0,  7,  7,2,   691200, 0x2395a3d7
 0,  9,  9,2,   691200, 0x81dc3cf2
-- 
2.40.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 4/5] lavfi/graphparser: reimplement avfilter_graph_parse* using new API

2023-05-31 Thread Paul B Mahol
On Tue, May 30, 2023 at 11:10 PM Marton Balint  wrote:

>
>
> On Fri, 20 Jan 2023, Anton Khirnov wrote:
>
> > ---
> > libavfilter/graphparser.c | 537 +-
> > 1 file changed, 126 insertions(+), 411 deletions(-)
>
> This change makes error messages for parse failures less useful or
> completely missing. E.g.:
>
> ffmpeg -f lavfi -i testsrc -vf yadif,scale=dummy=boo -f null none
>
> Before:
>
> [Parsed_scale_0 @ 0x555c19335b00] Option 'dummy' not found
> [AVFilterGraph @ 0x555c19333e00] Error initializing filter 'scale' with
> args 'dummy=boo:flags=bicubic'
> Error reinitializing filters!
>
> After:
>
> [AVFilterGraph @ 0x3c5a100] Error applying filter options
> Error reinitializing filters!
>
>
> ffplay -f lavfi -i testsrc -vf yadif,scale=dummy=boo
>
> Before:
>
> [Parsed_scale_1 @ 0x55fa2b935080] Option 'dummy' not found
> Error initializing filter 'scale' with args 'dummy=boo:flags=bicubic'
>
> After:
>
> (no error message)
>

Yes, I was hit by this bug, multiple times recently.
It makes my pain bigger.


> Regards,
> Marton
> ___
> 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 v2 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding

2023-05-31 Thread Wu, Tong1
>On Wednesday, May 31, 2023, Tong Wu 
>wrote:
>
>> From: Wu Jianhua 
>>
>> The implementation is based on:
>> https://learn.microsoft.com/en-us/windows/win32/medfound/
>> direct3d-12-video-overview
>>
>>
>
>> With the Direct3D 12 video decoding support, we can render or process
>> the decoded images by the pixel shaders or compute shaders directly
>
>do you have some demo regarding pixel shaders or compute shaders?

Currently we don't have a simple demo.
You can refer to the official samples. 
https://github.com/microsoft/DirectX-Graphics-Samples
>
>
>> without the extra copy overhead, which is beneficial especially if you
>
>are trying to render or post-process a 4K or 8K video.
>>
>> The command below is how to enable d3d12va:
>> ffmpeg -hwaccel d3d12va -i input.mp4 output.mp4
>>
>> Signed-off-by: Wu Jianhua 
>> Signed-off-by: Tong Wu 
>> ---
>>  configure   |   2 +
>>  libavcodec/Makefile |   3 +
>>  libavcodec/d3d11va.h|   3 -
>>  libavcodec/d3d12va.c| 552 
>>  libavcodec/d3d12va.h| 184 
>>  libavcodec/d3d12va_h264.c   | 210 ++
>>  libavcodec/dxva2.c  |  24 ++
>>  libavcodec/dxva2.h  |   3 -
>>  libavcodec/dxva2_h264.c |  12 +-
>>  libavcodec/dxva2_internal.h |  69 +++--
>>  libavcodec/h264_slice.c |   4 +
>>  libavcodec/h264dec.c|   3 +
>>  libavcodec/hwaccels.h   |   1 +
>>  libavcodec/hwconfig.h   |   2 +
>>  14 files changed, 1030 insertions(+), 42 deletions(-)
>>  create mode 100644 libavcodec/d3d12va.c
>>  create mode 100644 libavcodec/d3d12va.h
>>  create mode 100644 libavcodec/d3d12va_h264.c
>>
>> diff --git a/configure b/configure
>> index b86064e36f..f5dad4653f 100755
>> --- a/configure
>> +++ b/configure
>> @@ -3033,6 +3033,8 @@ h264_d3d11va_hwaccel_deps="d3d11va"
>>  h264_d3d11va_hwaccel_select="h264_decoder"
>>  h264_d3d11va2_hwaccel_deps="d3d11va"
>>  h264_d3d11va2_hwaccel_select="h264_decoder"
>> +h264_d3d12va_hwaccel_deps="d3d12va"
>> +h264_d3d12va_hwaccel_select="h264_decoder"
>>  h264_dxva2_hwaccel_deps="dxva2"
>>  h264_dxva2_hwaccel_select="h264_decoder"
>>  h264_nvdec_hwaccel_deps="nvdec"
>> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
>> index 9aacc1d477..ae143d8821 100644
>> --- a/libavcodec/Makefile
>> +++ b/libavcodec/Makefile
>> @@ -977,6 +977,7 @@ OBJS-$(CONFIG_ADPCM_ZORK_DECODER) +=
>adpcm.o
>> adpcm_data.o
>>
>>  # hardware accelerators
>>  OBJS-$(CONFIG_D3D11VA)+= dxva2.o
>> +OBJS-$(CONFIG_D3D12VA)+= dxva2.o d3d12va.o
>>  OBJS-$(CONFIG_DXVA2)  += dxva2.o
>>  OBJS-$(CONFIG_NVDEC)  += nvdec.o
>>  OBJS-$(CONFIG_VAAPI)  += vaapi_decode.o
>> @@ -994,6 +995,7 @@ OBJS-$(CONFIG_H263_VAAPI_HWACCEL) +=
>> vaapi_mpeg4.o
>>  OBJS-$(CONFIG_H263_VIDEOTOOLBOX_HWACCEL)  += videotoolbox.o
>>  OBJS-$(CONFIG_H264_D3D11VA_HWACCEL)   += dxva2_h264.o
>>  OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o
>> +OBJS-$(CONFIG_H264_D3D12VA_HWACCEL)   += dxva2_h264.o
>d3d12va_h264.o
>>  OBJS-$(CONFIG_H264_NVDEC_HWACCEL) += nvdec_h264.o
>>  OBJS-$(CONFIG_H264_QSV_HWACCEL)   += qsvdec.o
>>  OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o
>> @@ -1277,6 +1279,7 @@ SKIPHEADERS+=
>> %_tablegen.h  \
>>
>>  SKIPHEADERS-$(CONFIG_AMF)  += amfenc.h
>>  SKIPHEADERS-$(CONFIG_D3D11VA)  += d3d11va.h dxva2_internal.h
>> +SKIPHEADERS-$(CONFIG_D3D12VA)  += d3d12va.h
>>  SKIPHEADERS-$(CONFIG_DXVA2)+= dxva2.h dxva2_internal.h
>>  SKIPHEADERS-$(CONFIG_JNI)  += ffjni.h
>>  SKIPHEADERS-$(CONFIG_LCMS2)+= fflcms2.h
>> diff --git a/libavcodec/d3d11va.h b/libavcodec/d3d11va.h
>> index 6816b6c1e6..27f40e5519 100644
>> --- a/libavcodec/d3d11va.h
>> +++ b/libavcodec/d3d11va.h
>> @@ -45,9 +45,6 @@
>>   * @{
>>   */
>>
>> -#define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work
>around for
>> Direct3D11 and old UVD/UVD+ ATI video cards
>> -#define FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO2 ///< Work
>around for
>> Direct3D11 and old Intel GPUs with ClearVideo interface
>> -
>>  /**
>>   * This structure is used to provides the necessary configurations and
>> data
>>   * to the Direct3D11 FFmpeg HWAccel implementation.
>> diff --git a/libavcodec/d3d12va.c b/libavcodec/d3d12va.c
>> new file mode 100644
>> index 00..d80575441c
>> --- /dev/null
>> +++ b/libavcodec/d3d12va.c
>> @@ -0,0 +1,552 @@
>> +/*
>> + * Direct3D 12 HW acceleration video decoder
>> + *
>> + * copyright (c) 2022-2023 Wu Jianhua 
>> + *
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU Lesser General Public
>> + * License as published by the Free Software Foundation; either
>> + * version 2.1 of the License, or (at your option) any later 

Re: [FFmpeg-devel] [PATCH v2 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding

2023-05-31 Thread Zhanbang He
On Wednesday, May 31, 2023, Tong Wu 
wrote:

> From: Wu Jianhua 
>
> The implementation is based on:
> https://learn.microsoft.com/en-us/windows/win32/medfound/
> direct3d-12-video-overview
>
>

> With the Direct3D 12 video decoding support, we can render or process
> the decoded images by the pixel shaders or compute shaders directly

do you have some demo regarding pixel shaders or compute shaders?


> without the extra copy overhead, which is beneficial especially if you

are trying to render or post-process a 4K or 8K video.
>
> The command below is how to enable d3d12va:
> ffmpeg -hwaccel d3d12va -i input.mp4 output.mp4
>
> Signed-off-by: Wu Jianhua 
> Signed-off-by: Tong Wu 
> ---
>  configure   |   2 +
>  libavcodec/Makefile |   3 +
>  libavcodec/d3d11va.h|   3 -
>  libavcodec/d3d12va.c| 552 
>  libavcodec/d3d12va.h| 184 
>  libavcodec/d3d12va_h264.c   | 210 ++
>  libavcodec/dxva2.c  |  24 ++
>  libavcodec/dxva2.h  |   3 -
>  libavcodec/dxva2_h264.c |  12 +-
>  libavcodec/dxva2_internal.h |  69 +++--
>  libavcodec/h264_slice.c |   4 +
>  libavcodec/h264dec.c|   3 +
>  libavcodec/hwaccels.h   |   1 +
>  libavcodec/hwconfig.h   |   2 +
>  14 files changed, 1030 insertions(+), 42 deletions(-)
>  create mode 100644 libavcodec/d3d12va.c
>  create mode 100644 libavcodec/d3d12va.h
>  create mode 100644 libavcodec/d3d12va_h264.c
>
> diff --git a/configure b/configure
> index b86064e36f..f5dad4653f 100755
> --- a/configure
> +++ b/configure
> @@ -3033,6 +3033,8 @@ h264_d3d11va_hwaccel_deps="d3d11va"
>  h264_d3d11va_hwaccel_select="h264_decoder"
>  h264_d3d11va2_hwaccel_deps="d3d11va"
>  h264_d3d11va2_hwaccel_select="h264_decoder"
> +h264_d3d12va_hwaccel_deps="d3d12va"
> +h264_d3d12va_hwaccel_select="h264_decoder"
>  h264_dxva2_hwaccel_deps="dxva2"
>  h264_dxva2_hwaccel_select="h264_decoder"
>  h264_nvdec_hwaccel_deps="nvdec"
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 9aacc1d477..ae143d8821 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -977,6 +977,7 @@ OBJS-$(CONFIG_ADPCM_ZORK_DECODER) += adpcm.o
> adpcm_data.o
>
>  # hardware accelerators
>  OBJS-$(CONFIG_D3D11VA)+= dxva2.o
> +OBJS-$(CONFIG_D3D12VA)+= dxva2.o d3d12va.o
>  OBJS-$(CONFIG_DXVA2)  += dxva2.o
>  OBJS-$(CONFIG_NVDEC)  += nvdec.o
>  OBJS-$(CONFIG_VAAPI)  += vaapi_decode.o
> @@ -994,6 +995,7 @@ OBJS-$(CONFIG_H263_VAAPI_HWACCEL) +=
> vaapi_mpeg4.o
>  OBJS-$(CONFIG_H263_VIDEOTOOLBOX_HWACCEL)  += videotoolbox.o
>  OBJS-$(CONFIG_H264_D3D11VA_HWACCEL)   += dxva2_h264.o
>  OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o
> +OBJS-$(CONFIG_H264_D3D12VA_HWACCEL)   += dxva2_h264.o d3d12va_h264.o
>  OBJS-$(CONFIG_H264_NVDEC_HWACCEL) += nvdec_h264.o
>  OBJS-$(CONFIG_H264_QSV_HWACCEL)   += qsvdec.o
>  OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o
> @@ -1277,6 +1279,7 @@ SKIPHEADERS+=
> %_tablegen.h  \
>
>  SKIPHEADERS-$(CONFIG_AMF)  += amfenc.h
>  SKIPHEADERS-$(CONFIG_D3D11VA)  += d3d11va.h dxva2_internal.h
> +SKIPHEADERS-$(CONFIG_D3D12VA)  += d3d12va.h
>  SKIPHEADERS-$(CONFIG_DXVA2)+= dxva2.h dxva2_internal.h
>  SKIPHEADERS-$(CONFIG_JNI)  += ffjni.h
>  SKIPHEADERS-$(CONFIG_LCMS2)+= fflcms2.h
> diff --git a/libavcodec/d3d11va.h b/libavcodec/d3d11va.h
> index 6816b6c1e6..27f40e5519 100644
> --- a/libavcodec/d3d11va.h
> +++ b/libavcodec/d3d11va.h
> @@ -45,9 +45,6 @@
>   * @{
>   */
>
> -#define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work around for
> Direct3D11 and old UVD/UVD+ ATI video cards
> -#define FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO2 ///< Work around for
> Direct3D11 and old Intel GPUs with ClearVideo interface
> -
>  /**
>   * This structure is used to provides the necessary configurations and
> data
>   * to the Direct3D11 FFmpeg HWAccel implementation.
> diff --git a/libavcodec/d3d12va.c b/libavcodec/d3d12va.c
> new file mode 100644
> index 00..d80575441c
> --- /dev/null
> +++ b/libavcodec/d3d12va.c
> @@ -0,0 +1,552 @@
> +/*
> + * Direct3D 12 HW acceleration video decoder
> + *
> + * copyright (c) 2022-2023 Wu Jianhua 
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more