[FFmpeg-devel] avformat/yuv4mpegdec: simplify math

Submitted by Michael Niedermayer on May 1, 2018, 9:11 p.m.

Details

Message ID 20180501211120.GL20131@michaelspb
State Not Applicable
Headers show

Commit Message

Michael Niedermayer May 1, 2018, 9:11 p.m.
On Tue, May 01, 2018 at 05:48:32PM +0200, Paul B Mahol wrote:
> This one actually works with hd1080 y4m files when seeking backwards.
> 
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavformat/yuv4mpegdec.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/libavformat/yuv4mpegdec.c b/libavformat/yuv4mpegdec.c
> index 8662a42a4c..de3d5637fe 100644
> --- a/libavformat/yuv4mpegdec.c
> +++ b/libavformat/yuv4mpegdec.c
> @@ -317,11 +317,9 @@ static int yuv4_read_seek(AVFormatContext *s, int stream_index,
>      AVStream *st = s->streams[0];
>      int64_t pos;
>  
> -    pos = av_rescale_rnd(pts * s->packet_size,
> -                         st->time_base.num,
> -                         st->time_base.den * s->packet_size,
> -                         (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
> -    pos *= s->packet_size;
> +    if (flags & AVSEEK_FLAG_BACKWARD)
> +        pts -= 1;
> +    pos = pts * s->packet_size;
>  
>      if (avio_seek(s->pb, pos + s->internal->data_offset, SEEK_SET) < 0)
>          return -1;

breaks fate-seek-lavf-yuv4mpeg

Test seek-lavf-yuv4mpeg failed. Look at tests/data/fate/seek-lavf-yuv4mpeg.err for details.
make: *** [fate-seek-lavf-yuv4mpeg] Error 1

Comments

Paul B Mahol May 1, 2018, 9:15 p.m.
On 5/1/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
> On Tue, May 01, 2018 at 05:48:32PM +0200, Paul B Mahol wrote:
>> This one actually works with hd1080 y4m files when seeking backwards.
>>
>> Signed-off-by: Paul B Mahol <onemda@gmail.com>
>> ---
>>  libavformat/yuv4mpegdec.c | 8 +++-----
>>  1 file changed, 3 insertions(+), 5 deletions(-)
>>
>> diff --git a/libavformat/yuv4mpegdec.c b/libavformat/yuv4mpegdec.c
>> index 8662a42a4c..de3d5637fe 100644
>> --- a/libavformat/yuv4mpegdec.c
>> +++ b/libavformat/yuv4mpegdec.c
>> @@ -317,11 +317,9 @@ static int yuv4_read_seek(AVFormatContext *s, int
>> stream_index,
>>      AVStream *st = s->streams[0];
>>      int64_t pos;
>>
>> -    pos = av_rescale_rnd(pts * s->packet_size,
>> -                         st->time_base.num,
>> -                         st->time_base.den * s->packet_size,
>> -                         (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN :
>> AV_ROUND_UP);
>> -    pos *= s->packet_size;
>> +    if (flags & AVSEEK_FLAG_BACKWARD)
>> +        pts -= 1;
>> +    pos = pts * s->packet_size;
>>
>>      if (avio_seek(s->pb, pos + s->internal->data_offset, SEEK_SET) < 0)
>>          return -1;
>
> breaks fate-seek-lavf-yuv4mpeg
>

If you have no other remarks, I will update reference and push patch.
Derek Buitenhuis May 1, 2018, 9:43 p.m.
On 5/1/2018 10:15 PM, Paul B Mahol wrote:
> If you have no other remarks, I will update reference and push patch.

Is the reference change actually correct?

- Derek
Paul B Mahol May 1, 2018, 9:57 p.m.
On 5/1/18, Derek Buitenhuis <derek.buitenhuis@gmail.com> wrote:
> On 5/1/2018 10:15 PM, Paul B Mahol wrote:
>> If you have no other remarks, I will update reference and push patch.
>
> Is the reference change actually correct?

Yes, I tested extensively with mpv.

mpv have option to disable fix pts algo so brokeness came noticed just now.

Patch hide | download patch | download mbox

--- ./tests/ref/seek/lavf-yuv4mpeg	2018-05-01 18:09:16.499128665 +0200
+++ tests/data/fate/seek-lavf-yuv4mpeg	2018-05-01 23:04:43.039052762 +0200
@@ -1,48 +1,45 @@ 
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     64 size:152064
 ret:-1         st:-1 flags:0  ts:-1.000000
 ret: 0         st:-1 flags:1  ts: 1.894167
-ret: 0         st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
+ret:-EOF
 ret: 0         st: 0 flags:0  ts: 0.800000
-ret: 0         st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
+ret: 0         st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos:3041464 size:152064
 ret:-1         st: 0 flags:1  ts:-0.320000
 ret: 0         st:-1 flags:0  ts: 2.576668
-ret: 0         st: 0 flags:1 dts: 0.120000 pts: 0.120000 pos: 456274 size:152064
+ret:-EOF
 ret: 0         st:-1 flags:1  ts: 1.470835
-ret: 0         st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
+ret:-EOF
 ret: 0         st: 0 flags:0  ts: 0.360000
-ret: 0         st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
+ret: 0         st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:1368694 size:152064
 ret:-1         st: 0 flags:1  ts:-0.760000
 ret: 0         st:-1 flags:0  ts: 2.153336
-ret: 0         st: 0 flags:1 dts: 0.120000 pts: 0.120000 pos: 456274 size:152064
+ret:-EOF
 ret: 0         st:-1 flags:1  ts: 1.047503
-ret: 0         st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
-ret: 0         st: 0 flags:0  ts:-0.040000
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     64 size:152064
+ret:-EOF
+ret:-1         st: 0 flags:0  ts:-0.040000
 ret: 0         st: 0 flags:1  ts: 2.840000
-ret: 0         st: 0 flags:1 dts: 0.080000 pts: 0.080000 pos: 304204 size:152064
+ret:-EOF
 ret: 0         st:-1 flags:0  ts: 1.730004
-ret: 0         st: 0 flags:1 dts: 0.080000 pts: 0.080000 pos: 304204 size:152064
+ret:-EOF
 ret: 0         st:-1 flags:1  ts: 0.624171
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     64 size:152064
-ret: 0         st: 0 flags:0  ts:-0.480000
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     64 size:152064
+ret: 0         st: 0 flags:1 dts: 0.600000 pts: 0.600000 pos:2281114 size:152064
+ret:-1         st: 0 flags:0  ts:-0.480000
 ret: 0         st: 0 flags:1  ts: 2.400000
-ret: 0         st: 0 flags:1 dts: 0.080000 pts: 0.080000 pos: 304204 size:152064
+ret:-EOF
 ret: 0         st:-1 flags:0  ts: 1.306672
-ret: 0         st: 0 flags:1 dts: 0.080000 pts: 0.080000 pos: 304204 size:152064
+ret:-EOF
 ret: 0         st:-1 flags:1  ts: 0.200839
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     64 size:152064
-ret: 0         st: 0 flags:0  ts:-0.920000
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     64 size:152064
+ret: 0         st: 0 flags:1 dts: 0.160000 pts: 0.160000 pos: 608344 size:152064
+ret:-1         st: 0 flags:0  ts:-0.920000
 ret: 0         st: 0 flags:1  ts: 2.000000
-ret: 0         st: 0 flags:1 dts: 0.080000 pts: 0.080000 pos: 304204 size:152064
+ret:-EOF
 ret: 0         st:-1 flags:0  ts: 0.883340
-ret: 0         st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
+ret: 0         st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos:3345604 size:152064
 ret:-1         st:-1 flags:1  ts:-0.222493
 ret: 0         st: 0 flags:0  ts: 2.680000
-ret: 0         st: 0 flags:1 dts: 0.120000 pts: 0.120000 pos: 456274 size:152064
+ret:-EOF
 ret: 0         st: 0 flags:1  ts: 1.560000
-ret: 0         st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
+ret:-EOF
 ret: 0         st:-1 flags:0  ts: 0.460008
-ret: 0         st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:1824904 size:152064
 ret:-1         st:-1 flags:1  ts:-0.645825