[FFmpeg-devel] [PATCH v2 2/3] libavformat/oggparseopus.c: Accept empty packets, decode metadata packets.
toots at rastageeks.org
toots at rastageeks.org
Fri May 5 16:28:49 EEST 2023
From: Romain Beauxis <toots at rastageeks.org>
This patch provides the same functionality as the previous patch but for
ogg/opus.
The need to accept empty packets on end of stream (EOS) is explained in the
final patch of the series.
---
libavformat/oggparseopus.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c
index 54aa725be6..7991e9db42 100644
--- a/libavformat/oggparseopus.c
+++ b/libavformat/oggparseopus.c
@@ -117,8 +117,9 @@ static int opus_packet(AVFormatContext *avf, int idx)
uint8_t *packet = os->buf + os->pstart;
int ret;
- if (!os->psize)
+ if (!os->psize && !(os->flags & OGG_FLAG_EOS))
return AVERROR_INVALIDDATA;
+
if (os->granule > (1LL << 62)) {
av_log(avf, AV_LOG_ERROR, "Unsupported huge granule pos %"PRId64 "\n", os->granule);
return AVERROR_INVALIDDATA;
@@ -152,14 +153,23 @@ static int opus_packet(AVFormatContext *avf, int idx)
os->lastdts = os->granule - duration;
}
- if ((ret = opus_duration(packet, os->psize)) < 0)
- return ret;
+ if (os->psize > 0) {
+ if ((ret = opus_duration(packet, os->psize)) < 0)
+ return ret;
+
+ os->pduration = ret;
+ if (os->lastpts != AV_NOPTS_VALUE) {
+ if (st->start_time == AV_NOPTS_VALUE)
+ st->start_time = os->lastpts;
+ priv->cur_dts = os->lastdts = os->lastpts -= priv->pre_skip;
+ }
+ }
- os->pduration = ret;
- if (os->lastpts != AV_NOPTS_VALUE) {
- if (st->start_time == AV_NOPTS_VALUE)
- st->start_time = os->lastpts;
- priv->cur_dts = os->lastdts = os->lastpts -= priv->pre_skip;
+ if (os->psize > 8 && !memcmp(os->buf + os->pstart, "OpusTags", 8)) {
+ av_dict_free(&st->metadata);
+ ret = ff_vorbis_stream_comment(avf, st, os->buf + os->pstart + 8,
+ os->psize - 8);
+ if (ret < 0) return ret;
}
priv->cur_dts += os->pduration;
--
2.37.1 (Apple Git-137.1)
More information about the ffmpeg-devel
mailing list