diff mbox

[FFmpeg-devel,1/1] Sega FILM: set dts and duration when demuxing

Message ID 20180409012725.90395-2-misty@brew.sh
State Accepted
Commit d64183ea5da9c5248578d0bc4ffcbeddfc6c3555
Headers show

Commit Message

misty@brew.sh April 9, 2018, 1:27 a.m. UTC
From: Misty De Meo <mistydemeo@gmail.com>

---
 libavformat/segafilm.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Kyle Swanson April 9, 2018, 11:11 p.m. UTC | #1
Hi,

On Sun, Apr 8, 2018 at 6:27 PM, <misty@brew.sh> wrote:

> From: Misty De Meo <mistydemeo@gmail.com>
>
> ---
>  libavformat/segafilm.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>
> diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c
> index 4c0cca0140..e72c26b144 100644
> --- a/libavformat/segafilm.c
> +++ b/libavformat/segafilm.c
> @@ -270,6 +270,8 @@ static int film_read_packet(AVFormatContext *s,
>      FilmDemuxContext *film = s->priv_data;
>      AVIOContext *pb = s->pb;
>      film_sample *sample;
> +    film_sample *next_sample = NULL;
> +    int next_sample_id;
>      int ret = 0;
>
>      if (film->current_sample >= film->sample_count)
> @@ -277,6 +279,20 @@ static int film_read_packet(AVFormatContext *s,
>
>      sample = &film->sample_table[film->current_sample];
>
> +    /* Find the next sample from the same stream, assuming there is one;
> +     * this is used to calculate the duration below */
> +    next_sample_id = film->current_sample + 1;
> +    while (next_sample == NULL) {
> +        if (next_sample_id >= film->sample_count)
> +            break;
> +
> +        next_sample = &film->sample_table[next_sample_id];
> +        if (next_sample->stream != sample->stream) {
> +            next_sample = NULL;
> +            next_sample_id++;
> +        }
> +    }
> +
>      /* position the stream (will probably be there anyway) */
>      avio_seek(pb, sample->sample_offset, SEEK_SET);
>
> @@ -285,8 +301,11 @@ static int film_read_packet(AVFormatContext *s,
>          ret = AVERROR(EIO);
>
>      pkt->stream_index = sample->stream;
> +    pkt->dts = sample->pts;
>      pkt->pts = sample->pts;
>      pkt->flags |= sample->keyframe ? AV_PKT_FLAG_KEY : 0;
> +    if (next_sample != NULL)
> +        pkt->duration = next_sample->pts - sample->pts;
>
>      film->current_sample++;
>
> --
> 2.17.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

lgtm
Michael Niedermayer April 10, 2018, 12:35 a.m. UTC | #2
On Mon, Apr 09, 2018 at 04:11:43PM -0700, Kyle Swanson wrote:
> Hi,
> 
> On Sun, Apr 8, 2018 at 6:27 PM, <misty@brew.sh> wrote:
> 
> > From: Misty De Meo <mistydemeo@gmail.com>
> >
> > ---
> >  libavformat/segafilm.c | 19 +++++++++++++++++++
> >  1 file changed, 19 insertions(+)
> >
> > diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c
> > index 4c0cca0140..e72c26b144 100644
> > --- a/libavformat/segafilm.c
> > +++ b/libavformat/segafilm.c
> > @@ -270,6 +270,8 @@ static int film_read_packet(AVFormatContext *s,
> >      FilmDemuxContext *film = s->priv_data;
> >      AVIOContext *pb = s->pb;
> >      film_sample *sample;
> > +    film_sample *next_sample = NULL;
> > +    int next_sample_id;
> >      int ret = 0;
> >
> >      if (film->current_sample >= film->sample_count)
> > @@ -277,6 +279,20 @@ static int film_read_packet(AVFormatContext *s,
> >
> >      sample = &film->sample_table[film->current_sample];
> >
> > +    /* Find the next sample from the same stream, assuming there is one;
> > +     * this is used to calculate the duration below */
> > +    next_sample_id = film->current_sample + 1;
> > +    while (next_sample == NULL) {
> > +        if (next_sample_id >= film->sample_count)
> > +            break;
> > +
> > +        next_sample = &film->sample_table[next_sample_id];
> > +        if (next_sample->stream != sample->stream) {
> > +            next_sample = NULL;
> > +            next_sample_id++;
> > +        }
> > +    }
> > +
> >      /* position the stream (will probably be there anyway) */
> >      avio_seek(pb, sample->sample_offset, SEEK_SET);
> >
> > @@ -285,8 +301,11 @@ static int film_read_packet(AVFormatContext *s,
> >          ret = AVERROR(EIO);
> >
> >      pkt->stream_index = sample->stream;
> > +    pkt->dts = sample->pts;
> >      pkt->pts = sample->pts;
> >      pkt->flags |= sample->keyframe ? AV_PKT_FLAG_KEY : 0;
> > +    if (next_sample != NULL)
> > +        pkt->duration = next_sample->pts - sample->pts;
> >
> >      film->current_sample++;
> >
> > --
> > 2.17.0
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> 
> lgtm

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c
index 4c0cca0140..e72c26b144 100644
--- a/libavformat/segafilm.c
+++ b/libavformat/segafilm.c
@@ -270,6 +270,8 @@  static int film_read_packet(AVFormatContext *s,
     FilmDemuxContext *film = s->priv_data;
     AVIOContext *pb = s->pb;
     film_sample *sample;
+    film_sample *next_sample = NULL;
+    int next_sample_id;
     int ret = 0;
 
     if (film->current_sample >= film->sample_count)
@@ -277,6 +279,20 @@  static int film_read_packet(AVFormatContext *s,
 
     sample = &film->sample_table[film->current_sample];
 
+    /* Find the next sample from the same stream, assuming there is one;
+     * this is used to calculate the duration below */
+    next_sample_id = film->current_sample + 1;
+    while (next_sample == NULL) {
+        if (next_sample_id >= film->sample_count)
+            break;
+
+        next_sample = &film->sample_table[next_sample_id];
+        if (next_sample->stream != sample->stream) {
+            next_sample = NULL;
+            next_sample_id++;
+        }
+    }
+
     /* position the stream (will probably be there anyway) */
     avio_seek(pb, sample->sample_offset, SEEK_SET);
 
@@ -285,8 +301,11 @@  static int film_read_packet(AVFormatContext *s,
         ret = AVERROR(EIO);
 
     pkt->stream_index = sample->stream;
+    pkt->dts = sample->pts;
     pkt->pts = sample->pts;
     pkt->flags |= sample->keyframe ? AV_PKT_FLAG_KEY : 0;
+    if (next_sample != NULL)
+        pkt->duration = next_sample->pts - sample->pts;
 
     film->current_sample++;