Re: [FFmpeg-devel] [PATCH 1/3] lavf/dv: do not set video timebase more than once

2023-04-27 Thread Anton Khirnov
Quoting Michael Niedermayer (2023-04-26 13:54:10)
> On Mon, Apr 24, 2023 at 05:55:51PM +0200, Anton Khirnov wrote:
> > Current code will call avpriv_set_pts_info() for each video frame,
> > possibly setting a different timebase if the stream framerate changes.
> > This violates API conventions, as the timebase is supposed to stay
> > constant after stream creation.
> > 
> > Change the demuxer to set a single timebase that is fine enough to
> > handle all supported DV framerates.
> > 
> > The seek tests change slightly because the new timebase is more
> > granular.
> > ---
> >  libavcodec/dv.h   |  3 +++
> >  libavformat/dv.c  | 25 -
> >  tests/ref/seek/lavf-dv| 16 
> >  tests/ref/seek/vsynth_lena-dv | 24 
> >  tests/ref/seek/vsynth_lena-dv-411 | 24 
> >  tests/ref/seek/vsynth_lena-dv-50  | 24 
> >  6 files changed, 67 insertions(+), 49 deletions(-)
> 
> This breaks:
> 
> ./ffmpeg -ss 4:56 -i ~/tickets/4086/Oca-Agu\ 1995.avi -codec copy -t 1 
> -bitexact 4086-30frames.dv
> (the file is empty after the patch)
> 
> The file seems no longer available on the original link and a little big
> ill put it in your home directory on the server probably in 30+min or so.
> once you are done with it please delete it off the server so it doesnt eat
> diskspace

Thank you, file downloaded and deleted.

Seems we do not have any FATE tests for dv in avi - do you (or anyone
else) have a reasonably small sample that can be used for that?

-- 
Anton Khirnov
___
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] lavf/dv: do not set video timebase more than once

2023-04-26 Thread Michael Niedermayer
On Mon, Apr 24, 2023 at 05:55:51PM +0200, Anton Khirnov wrote:
> Current code will call avpriv_set_pts_info() for each video frame,
> possibly setting a different timebase if the stream framerate changes.
> This violates API conventions, as the timebase is supposed to stay
> constant after stream creation.
> 
> Change the demuxer to set a single timebase that is fine enough to
> handle all supported DV framerates.
> 
> The seek tests change slightly because the new timebase is more
> granular.
> ---
>  libavcodec/dv.h   |  3 +++
>  libavformat/dv.c  | 25 -
>  tests/ref/seek/lavf-dv| 16 
>  tests/ref/seek/vsynth_lena-dv | 24 
>  tests/ref/seek/vsynth_lena-dv-411 | 24 
>  tests/ref/seek/vsynth_lena-dv-50  | 24 
>  6 files changed, 67 insertions(+), 49 deletions(-)

This breaks:

./ffmpeg -ss 4:56 -i ~/tickets/4086/Oca-Agu\ 1995.avi -codec copy -t 1 
-bitexact 4086-30frames.dv
(the file is empty after the patch)

The file seems no longer available on the original link and a little big
ill put it in your home directory on the server probably in 30+min or so.
once you are done with it please delete it off the server so it doesnt eat
diskspace

thx


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

What does censorship reveal? It reveals fear. -- Julian Assange


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".


[FFmpeg-devel] [PATCH 1/3] lavf/dv: do not set video timebase more than once

2023-04-24 Thread Anton Khirnov
Current code will call avpriv_set_pts_info() for each video frame,
possibly setting a different timebase if the stream framerate changes.
This violates API conventions, as the timebase is supposed to stay
constant after stream creation.

Change the demuxer to set a single timebase that is fine enough to
handle all supported DV framerates.

The seek tests change slightly because the new timebase is more
granular.
---
 libavcodec/dv.h   |  3 +++
 libavformat/dv.c  | 25 -
 tests/ref/seek/lavf-dv| 16 
 tests/ref/seek/vsynth_lena-dv | 24 
 tests/ref/seek/vsynth_lena-dv-411 | 24 
 tests/ref/seek/vsynth_lena-dv-50  | 24 
 6 files changed, 67 insertions(+), 49 deletions(-)

diff --git a/libavcodec/dv.h b/libavcodec/dv.h
index 29f97b6089a..b473bdc992d 100644
--- a/libavcodec/dv.h
+++ b/libavcodec/dv.h
@@ -60,6 +60,9 @@ enum DVPackType {
  */
 #define DV_MAX_FRAME_SIZE 576000
 
+// LCM of video framerate numerators
+#define DV_TIMESCALE_VIDEO 6
+
 /**
  * maximum number of blocks per macroblock in any DV format
  */
diff --git a/libavformat/dv.c b/libavformat/dv.c
index ffed1a7a90e..d30dc298805 100644
--- a/libavformat/dv.c
+++ b/libavformat/dv.c
@@ -69,6 +69,8 @@ struct DVDemuxContext {
 uint8_t   audio_buf[4][8192];
 int   ach;
 int   frames;
+
+int64_t   next_pts_video;
 };
 
 static inline uint16_t dv_audio_12to16(uint16_t sample)
@@ -314,8 +316,6 @@ static int dv_extract_video_info(DVDemuxContext *c, const 
uint8_t *frame)
 
 par = c->vst->codecpar;
 
-avpriv_set_pts_info(c->vst, 64, c->sys->time_base.num,
-c->sys->time_base.den);
 c->vst->avg_frame_rate = av_inv_q(c->vst->time_base);
 
 /* finding out SAR is a little bit messy */
@@ -360,6 +360,8 @@ static int dv_init_demux(AVFormatContext *s, DVDemuxContext 
*c)
 c->vst->codecpar->bit_rate   = 2500;
 c->vst->start_time= 0;
 
+avpriv_set_pts_info(c->vst, 64, 1, DV_TIMESCALE_VIDEO);
+
 /* Audio streams are added later as they are encountered. */
 s->ctx_flags |= AVFMTCTX_NOHEADER;
 
@@ -463,7 +465,10 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket 
*pkt,
 pkt->size = size;
 pkt->flags   |= AV_PKT_FLAG_KEY;
 pkt->stream_index = c->vst->index;
-pkt->pts  = c->frames;
+pkt->pts  = c->next_pts_video;
+pkt->duration = av_rescale_q(1, c->sys->time_base, 
c->vst->time_base);
+
+c->next_pts_video += pkt->duration;
 }
 
 c->frames++;
@@ -477,11 +482,12 @@ static int64_t dv_frame_offset(AVFormatContext *s, 
DVDemuxContext *c,
 // FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk)
 FFFormatContext *const si = ffformatcontext(s);
 const int frame_size = c->sys->frame_size;
+int64_t  frame_count = av_rescale_q(timestamp, c->vst->time_base, 
c->sys->time_base);
 int64_t offset;
 int64_t size   = avio_size(s->pb) - si->data_offset;
 int64_t max_offset = ((size - 1) / frame_size) * frame_size;
 
-offset = frame_size * timestamp;
+offset = frame_size * frame_count;
 
 if (size >= 0 && offset > max_offset)
 offset = max_offset;
@@ -494,6 +500,8 @@ static int64_t dv_frame_offset(AVFormatContext *s, 
DVDemuxContext *c,
 void ff_dv_offset_reset(DVDemuxContext *c, int64_t frame_offset)
 {
 c->frames = frame_offset;
+if (c->sys)
+c->next_pts_video = av_rescale_q(frame_offset, c->sys->time_base, 
c->vst->time_base);
 c->audio_pkt[0].size = c->audio_pkt[1].size = 0;
 c->audio_pkt[2].size = c->audio_pkt[3].size = 0;
 }
@@ -618,7 +626,14 @@ static int dv_read_seek(AVFormatContext *s, int 
stream_index,
 {
 RawDVContext *r   = s->priv_data;
 DVDemuxContext *c = >dv_demux;
-int64_t offset= dv_frame_offset(s, c, timestamp, flags);
+int64_t offset;
+
+// seek using the video stream
+if (stream_index != c->vst->index)
+timestamp = av_rescale_q(timestamp, 
s->streams[stream_index]->time_base,
+ c->vst->time_base);
+
+offset = dv_frame_offset(s, c, timestamp, flags);
 
 if (avio_seek(s->pb, offset, SEEK_SET) < 0)
 return -1;
diff --git a/tests/ref/seek/lavf-dv b/tests/ref/seek/lavf-dv
index f63e4460be6..95f19d28f03 100644
--- a/tests/ref/seek/lavf-dv
+++ b/tests/ref/seek/lavf-dv
@@ -3,9 +3,9 @@ ret: 0 st:-1 flags:0  ts:-1.00
 ret: 0 st: 0 flags:1 dts: 0.00 pts: 0.00 pos:  0 
size:144000
 ret: 0 st:-1 flags:1  ts: 1.894167
 ret: 0 st: 0 flags:1 dts: 0.96 pts: 0.96 pos:3456000 
size:144000
-ret: 0 st: 0 flags:0  ts: 0.80
+ret: 0 st: 0 flags:0  ts: 0.788333
 ret: 0 st: 0 flags:1 dts: 0.80 pts: 0.80 pos:288 
size:144000
-ret: 0