* [FFmpeg-devel] [PATCH] avformat/oggparsevorbis: Fix oggvorbis duration parsing for small files
@ 2022-05-05 23:04 Guangyu Sun
2022-05-09 18:19 ` Guangyu Sun
0 siblings, 1 reply; 4+ messages in thread
From: Guangyu Sun @ 2022-05-05 23:04 UTC (permalink / raw)
To: ffmpeg-devel
The decoded Data is not returned from the first frame; it must be used
to 'prime' the decode engine. The duration of the first packet should
be ignored also by the container, to make sure the total duration is
trimmed correctly.
If the file has multiple pages for the data packets. The duration of the
last packet can be correctly adjusted without being affected by the first
packet. But if the first packet and the last packet are located in the
same page, the duration of the last packet will have an unwanted offset.
This commit fixes https://trac.ffmpeg.org/ticket/6367.
dd if=/dev/zero of=./silence.raw count=1 bs=500
oggenc --raw silence.raw --output=silence.ogg
oggdec --raw --output silence.oggdec.raw silence.ogg
ffmpeg -codec:a libvorbis -i silence.ogg -f s16le -codec:a pcm_s16le silence.libvorbis.ffmpeg.raw
ffmpeg -i silence.ogg -f s16le -codec:a pcm_s16le silence.native.ffmpeg.raw
ls -l *.raw
Signed-off-by: Guangyu Sun <gsun@roblox.com>
---
libavformat/oggparsevorbis.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index 289900f7cf..9a486c9fe8 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -412,6 +412,7 @@ static int vorbis_packet(AVFormatContext *s, int idx)
struct ogg_stream *os = ogg->streams + idx;
struct oggvorbis_private *priv = os->private;
int duration, flags = 0;
+ int first_page;
if (!priv->vp)
return AVERROR_INVALIDDATA;
@@ -420,7 +421,8 @@ static int vorbis_packet(AVFormatContext *s, int idx)
* here we parse the duration of each packet in the first page and compare
* the total duration to the page granule to find the encoder delay and
* set the first timestamp */
- if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags & OGG_FLAG_EOS) && (int64_t)os->granule>=0) {
+ first_page = !os->lastpts || os->lastpts == AV_NOPTS_VALUE;
+ if (first_page && !(os->flags & OGG_FLAG_EOS) && (int64_t)os->granule>=0) {
int seg, d;
uint8_t *last_pkt = os->buf + os->pstart;
uint8_t *next_pkt = last_pkt;
@@ -479,6 +481,13 @@ static int vorbis_packet(AVFormatContext *s, int idx)
flags = 0;
}
os->pduration = duration;
+ /* Data is not returned from the first frame; it must be used to 'prime'
+ * the decode engine. The duration of the first packet should be ignored
+ * also by the container, to make sure the total duration is trimmed
+ * correctly.
+ */
+ if (first_page && os->segp == 1)
+ os->pduration = 0;
}
/* final packet handling
--
2.30.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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/oggparsevorbis: Fix oggvorbis duration parsing for small files
2022-05-05 23:04 [FFmpeg-devel] [PATCH] avformat/oggparsevorbis: Fix oggvorbis duration parsing for small files Guangyu Sun
@ 2022-05-09 18:19 ` Guangyu Sun
2022-05-17 0:05 ` Guangyu Sun
0 siblings, 1 reply; 4+ messages in thread
From: Guangyu Sun @ 2022-05-09 18:19 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Thu, May 5, 2022 at 4:05 PM Guangyu Sun <sunguangyucn@gmail.com> wrote:
> The decoded Data is not returned from the first frame; it must be used
> to 'prime' the decode engine. The duration of the first packet should
> be ignored also by the container, to make sure the total duration is
> trimmed correctly.
>
> If the file has multiple pages for the data packets. The duration of the
> last packet can be correctly adjusted without being affected by the first
> packet. But if the first packet and the last packet are located in the
> same page, the duration of the last packet will have an unwanted offset.
>
> This commit fixes https://trac.ffmpeg.org/ticket/6367.
>
> dd if=/dev/zero of=./silence.raw count=1 bs=500
> oggenc --raw silence.raw --output=silence.ogg
> oggdec --raw --output silence.oggdec.raw silence.ogg
> ffmpeg -codec:a libvorbis -i silence.ogg -f s16le -codec:a pcm_s16le
> silence.libvorbis.ffmpeg.raw
> ffmpeg -i silence.ogg -f s16le -codec:a pcm_s16le silence.native.ffmpeg.raw
> ls -l *.raw
>
> Signed-off-by: Guangyu Sun <gsun@roblox.com>
> ---
> libavformat/oggparsevorbis.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
> index 289900f7cf..9a486c9fe8 100644
> --- a/libavformat/oggparsevorbis.c
> +++ b/libavformat/oggparsevorbis.c
> @@ -412,6 +412,7 @@ static int vorbis_packet(AVFormatContext *s, int idx)
> struct ogg_stream *os = ogg->streams + idx;
> struct oggvorbis_private *priv = os->private;
> int duration, flags = 0;
> + int first_page;
>
> if (!priv->vp)
> return AVERROR_INVALIDDATA;
> @@ -420,7 +421,8 @@ static int vorbis_packet(AVFormatContext *s, int idx)
> * here we parse the duration of each packet in the first page and
> compare
> * the total duration to the page granule to find the encoder delay
> and
> * set the first timestamp */
> - if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags &
> OGG_FLAG_EOS) && (int64_t)os->granule>=0) {
> + first_page = !os->lastpts || os->lastpts == AV_NOPTS_VALUE;
> + if (first_page && !(os->flags & OGG_FLAG_EOS) &&
> (int64_t)os->granule>=0) {
> int seg, d;
> uint8_t *last_pkt = os->buf + os->pstart;
> uint8_t *next_pkt = last_pkt;
> @@ -479,6 +481,13 @@ static int vorbis_packet(AVFormatContext *s, int idx)
> flags = 0;
> }
> os->pduration = duration;
> + /* Data is not returned from the first frame; it must be used to
> 'prime'
> + * the decode engine. The duration of the first packet should be
> ignored
> + * also by the container, to make sure the total duration is
> trimmed
> + * correctly.
> + */
> + if (first_page && os->segp == 1)
> + os->pduration = 0;
> }
>
> /* final packet handling
> --
> 2.30.1
>
>
Ping.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/oggparsevorbis: Fix oggvorbis duration parsing for small files
2022-05-09 18:19 ` Guangyu Sun
@ 2022-05-17 0:05 ` Guangyu Sun
2022-06-16 23:22 ` Guangyu Sun
0 siblings, 1 reply; 4+ messages in thread
From: Guangyu Sun @ 2022-05-17 0:05 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Mon, May 9, 2022 at 11:19 AM Guangyu Sun <sunguangyucn@gmail.com> wrote:
> On Thu, May 5, 2022 at 4:05 PM Guangyu Sun <sunguangyucn@gmail.com> wrote:
>
>> The decoded Data is not returned from the first frame; it must be used
>> to 'prime' the decode engine. The duration of the first packet should
>> be ignored also by the container, to make sure the total duration is
>> trimmed correctly.
>>
>> If the file has multiple pages for the data packets. The duration of the
>> last packet can be correctly adjusted without being affected by the first
>> packet. But if the first packet and the last packet are located in the
>> same page, the duration of the last packet will have an unwanted offset.
>>
>> This commit fixes https://trac.ffmpeg.org/ticket/6367.
>>
>> dd if=/dev/zero of=./silence.raw count=1 bs=500
>> oggenc --raw silence.raw --output=silence.ogg
>> oggdec --raw --output silence.oggdec.raw silence.ogg
>> ffmpeg -codec:a libvorbis -i silence.ogg -f s16le -codec:a pcm_s16le
>> silence.libvorbis.ffmpeg.raw
>> ffmpeg -i silence.ogg -f s16le -codec:a pcm_s16le
>> silence.native.ffmpeg.raw
>> ls -l *.raw
>>
>> Signed-off-by: Guangyu Sun <gsun@roblox.com>
>> ---
>> libavformat/oggparsevorbis.c | 11 ++++++++++-
>> 1 file changed, 10 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
>> index 289900f7cf..9a486c9fe8 100644
>> --- a/libavformat/oggparsevorbis.c
>> +++ b/libavformat/oggparsevorbis.c
>> @@ -412,6 +412,7 @@ static int vorbis_packet(AVFormatContext *s, int idx)
>> struct ogg_stream *os = ogg->streams + idx;
>> struct oggvorbis_private *priv = os->private;
>> int duration, flags = 0;
>> + int first_page;
>>
>> if (!priv->vp)
>> return AVERROR_INVALIDDATA;
>> @@ -420,7 +421,8 @@ static int vorbis_packet(AVFormatContext *s, int idx)
>> * here we parse the duration of each packet in the first page and
>> compare
>> * the total duration to the page granule to find the encoder delay
>> and
>> * set the first timestamp */
>> - if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags &
>> OGG_FLAG_EOS) && (int64_t)os->granule>=0) {
>> + first_page = !os->lastpts || os->lastpts == AV_NOPTS_VALUE;
>> + if (first_page && !(os->flags & OGG_FLAG_EOS) &&
>> (int64_t)os->granule>=0) {
>> int seg, d;
>> uint8_t *last_pkt = os->buf + os->pstart;
>> uint8_t *next_pkt = last_pkt;
>> @@ -479,6 +481,13 @@ static int vorbis_packet(AVFormatContext *s, int idx)
>> flags = 0;
>> }
>> os->pduration = duration;
>> + /* Data is not returned from the first frame; it must be used to
>> 'prime'
>> + * the decode engine. The duration of the first packet should be
>> ignored
>> + * also by the container, to make sure the total duration is
>> trimmed
>> + * correctly.
>> + */
>> + if (first_page && os->segp == 1)
>> + os->pduration = 0;
>> }
>>
>> /* final packet handling
>> --
>> 2.30.1
>>
>>
> Ping.
>
Ping again. This patch fixes an oggvorbis transcode issue.
https://devforum.roblox.com/t/recent-changes-to-uploaded-audio-compressionprocessing-causing-timing-drift/1735440/10
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/oggparsevorbis: Fix oggvorbis duration parsing for small files
2022-05-17 0:05 ` Guangyu Sun
@ 2022-06-16 23:22 ` Guangyu Sun
0 siblings, 0 replies; 4+ messages in thread
From: Guangyu Sun @ 2022-06-16 23:22 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Mon, May 16, 2022 at 5:05 PM Guangyu Sun <sunguangyucn@gmail.com> wrote:
>
> On Mon, May 9, 2022 at 11:19 AM Guangyu Sun <sunguangyucn@gmail.com> wrote:
>
> > On Thu, May 5, 2022 at 4:05 PM Guangyu Sun <sunguangyucn@gmail.com> wrote:
> >
> >> The decoded Data is not returned from the first frame; it must be used
> >> to 'prime' the decode engine. The duration of the first packet should
> >> be ignored also by the container, to make sure the total duration is
> >> trimmed correctly.
> >>
> >> If the file has multiple pages for the data packets. The duration of the
> >> last packet can be correctly adjusted without being affected by the first
> >> packet. But if the first packet and the last packet are located in the
> >> same page, the duration of the last packet will have an unwanted offset.
> >>
> >> This commit fixes https://trac.ffmpeg.org/ticket/6367.
> >>
> >> dd if=/dev/zero of=./silence.raw count=1 bs=500
> >> oggenc --raw silence.raw --output=silence.ogg
> >> oggdec --raw --output silence.oggdec.raw silence.ogg
> >> ffmpeg -codec:a libvorbis -i silence.ogg -f s16le -codec:a pcm_s16le
> >> silence.libvorbis.ffmpeg.raw
> >> ffmpeg -i silence.ogg -f s16le -codec:a pcm_s16le
> >> silence.native.ffmpeg.raw
> >> ls -l *.raw
> >>
> >> Signed-off-by: Guangyu Sun <gsun@roblox.com>
> >> ---
> >> libavformat/oggparsevorbis.c | 11 ++++++++++-
> >> 1 file changed, 10 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
> >> index 289900f7cf..9a486c9fe8 100644
> >> --- a/libavformat/oggparsevorbis.c
> >> +++ b/libavformat/oggparsevorbis.c
> >> @@ -412,6 +412,7 @@ static int vorbis_packet(AVFormatContext *s, int idx)
> >> struct ogg_stream *os = ogg->streams + idx;
> >> struct oggvorbis_private *priv = os->private;
> >> int duration, flags = 0;
> >> + int first_page;
> >>
> >> if (!priv->vp)
> >> return AVERROR_INVALIDDATA;
> >> @@ -420,7 +421,8 @@ static int vorbis_packet(AVFormatContext *s, int idx)
> >> * here we parse the duration of each packet in the first page and
> >> compare
> >> * the total duration to the page granule to find the encoder delay
> >> and
> >> * set the first timestamp */
> >> - if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags &
> >> OGG_FLAG_EOS) && (int64_t)os->granule>=0) {
> >> + first_page = !os->lastpts || os->lastpts == AV_NOPTS_VALUE;
> >> + if (first_page && !(os->flags & OGG_FLAG_EOS) &&
> >> (int64_t)os->granule>=0) {
> >> int seg, d;
> >> uint8_t *last_pkt = os->buf + os->pstart;
> >> uint8_t *next_pkt = last_pkt;
> >> @@ -479,6 +481,13 @@ static int vorbis_packet(AVFormatContext *s, int idx)
> >> flags = 0;
> >> }
> >> os->pduration = duration;
> >> + /* Data is not returned from the first frame; it must be used to
> >> 'prime'
> >> + * the decode engine. The duration of the first packet should be
> >> ignored
> >> + * also by the container, to make sure the total duration is
> >> trimmed
> >> + * correctly.
> >> + */
> >> + if (first_page && os->segp == 1)
> >> + os->pduration = 0;
> >> }
> >>
> >> /* final packet handling
> >> --
> >> 2.30.1
> >>
> >>
> > Ping.
> >
> Ping again. This patch fixes an oggvorbis transcode issue.
> https://devforum.roblox.com/t/recent-changes-to-uploaded-audio-compressionprocessing-causing-timing-drift/1735440/10
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Ping. Any feedback about this patch?
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-06-16 23:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-05 23:04 [FFmpeg-devel] [PATCH] avformat/oggparsevorbis: Fix oggvorbis duration parsing for small files Guangyu Sun
2022-05-09 18:19 ` Guangyu Sun
2022-05-17 0:05 ` Guangyu Sun
2022-06-16 23:22 ` Guangyu Sun
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git