[PATCH 0/2] Pass Xing gapless metadata to users during mp3 parsing
These patches expose the encoder delay/padding parsed from an mp3's Xing header to users of lavc/lavf, and show gapless info in the stream summary string. Jon Toohill (2): lavf/mp3dec: pass Xing gapless metadata to AVCodecParameters lavc: show gapless info in stream summary libavcodec/avcodec.h | 11 +++++++++++ libavcodec/utils.c | 38 ++++++++++++++++++++++---------------- libavformat/mp3dec.c | 2 ++ 3 files changed, 35 insertions(+), 16 deletions(-) -- 2.8.0.rc3.226.g39d4020
From: Jon Toohill <jon.toohill@gmail.com> --- libavformat/mp3dec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 3725d67..192f5ef 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -234,6 +234,8 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, mp3->start_pad = v>>12; mp3-> end_pad = v&4095; + st->codecpar->initial_padding = mp3->start_pad; + st->codecpar->trailing_padding = mp3->end_pad; st->start_skip_samples = mp3->start_pad + 528 + 1; if (mp3->frames) { st->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf; -- 2.8.0.rc3.226.g39d4020
From: Jon Toohill <jon.toohill@gmail.com> Also adds trailing_padding to AVCodecContext to match AVCodecParameters so that it doesn't get lost when mapping between them. --- libavcodec/avcodec.h | 11 +++++++++++ libavcodec/utils.c | 38 ++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 9ec9adf..408efe1 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3321,6 +3321,17 @@ typedef struct AVCodecContext { int initial_padding; /** + * Audio only. The amount of padding (in samples) appended by the encoder to + * the end of the audio. I.e. this number of decoded samples must be + * discarded by the caller from the end of the stream to get the original + * audio without any trailing padding. + * + * - decoding: unused + * - encoding: unused + */ + int trailing_padding; + + /** * - decoding: For codecs that store a framerate value in the compressed * bitstream, the decoder may export it here. { 0, 1} when * unknown. diff --git a/libavcodec/utils.c b/libavcodec/utils.c index e5a832b..51f50b0 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -3251,6 +3251,10 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) && enc->bits_per_raw_sample != av_get_bytes_per_sample(enc->sample_fmt) * 8) snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%d bit)", enc->bits_per_raw_sample); + if (enc->initial_padding || enc->trailing_padding) { + snprintf(buf + strlen(buf), buf_size - strlen(buf), + ", delay %d, padding %d", enc->initial_padding, enc->trailing_padding); + } break; case AVMEDIA_TYPE_DATA: if (av_log_get_level() >= AV_LOG_DEBUG) { @@ -4094,14 +4098,15 @@ int avcodec_parameters_from_context(AVCodecParameters *par, par->video_delay = codec->has_b_frames; break; case AVMEDIA_TYPE_AUDIO: - par->format = codec->sample_fmt; - par->channel_layout = codec->channel_layout; - par->channels = codec->channels; - par->sample_rate = codec->sample_rate; - par->block_align = codec->block_align; - par->frame_size = codec->frame_size; - par->initial_padding = codec->initial_padding; - par->seek_preroll = codec->seek_preroll; + par->format = codec->sample_fmt; + par->channel_layout = codec->channel_layout; + par->channels = codec->channels; + par->sample_rate = codec->sample_rate; + par->block_align = codec->block_align; + par->frame_size = codec->frame_size; + par->initial_padding = codec->initial_padding; + par->trailing_padding = codec->trailing_padding; + par->seek_preroll = codec->seek_preroll; break; case AVMEDIA_TYPE_SUBTITLE: par->width = codec->width; @@ -4148,14 +4153,15 @@ int avcodec_parameters_to_context(AVCodecContext *codec, codec->has_b_frames = par->video_delay; break; case AVMEDIA_TYPE_AUDIO: - codec->sample_fmt = par->format; - codec->channel_layout = par->channel_layout; - codec->channels = par->channels; - codec->sample_rate = par->sample_rate; - codec->block_align = par->block_align; - codec->frame_size = par->frame_size; - codec->initial_padding = par->initial_padding; - codec->seek_preroll = par->seek_preroll; + codec->sample_fmt = par->format; + codec->channel_layout = par->channel_layout; + codec->channels = par->channels; + codec->sample_rate = par->sample_rate; + codec->block_align = par->block_align; + codec->frame_size = par->frame_size; + codec->initial_padding = par->initial_padding; + codec->trailing_padding = par->trailing_padding; + codec->seek_preroll = par->seek_preroll; break; case AVMEDIA_TYPE_SUBTITLE: codec->width = par->width; -- 2.8.0.rc3.226.g39d4020
On Tue, May 24, 2016 at 03:52:49PM -0700, Jon Toohill wrote:
From: Jon Toohill <jon.toohill@gmail.com>
Also adds trailing_padding to AVCodecContext to match AVCodecParameters so that it doesn't get lost when mapping between them. --- libavcodec/avcodec.h | 11 +++++++++++ libavcodec/utils.c | 38 ++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 9ec9adf..408efe1 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3321,6 +3321,17 @@ typedef struct AVCodecContext { int initial_padding;
/** + * Audio only. The amount of padding (in samples) appended by the encoder to + * the end of the audio. I.e. this number of decoded samples must be + * discarded by the caller from the end of the stream to get the original + * audio without any trailing padding. + * + * - decoding: unused + * - encoding: unused + */ + int trailing_padding; + + /**
new fields must be added at the end to avoid breaking ABI also minor version has to be bumped and an entry should be added to doc/APIchanges [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Into a blind darkness they enter who follow after the Ignorance, they as if into a greater darkness enter who devote themselves to the Knowledge alone. -- Isha Upanishad
Forgot to fix the author line in those patches, it should read "Jon Toohill <jtoohill@google.com>" instead. I can fix it when sending updated patches if there are revisions to make, otherwise can you change it before merging (or should I send updated patches)? Jon Toohill | Google Play Music | jtoohill@google.com | (650) 215-0770 On Tue, May 24, 2016 at 3:52 PM, Jon Toohill <jtoohill@google.com> wrote:
These patches expose the encoder delay/padding parsed from an mp3's Xing header to users of lavc/lavf, and show gapless info in the stream summary string.
Jon Toohill (2): lavf/mp3dec: pass Xing gapless metadata to AVCodecParameters lavc: show gapless info in stream summary
libavcodec/avcodec.h | 11 +++++++++++ libavcodec/utils.c | 38 ++++++++++++++++++++++---------------- libavformat/mp3dec.c | 2 ++ 3 files changed, 35 insertions(+), 16 deletions(-)
-- 2.8.0.rc3.226.g39d4020
These patches expose the encoder delay/padding parsed from an mp3's Xing header to users of lavc/lavf, and show gapless info in the stream summary string. Jon Toohill (2): lavf/mp3dec: pass Xing gapless metadata to AVCodecParameters lavc: show gapless info in stream summary doc/APIchanges | 4 ++++ libavcodec/avcodec.h | 11 +++++++++++ libavcodec/utils.c | 38 ++++++++++++++++++++++---------------- libavcodec/version.h | 2 +- libavformat/mp3dec.c | 2 ++ 5 files changed, 40 insertions(+), 17 deletions(-) -- 2.8.0.rc3.226.g39d4020
--- libavformat/mp3dec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 3725d67..192f5ef 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -234,6 +234,8 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, mp3->start_pad = v>>12; mp3-> end_pad = v&4095; + st->codecpar->initial_padding = mp3->start_pad; + st->codecpar->trailing_padding = mp3->end_pad; st->start_skip_samples = mp3->start_pad + 528 + 1; if (mp3->frames) { st->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf; -- 2.8.0.rc3.226.g39d4020
On 5/25/2016 1:56 PM, Jon Toohill wrote:
--- libavformat/mp3dec.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 3725d67..192f5ef 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -234,6 +234,8 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st,
mp3->start_pad = v>>12; mp3-> end_pad = v&4095; + st->codecpar->initial_padding = mp3->start_pad; + st->codecpar->trailing_padding = mp3->end_pad;
Every other format so far is using the AV_PKT_DATA_SKIP_SAMPLES side data to discard samples from the last packet/frame. See matroska and ogg demuxers, currently used for Opus only. The trailing_padding AVCodecParameters element was added after the above was designed. To be honest i can't say if we should replace one with the other or find a way to keep both, and seeing how AVCodecParameters hasn't made it to a release yet, we're still on time to choose.
st->start_skip_samples = mp3->start_pad + 528 + 1; if (mp3->frames) { st->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf;
Hi, On Wed, May 25, 2016 at 1:24 PM, James Almer <jamrial@gmail.com> wrote:
On 5/25/2016 1:56 PM, Jon Toohill wrote:
--- libavformat/mp3dec.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 3725d67..192f5ef 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -234,6 +234,8 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st,
mp3->start_pad = v>>12; mp3-> end_pad = v&4095; + st->codecpar->initial_padding = mp3->start_pad; + st->codecpar->trailing_padding = mp3->end_pad;
Every other format so far is using the AV_PKT_DATA_SKIP_SAMPLES side data to discard samples from the last packet/frame. See matroska and ogg demuxers, currently used for Opus only.
The trailing_padding AVCodecParameters element was added after the above was designed. To be honest i can't say if we should replace one with the other or find a way to keep both, and seeing how AVCodecParameters hasn't made it to a release yet, we're still on time to choose.
I agree having 1 is better than having 2. I can't technically comment on which one is better/easier/*. Ronald
On Wed, May 25, 2016 at 02:18:38PM -0400, Ronald S. Bultje wrote:
Hi,
On Wed, May 25, 2016 at 1:24 PM, James Almer <jamrial@gmail.com> wrote:
On 5/25/2016 1:56 PM, Jon Toohill wrote:
--- libavformat/mp3dec.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 3725d67..192f5ef 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -234,6 +234,8 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st,
mp3->start_pad = v>>12; mp3-> end_pad = v&4095; + st->codecpar->initial_padding = mp3->start_pad; + st->codecpar->trailing_padding = mp3->end_pad;
Every other format so far is using the AV_PKT_DATA_SKIP_SAMPLES side data to discard samples from the last packet/frame. See matroska and ogg demuxers, currently used for Opus only.
The trailing_padding AVCodecParameters element was added after the above was designed. To be honest i can't say if we should replace one with the other or find a way to keep both, and seeing how AVCodecParameters hasn't made it to a release yet, we're still on time to choose.
I agree having 1 is better than having 2. I can't technically comment on which one is better/easier/*.
mp3 supports AV_PKT_DATA_SKIP_SAMPLES since FFmpeg 2.5 ogg opus sets codecpar->initial_padding like this patch would so does dtshddec and matroskadec AV_PKT_DATA_SKIP_SAMPLES is not a substitute for setting trailing_padding because with AV_PKT_DATA_SKIP_SAMPLES the trailing_padding only becomes available at the end of the stream also theres nothing wrong with AV_PKT_DATA_SKIP_SAMPLES, its local information for the current packet and there may indeed be cases like with concatenated streams where there are packets in the middle with discarding. So the 2 AVCodecParameters fields are not a substitute for AV_PKT_DATA_SKIP_SAMPLES also for encoding AV_PKT_DATA_SKIP_SAMPLES does not work with some formats the trailing_padding is needed to be known when writing the header the patch does look like a reasonable step to me but i might be missing something [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I am the wisest man alive, for I know one thing, and that is that I know nothing. -- Socrates
On 5/26/2016 11:05 PM, Michael Niedermayer wrote:
On Wed, May 25, 2016 at 02:18:38PM -0400, Ronald S. Bultje wrote:
Hi,
On Wed, May 25, 2016 at 1:24 PM, James Almer <jamrial@gmail.com> wrote:
On 5/25/2016 1:56 PM, Jon Toohill wrote:
--- libavformat/mp3dec.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 3725d67..192f5ef 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -234,6 +234,8 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st,
mp3->start_pad = v>>12; mp3-> end_pad = v&4095; + st->codecpar->initial_padding = mp3->start_pad; + st->codecpar->trailing_padding = mp3->end_pad;
Every other format so far is using the AV_PKT_DATA_SKIP_SAMPLES side data to discard samples from the last packet/frame. See matroska and ogg demuxers, currently used for Opus only.
The trailing_padding AVCodecParameters element was added after the above was designed. To be honest i can't say if we should replace one with the other or find a way to keep both, and seeing how AVCodecParameters hasn't made it to a release yet, we're still on time to choose.
I agree having 1 is better than having 2. I can't technically comment on which one is better/easier/*.
mp3 supports AV_PKT_DATA_SKIP_SAMPLES since FFmpeg 2.5 ogg opus sets codecpar->initial_padding like this patch would so does dtshddec and matroskadec
AV_PKT_DATA_SKIP_SAMPLES is not a substitute for setting trailing_padding because with AV_PKT_DATA_SKIP_SAMPLES the trailing_padding only becomes available at the end of the stream
also theres nothing wrong with AV_PKT_DATA_SKIP_SAMPLES, its local information for the current packet and there may indeed be cases like with concatenated streams where there are packets in the middle with discarding. So the 2 AVCodecParameters fields are not a substitute for AV_PKT_DATA_SKIP_SAMPLES
Fine with me, then. I assumed both both were pretty much made for the same purpose and to cover the same use cases.
also for encoding AV_PKT_DATA_SKIP_SAMPLES does not work with some formats the trailing_padding is needed to be known when writing the header
The one format i know should be using AV_PKT_DATA_SKIP_SAMPLES the same way as ogg and matroska is mpegts. Probably also mp4. At least for Opus the mpegts muxer reads the value from the last packet the encoder or demuxer sends its way and writes it to the output file, but the mpegts demuxer is apparently none the wiser because the opus parser just discards this information.
the patch does look like a reasonable step to me but i might be missing something
On Wed, May 25, 2016 at 09:56:59AM -0700, Jon Toohill wrote:
--- libavformat/mp3dec.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 3725d67..192f5ef 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -234,6 +234,8 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st,
mp3->start_pad = v>>12; mp3-> end_pad = v&4095; + st->codecpar->initial_padding = mp3->start_pad; + st->codecpar->trailing_padding = mp3->end_pad; st->start_skip_samples = mp3->start_pad + 528 + 1; if (mp3->frames) { st->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf;
is the 528 + 1 difference intended to start_skip_samples/first_discard_sample ? mp3enc stores par->initial_padding - 528 - 1 [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB If you drop bombs on a foreign country and kill a hundred thousand innocent people, expect your government to call the consequence "unprovoked inhuman terrorist attacks" and use it to justify dropping more bombs and killing more people. The technology changed, the idea is old.
Based on my understanding of [1], these values in the Info tag specify only the encoder delay/padding, which matches the documentation for these fields. It looks like other formats are using the fields that way as well. I think the extra 528 + 1 samples are the decoder delay [2]. It looks like libmp3lame adds the 528 + 1 only to have mp3dec subtract it, so I'm not sure why that's done. IIUC start_skip_samples is the mechanism that actually accounts for the extra delay when decoding. [1]: http://gabriel.mp3-tech.org/mp3infotag.html#delays [2]: http://lame.sourceforge.net/tech-FAQ.txt Jon Toohill | Google Play Music | jtoohill@google.com | (650) 215-0770 On Thu, May 26, 2016 at 7:51 PM, Michael Niedermayer <michael@niedermayer.cc
wrote:
On Wed, May 25, 2016 at 09:56:59AM -0700, Jon Toohill wrote:
--- libavformat/mp3dec.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 3725d67..192f5ef 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -234,6 +234,8 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st,
mp3->start_pad = v>>12; mp3-> end_pad = v&4095; + st->codecpar->initial_padding = mp3->start_pad; + st->codecpar->trailing_padding = mp3->end_pad; st->start_skip_samples = mp3->start_pad + 528 + 1; if (mp3->frames) { st->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf;
is the 528 + 1 difference intended to start_skip_samples/first_discard_sample ? mp3enc stores par->initial_padding - 528 - 1
[...]
-- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
If you drop bombs on a foreign country and kill a hundred thousand innocent people, expect your government to call the consequence "unprovoked inhuman terrorist attacks" and use it to justify dropping more bombs and killing more people. The technology changed, the idea is old.
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Michael et al., is this good to merge as-is? I just tested and a round trip with ffmpeg from wav -> mp3 -> wav retains the correct number of samples. Jon Toohill | Google Play Music | jtoohill@google.com | (650) 215-0770 On Wed, Jun 1, 2016 at 5:58 PM, Jon Toohill <jtoohill@google.com> wrote:
Based on my understanding of [1], these values in the Info tag specify only the encoder delay/padding, which matches the documentation for these fields. It looks like other formats are using the fields that way as well.
I think the extra 528 + 1 samples are the decoder delay [2]. It looks like libmp3lame adds the 528 + 1 only to have mp3dec subtract it, so I'm not sure why that's done. IIUC start_skip_samples is the mechanism that actually accounts for the extra delay when decoding.
[1]: http://gabriel.mp3-tech.org/mp3infotag.html#delays [2]: http://lame.sourceforge.net/tech-FAQ.txt
Jon Toohill | Google Play Music | jtoohill@google.com | (650) 215-0770
On Thu, May 26, 2016 at 7:51 PM, Michael Niedermayer < michael@niedermayer.cc> wrote:
On Wed, May 25, 2016 at 09:56:59AM -0700, Jon Toohill wrote:
--- libavformat/mp3dec.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 3725d67..192f5ef 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -234,6 +234,8 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st,
mp3->start_pad = v>>12; mp3-> end_pad = v&4095; + st->codecpar->initial_padding = mp3->start_pad; + st->codecpar->trailing_padding = mp3->end_pad; st->start_skip_samples = mp3->start_pad + 528 + 1; if (mp3->frames) { st->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf;
is the 528 + 1 difference intended to start_skip_samples/first_discard_sample ? mp3enc stores par->initial_padding - 528 - 1
[...]
-- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
If you drop bombs on a foreign country and kill a hundred thousand innocent people, expect your government to call the consequence "unprovoked inhuman terrorist attacks" and use it to justify dropping more bombs and killing more people. The technology changed, the idea is old.
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
On Wed, Jun 08, 2016 at 10:46:49AM -0700, Jon Toohill wrote:
Michael et al., is this good to merge as-is? I just tested and a round trip with ffmpeg from wav -> mp3 -> wav retains the correct number of samples.
There seems to be a inconsistency try the patch below with your patch, and write a mp3 file with ffmpeg and the read it the initial_padding is not what was written or try this: /ffmpeg -i test.mp3 -codec copy test2.mp3 read padding 576 written padding 576 ./ffmpeg -i test2.mp3 -codec copy test3.mp3 read padding 47 written padding 47 diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 345fa88..b063ad9 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -240,6 +240,7 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, mp3->start_pad = v>>12; mp3-> end_pad = v&4095; st->codecpar->initial_padding = mp3->start_pad; + av_log(0,0, "read padding %d\n", st->codecpar->initial_padding ); st->codecpar->trailing_padding = mp3->end_pad; st->start_skip_samples = mp3->start_pad + 528 + 1; if (mp3->frames) { diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index de63401..a971136 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -253,7 +253,7 @@ static int mp3_write_xing(AVFormatContext *s) av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); } avio_wb24(dyn_ctx, FFMAX(par->initial_padding - 528 - 1, 0)<<12); - +av_log(0,0, "written padding %d\n", par->initial_padding ); avio_w8(dyn_ctx, 0); // misc avio_w8(dyn_ctx, 0); // mp3gain avio_wb16(dyn_ctx, 0); // preset [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB During times of universal deceit, telling the truth becomes a revolutionary act. -- George Orwell
Also adds trailing_padding to AVCodecContext to match AVCodecParameters so that it doesn't get lost when mapping between them. --- doc/APIchanges | 4 ++++ libavcodec/avcodec.h | 11 +++++++++++ libavcodec/utils.c | 38 ++++++++++++++++++++++---------------- libavcodec/version.h | 2 +- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index d777dc0..4720b70 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,10 @@ libavutil: 2015-08-28 API changes, most recent first: +2016-05-25 - xxxxxxx - lavc 57.43.100 - avcodec.h + Add trailing_padding to AVCodecContext to match the corresponding + field in AVCodecParameters. + 2016-04-27 - xxxxxxx - lavu 55.23.100 - log.h Add a new function av_log_format_line2() which returns number of bytes written to the target buffer. diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 9ec9adf..554e1ee 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3497,6 +3497,17 @@ typedef struct AVCodecContext { #define FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS 1 #endif + /** + * Audio only. The amount of padding (in samples) appended by the encoder to + * the end of the audio. I.e. this number of decoded samples must be + * discarded by the caller from the end of the stream to get the original + * audio without any trailing padding. + * + * - decoding: unused + * - encoding: unused + */ + int trailing_padding; + } AVCodecContext; AVRational av_codec_get_pkt_timebase (const AVCodecContext *avctx); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index e5a832b..51f50b0 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -3251,6 +3251,10 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) && enc->bits_per_raw_sample != av_get_bytes_per_sample(enc->sample_fmt) * 8) snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%d bit)", enc->bits_per_raw_sample); + if (enc->initial_padding || enc->trailing_padding) { + snprintf(buf + strlen(buf), buf_size - strlen(buf), + ", delay %d, padding %d", enc->initial_padding, enc->trailing_padding); + } break; case AVMEDIA_TYPE_DATA: if (av_log_get_level() >= AV_LOG_DEBUG) { @@ -4094,14 +4098,15 @@ int avcodec_parameters_from_context(AVCodecParameters *par, par->video_delay = codec->has_b_frames; break; case AVMEDIA_TYPE_AUDIO: - par->format = codec->sample_fmt; - par->channel_layout = codec->channel_layout; - par->channels = codec->channels; - par->sample_rate = codec->sample_rate; - par->block_align = codec->block_align; - par->frame_size = codec->frame_size; - par->initial_padding = codec->initial_padding; - par->seek_preroll = codec->seek_preroll; + par->format = codec->sample_fmt; + par->channel_layout = codec->channel_layout; + par->channels = codec->channels; + par->sample_rate = codec->sample_rate; + par->block_align = codec->block_align; + par->frame_size = codec->frame_size; + par->initial_padding = codec->initial_padding; + par->trailing_padding = codec->trailing_padding; + par->seek_preroll = codec->seek_preroll; break; case AVMEDIA_TYPE_SUBTITLE: par->width = codec->width; @@ -4148,14 +4153,15 @@ int avcodec_parameters_to_context(AVCodecContext *codec, codec->has_b_frames = par->video_delay; break; case AVMEDIA_TYPE_AUDIO: - codec->sample_fmt = par->format; - codec->channel_layout = par->channel_layout; - codec->channels = par->channels; - codec->sample_rate = par->sample_rate; - codec->block_align = par->block_align; - codec->frame_size = par->frame_size; - codec->initial_padding = par->initial_padding; - codec->seek_preroll = par->seek_preroll; + codec->sample_fmt = par->format; + codec->channel_layout = par->channel_layout; + codec->channels = par->channels; + codec->sample_rate = par->sample_rate; + codec->block_align = par->block_align; + codec->frame_size = par->frame_size; + codec->initial_padding = par->initial_padding; + codec->trailing_padding = par->trailing_padding; + codec->seek_preroll = par->seek_preroll; break; case AVMEDIA_TYPE_SUBTITLE: codec->width = par->width; diff --git a/libavcodec/version.h b/libavcodec/version.h index 0916f81..ee3006c 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -28,7 +28,7 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 57 -#define LIBAVCODEC_VERSION_MINOR 42 +#define LIBAVCODEC_VERSION_MINOR 43 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ -- 2.8.0.rc3.226.g39d4020
These patches expose the encoder delay/padding parsed from an mp3's Xing header to users of lavc/lavf, and show gapless info in the stream summary string. They also change ffmpeg to pass Xing gapless metadata from input to output when using -acodec copy. trailing_padding is still not set properly when encoding with libmp3lame, causing an encode/decode round trip to add trailing silence. This is not a regression from current behavior, and will be addressed in a separate patch set. Jon Toohill (3): lavf/mp3dec: pass Xing gapless metadata to AVCodecParameters lavc: show gapless info in stream summary ffmpeg: copy trailing_padding when using -acodec copy doc/APIchanges | 4 ++++ ffmpeg.c | 1 + libavcodec/avcodec.h | 11 +++++++++++ libavcodec/libmp3lame.c | 2 +- libavcodec/utils.c | 40 +++++++++++++++++++++++----------------- libavcodec/version.h | 2 +- libavformat/mp3dec.c | 2 ++ libavformat/mp3enc.c | 9 ++++++--- 8 files changed, 49 insertions(+), 22 deletions(-) -- 2.8.0.rc3.226.g39d4020
Also removes decoder delay compensation from libmp3lame and mp3enc. initial_padding specifies only encoder delay, decoder delay is handled by start_skip_samples. --- libavcodec/libmp3lame.c | 2 +- libavformat/mp3dec.c | 2 ++ libavformat/mp3enc.c | 9 ++++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index 5642264..198ac94 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -137,7 +137,7 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx) } /* get encoder delay */ - avctx->initial_padding = lame_get_encoder_delay(s->gfp) + 528 + 1; + avctx->initial_padding = lame_get_encoder_delay(s->gfp); ff_af_queue_init(avctx, &s->afq); avctx->frame_size = lame_get_framesize(s->gfp); diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 56c7f8c..345fa88 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -239,6 +239,8 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, mp3->start_pad = v>>12; mp3-> end_pad = v&4095; + st->codecpar->initial_padding = mp3->start_pad; + st->codecpar->trailing_padding = mp3->end_pad; st->start_skip_samples = mp3->start_pad + 528 + 1; if (mp3->frames) { st->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf; diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index de63401..da70d13 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -248,11 +248,14 @@ static int mp3_write_xing(AVFormatContext *s) avio_w8(dyn_ctx, 0); // unknown encoding flags avio_w8(dyn_ctx, 0); // unknown abr/minimal bitrate - // encoder delay - if (par->initial_padding - 528 - 1 >= 1 << 12) { + // encoder delay/padding + if (par->initial_padding >= 1 << 12) { av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); } - avio_wb24(dyn_ctx, FFMAX(par->initial_padding - 528 - 1, 0)<<12); + if (par->trailing_padding >= 1 << 12) { + av_log(s, AV_LOG_WARNING, "Too many samples of trailing padding.\n"); + } + avio_wb24(dyn_ctx, (par->initial_padding << 12) | (par->trailing_padding & 0xFFF)); avio_w8(dyn_ctx, 0); // misc avio_w8(dyn_ctx, 0); // mp3gain -- 2.8.0.rc3.226.g39d4020
On Thu, Jun 16, 2016 at 11:16:05AM -0700, Jon Toohill wrote:
Also removes decoder delay compensation from libmp3lame and mp3enc. initial_padding specifies only encoder delay, decoder delay is handled by start_skip_samples. --- libavcodec/libmp3lame.c | 2 +- libavformat/mp3dec.c | 2 ++ libavformat/mp3enc.c | 9 ++++++--- 3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index 5642264..198ac94 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -137,7 +137,7 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx) }
/* get encoder delay */ - avctx->initial_padding = lame_get_encoder_delay(s->gfp) + 528 + 1; + avctx->initial_padding = lame_get_encoder_delay(s->gfp); ff_af_queue_init(avctx, &s->afq);
avctx->frame_size = lame_get_framesize(s->gfp);
you are changing a field of the public API changing public API without major version bumps is tricky, we dont want to break applications linkng to a newer lib is there software that uses this? software that would break if this is applied ? (or maybe it wuld fix some software usig it) If this is a bugfix it should be documented in APIChanges with minor version bumps, any available references to specifications should be added too Such bugfix should also be seperate of other unrelated changes [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I have often repented speaking, but never of holding my tongue. -- Xenocrates
I'm having a hard time finding software that uses this via simple GitHub searches. I think this should be considered a bugfix, since the struct field states that it only represents encoder delay, not decoder delay. I'll send out an updated patchset that splits this into more patches, including documentation and another minor version bump. Jon Toohill | Google Play Music | jtoohill@google.com | (650) 215-0770 On Fri, Jun 17, 2016 at 5:32 PM, Michael Niedermayer <michael@niedermayer.cc
wrote:
On Thu, Jun 16, 2016 at 11:16:05AM -0700, Jon Toohill wrote:
Also removes decoder delay compensation from libmp3lame and mp3enc. initial_padding specifies only encoder delay, decoder delay is handled by start_skip_samples. --- libavcodec/libmp3lame.c | 2 +- libavformat/mp3dec.c | 2 ++ libavformat/mp3enc.c | 9 ++++++--- 3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index 5642264..198ac94 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -137,7 +137,7 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx) }
/* get encoder delay */ - avctx->initial_padding = lame_get_encoder_delay(s->gfp) + 528 + 1; + avctx->initial_padding = lame_get_encoder_delay(s->gfp); ff_af_queue_init(avctx, &s->afq);
avctx->frame_size = lame_get_framesize(s->gfp);
you are changing a field of the public API changing public API without major version bumps is tricky, we dont want to break applications linkng to a newer lib
is there software that uses this? software that would break if this is applied ? (or maybe it wuld fix some software usig it)
If this is a bugfix it should be documented in APIChanges with minor version bumps, any available references to specifications should be added too
Such bugfix should also be seperate of other unrelated changes
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I have often repented speaking, but never of holding my tongue. -- Xenocrates
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
On Tue, Jul 12, 2016 at 03:41:38PM -0700, Jon Toohill wrote:
I'm having a hard time finding software that uses this via simple GitHub searches.
FFmpeg itself uses it
I think this should be considered a bugfix, since the struct field states that it only represents encoder delay, not decoder delay. I'll send out an updated patchset that splits this into more patches, including documentation and another minor version bump.
heres a case that this patch breaks: ./ffmpeg -i ~/videos/matrixbench_mpeg2.mpg -acodec mp3 -vn -t 1 file.mp4 ./ffprobe -show_packets -print_format compact file.mp4 this seems to require libmp3lame which is why it doesnt show up in fate --- 3-old 2016-07-13 01:19:50.338105803 +0200 +++ 3-new 2016-07-13 01:18:59.354104729 +0200 @@ -1,43 +1,43 @@ -packet|codec_type=audio|stream_index=0|pts=-1105|pts_time=-0.023021|dts=-1105|dts_time=-0.023021|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=44|flags=K -packet|codec_type=audio|stream_index=0|pts=47|pts_time=0.000979|dts=47|dts_time=0.000979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=428|flags=K -packet|codec_type=audio|stream_index=0|pts=1199|pts_time=0.024979|dts=1199|dts_time=0.024979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=812|flags=K -packet|codec_type=audio|stream_index=0|pts=2351|pts_time=0.048979|dts=2351|dts_time=0.048979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=1196|flags=K -packet|codec_type=audio|stream_index=0|pts=3503|pts_time=0.072979|dts=3503|dts_time=0.072979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=1580|flags=K -packet|codec_type=audio|stream_index=0|pts=4655|pts_time=0.096979|dts=4655|dts_time=0.096979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=1964|flags=K -packet|codec_type=audio|stream_index=0|pts=5807|pts_time=0.120979|dts=5807|dts_time=0.120979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=2348|flags=K -packet|codec_type=audio|stream_index=0|pts=6959|pts_time=0.144979|dts=6959|dts_time=0.144979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=2732|flags=K -packet|codec_type=audio|stream_index=0|pts=8111|pts_time=0.168979|dts=8111|dts_time=0.168979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=3116|flags=K -packet|codec_type=audio|stream_index=0|pts=9263|pts_time=0.192979|dts=9263|dts_time=0.192979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=3500|flags=K -packet|codec_type=audio|stream_index=0|pts=10415|pts_time=0.216979|dts=10415|dts_time=0.216979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=3884|flags=K -packet|codec_type=audio|stream_index=0|pts=11567|pts_time=0.240979|dts=11567|dts_time=0.240979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=4268|flags=K -packet|codec_type=audio|stream_index=0|pts=12719|pts_time=0.264979|dts=12719|dts_time=0.264979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=4652|flags=K -packet|codec_type=audio|stream_index=0|pts=13871|pts_time=0.288979|dts=13871|dts_time=0.288979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=5036|flags=K -packet|codec_type=audio|stream_index=0|pts=15023|pts_time=0.312979|dts=15023|dts_time=0.312979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=5420|flags=K -packet|codec_type=audio|stream_index=0|pts=16175|pts_time=0.336979|dts=16175|dts_time=0.336979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=5804|flags=K -packet|codec_type=audio|stream_index=0|pts=17327|pts_time=0.360979|dts=17327|dts_time=0.360979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=6188|flags=K -packet|codec_type=audio|stream_index=0|pts=18479|pts_time=0.384979|dts=18479|dts_time=0.384979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=6572|flags=K -packet|codec_type=audio|stream_index=0|pts=19631|pts_time=0.408979|dts=19631|dts_time=0.408979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=6956|flags=K -packet|codec_type=audio|stream_index=0|pts=20783|pts_time=0.432979|dts=20783|dts_time=0.432979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=7340|flags=K -packet|codec_type=audio|stream_index=0|pts=21935|pts_time=0.456979|dts=21935|dts_time=0.456979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=7724|flags=K -packet|codec_type=audio|stream_index=0|pts=23087|pts_time=0.480979|dts=23087|dts_time=0.480979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=8108|flags=K -packet|codec_type=audio|stream_index=0|pts=24239|pts_time=0.504979|dts=24239|dts_time=0.504979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=8492|flags=K -packet|codec_type=audio|stream_index=0|pts=25391|pts_time=0.528979|dts=25391|dts_time=0.528979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=8876|flags=K -packet|codec_type=audio|stream_index=0|pts=26543|pts_time=0.552979|dts=26543|dts_time=0.552979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=9260|flags=K -packet|codec_type=audio|stream_index=0|pts=27695|pts_time=0.576979|dts=27695|dts_time=0.576979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=9644|flags=K -packet|codec_type=audio|stream_index=0|pts=28847|pts_time=0.600979|dts=28847|dts_time=0.600979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=10028|flags=K -packet|codec_type=audio|stream_index=0|pts=29999|pts_time=0.624979|dts=29999|dts_time=0.624979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=10412|flags=K -packet|codec_type=audio|stream_index=0|pts=31151|pts_time=0.648979|dts=31151|dts_time=0.648979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=10796|flags=K -packet|codec_type=audio|stream_index=0|pts=32303|pts_time=0.672979|dts=32303|dts_time=0.672979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=11180|flags=K -packet|codec_type=audio|stream_index=0|pts=33455|pts_time=0.696979|dts=33455|dts_time=0.696979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=11564|flags=K -packet|codec_type=audio|stream_index=0|pts=34607|pts_time=0.720979|dts=34607|dts_time=0.720979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=11948|flags=K -packet|codec_type=audio|stream_index=0|pts=35759|pts_time=0.744979|dts=35759|dts_time=0.744979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=12332|flags=K -packet|codec_type=audio|stream_index=0|pts=36911|pts_time=0.768979|dts=36911|dts_time=0.768979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=12716|flags=K -packet|codec_type=audio|stream_index=0|pts=38063|pts_time=0.792979|dts=38063|dts_time=0.792979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=13100|flags=K -packet|codec_type=audio|stream_index=0|pts=39215|pts_time=0.816979|dts=39215|dts_time=0.816979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=13484|flags=K -packet|codec_type=audio|stream_index=0|pts=40367|pts_time=0.840979|dts=40367|dts_time=0.840979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=13868|flags=K -packet|codec_type=audio|stream_index=0|pts=41519|pts_time=0.864979|dts=41519|dts_time=0.864979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=14252|flags=K -packet|codec_type=audio|stream_index=0|pts=42671|pts_time=0.888979|dts=42671|dts_time=0.888979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=14636|flags=K -packet|codec_type=audio|stream_index=0|pts=43823|pts_time=0.912979|dts=43823|dts_time=0.912979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=15020|flags=K -packet|codec_type=audio|stream_index=0|pts=44975|pts_time=0.936979|dts=44975|dts_time=0.936979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=15404|flags=K -packet|codec_type=audio|stream_index=0|pts=46127|pts_time=0.960979|dts=46127|dts_time=0.960979|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=15788|flags=K -packet|codec_type=audio|stream_index=0|pts=47279|pts_time=0.984979|dts=47279|dts_time=0.984979|duration=1826|duration_time=0.038042|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=16172|flags=K +packet|codec_type=audio|stream_index=0|pts=-576|pts_time=-0.012000|dts=-576|dts_time=-0.012000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=44|flags=K +packet|codec_type=audio|stream_index=0|pts=576|pts_time=0.012000|dts=576|dts_time=0.012000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=428|flags=K +packet|codec_type=audio|stream_index=0|pts=1728|pts_time=0.036000|dts=1728|dts_time=0.036000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=812|flags=K +packet|codec_type=audio|stream_index=0|pts=2880|pts_time=0.060000|dts=2880|dts_time=0.060000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=1196|flags=K +packet|codec_type=audio|stream_index=0|pts=4032|pts_time=0.084000|dts=4032|dts_time=0.084000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=1580|flags=K +packet|codec_type=audio|stream_index=0|pts=5184|pts_time=0.108000|dts=5184|dts_time=0.108000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=1964|flags=K +packet|codec_type=audio|stream_index=0|pts=6336|pts_time=0.132000|dts=6336|dts_time=0.132000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=2348|flags=K +packet|codec_type=audio|stream_index=0|pts=7488|pts_time=0.156000|dts=7488|dts_time=0.156000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=2732|flags=K +packet|codec_type=audio|stream_index=0|pts=8640|pts_time=0.180000|dts=8640|dts_time=0.180000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=3116|flags=K +packet|codec_type=audio|stream_index=0|pts=9792|pts_time=0.204000|dts=9792|dts_time=0.204000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=3500|flags=K +packet|codec_type=audio|stream_index=0|pts=10944|pts_time=0.228000|dts=10944|dts_time=0.228000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=3884|flags=K +packet|codec_type=audio|stream_index=0|pts=12096|pts_time=0.252000|dts=12096|dts_time=0.252000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=4268|flags=K +packet|codec_type=audio|stream_index=0|pts=13248|pts_time=0.276000|dts=13248|dts_time=0.276000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=4652|flags=K +packet|codec_type=audio|stream_index=0|pts=14400|pts_time=0.300000|dts=14400|dts_time=0.300000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=5036|flags=K +packet|codec_type=audio|stream_index=0|pts=15552|pts_time=0.324000|dts=15552|dts_time=0.324000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=5420|flags=K +packet|codec_type=audio|stream_index=0|pts=16704|pts_time=0.348000|dts=16704|dts_time=0.348000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=5804|flags=K +packet|codec_type=audio|stream_index=0|pts=17856|pts_time=0.372000|dts=17856|dts_time=0.372000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=6188|flags=K +packet|codec_type=audio|stream_index=0|pts=19008|pts_time=0.396000|dts=19008|dts_time=0.396000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=6572|flags=K +packet|codec_type=audio|stream_index=0|pts=20160|pts_time=0.420000|dts=20160|dts_time=0.420000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=6956|flags=K +packet|codec_type=audio|stream_index=0|pts=21312|pts_time=0.444000|dts=21312|dts_time=0.444000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=7340|flags=K +packet|codec_type=audio|stream_index=0|pts=22464|pts_time=0.468000|dts=22464|dts_time=0.468000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=7724|flags=K +packet|codec_type=audio|stream_index=0|pts=23616|pts_time=0.492000|dts=23616|dts_time=0.492000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=8108|flags=K +packet|codec_type=audio|stream_index=0|pts=24768|pts_time=0.516000|dts=24768|dts_time=0.516000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=8492|flags=K +packet|codec_type=audio|stream_index=0|pts=25920|pts_time=0.540000|dts=25920|dts_time=0.540000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=8876|flags=K +packet|codec_type=audio|stream_index=0|pts=27072|pts_time=0.564000|dts=27072|dts_time=0.564000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=9260|flags=K +packet|codec_type=audio|stream_index=0|pts=28224|pts_time=0.588000|dts=28224|dts_time=0.588000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=9644|flags=K +packet|codec_type=audio|stream_index=0|pts=29376|pts_time=0.612000|dts=29376|dts_time=0.612000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=10028|flags=K +packet|codec_type=audio|stream_index=0|pts=30528|pts_time=0.636000|dts=30528|dts_time=0.636000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=10412|flags=K +packet|codec_type=audio|stream_index=0|pts=31680|pts_time=0.660000|dts=31680|dts_time=0.660000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=10796|flags=K +packet|codec_type=audio|stream_index=0|pts=32832|pts_time=0.684000|dts=32832|dts_time=0.684000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=11180|flags=K +packet|codec_type=audio|stream_index=0|pts=33984|pts_time=0.708000|dts=33984|dts_time=0.708000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=11564|flags=K +packet|codec_type=audio|stream_index=0|pts=35136|pts_time=0.732000|dts=35136|dts_time=0.732000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=11948|flags=K +packet|codec_type=audio|stream_index=0|pts=36288|pts_time=0.756000|dts=36288|dts_time=0.756000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=12332|flags=K +packet|codec_type=audio|stream_index=0|pts=37440|pts_time=0.780000|dts=37440|dts_time=0.780000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=12716|flags=K +packet|codec_type=audio|stream_index=0|pts=38592|pts_time=0.804000|dts=38592|dts_time=0.804000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=13100|flags=K +packet|codec_type=audio|stream_index=0|pts=39744|pts_time=0.828000|dts=39744|dts_time=0.828000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=13484|flags=K +packet|codec_type=audio|stream_index=0|pts=40896|pts_time=0.852000|dts=40896|dts_time=0.852000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=13868|flags=K +packet|codec_type=audio|stream_index=0|pts=42048|pts_time=0.876000|dts=42048|dts_time=0.876000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=14252|flags=K +packet|codec_type=audio|stream_index=0|pts=43200|pts_time=0.900000|dts=43200|dts_time=0.900000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=14636|flags=K +packet|codec_type=audio|stream_index=0|pts=44352|pts_time=0.924000|dts=44352|dts_time=0.924000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=15020|flags=K +packet|codec_type=audio|stream_index=0|pts=45504|pts_time=0.948000|dts=45504|dts_time=0.948000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=15404|flags=K +packet|codec_type=audio|stream_index=0|pts=46656|pts_time=0.972000|dts=46656|dts_time=0.972000|duration=1152|duration_time=0.024000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=15788|flags=K +packet|codec_type=audio|stream_index=0|pts=47808|pts_time=0.996000|dts=47808|dts_time=0.996000|duration=768|duration_time=0.016000|convergence_duration=N/A|convergence_duration_time=N/A|size=384|pos=16172|flags=K [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Awnsering whenever a program halts or runs forever is On a turing machine, in general impossible (turings halting problem). On any real computer, always possible as a real computer has a finite number of states N, and will either halt in less than N cycles or never halt.
Also adds trailing_padding to AVCodecContext to match AVCodecParameters so that it doesn't get lost when mapping between them. --- doc/APIchanges | 4 ++++ libavcodec/avcodec.h | 11 +++++++++++ libavcodec/utils.c | 40 +++++++++++++++++++++++----------------- libavcodec/version.h | 2 +- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index d777dc0..6092419 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,10 @@ libavutil: 2015-08-28 API changes, most recent first: +2016-05-25 - xxxxxxx - lavc 57.47.100 - avcodec.h + Add trailing_padding to AVCodecContext to match the corresponding + field in AVCodecParameters. + 2016-04-27 - xxxxxxx - lavu 55.23.100 - log.h Add a new function av_log_format_line2() which returns number of bytes written to the target buffer. diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 0181eb1..700c9b8 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3504,6 +3504,17 @@ typedef struct AVCodecContext { #define FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS 1 #endif + /** + * Audio only. The amount of padding (in samples) appended by the encoder to + * the end of the audio. I.e. this number of decoded samples must be + * discarded by the caller from the end of the stream to get the original + * audio without any trailing padding. + * + * - decoding: unused + * - encoding: unused + */ + int trailing_padding; + } AVCodecContext; AVRational av_codec_get_pkt_timebase (const AVCodecContext *avctx); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 402a9d8..481e09c 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -3252,6 +3252,10 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) && enc->bits_per_raw_sample != av_get_bytes_per_sample(enc->sample_fmt) * 8) snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%d bit)", enc->bits_per_raw_sample); + if (enc->initial_padding || enc->trailing_padding) { + snprintf(buf + strlen(buf), buf_size - strlen(buf), + ", delay %d, padding %d", enc->initial_padding, enc->trailing_padding); + } break; case AVMEDIA_TYPE_DATA: if (av_log_get_level() >= AV_LOG_DEBUG) { @@ -4097,14 +4101,15 @@ int avcodec_parameters_from_context(AVCodecParameters *par, par->video_delay = codec->has_b_frames; break; case AVMEDIA_TYPE_AUDIO: - par->format = codec->sample_fmt; - par->channel_layout = codec->channel_layout; - par->channels = codec->channels; - par->sample_rate = codec->sample_rate; - par->block_align = codec->block_align; - par->frame_size = codec->frame_size; - par->initial_padding = codec->initial_padding; - par->seek_preroll = codec->seek_preroll; + par->format = codec->sample_fmt; + par->channel_layout = codec->channel_layout; + par->channels = codec->channels; + par->sample_rate = codec->sample_rate; + par->block_align = codec->block_align; + par->frame_size = codec->frame_size; + par->initial_padding = codec->initial_padding; + par->trailing_padding = codec->trailing_padding; + par->seek_preroll = codec->seek_preroll; break; case AVMEDIA_TYPE_SUBTITLE: par->width = codec->width; @@ -4151,15 +4156,16 @@ int avcodec_parameters_to_context(AVCodecContext *codec, codec->has_b_frames = par->video_delay; break; case AVMEDIA_TYPE_AUDIO: - codec->sample_fmt = par->format; - codec->channel_layout = par->channel_layout; - codec->channels = par->channels; - codec->sample_rate = par->sample_rate; - codec->block_align = par->block_align; - codec->frame_size = par->frame_size; - codec->delay = - codec->initial_padding = par->initial_padding; - codec->seek_preroll = par->seek_preroll; + codec->sample_fmt = par->format; + codec->channel_layout = par->channel_layout; + codec->channels = par->channels; + codec->sample_rate = par->sample_rate; + codec->block_align = par->block_align; + codec->frame_size = par->frame_size; + codec->delay = + codec->initial_padding = par->initial_padding; + codec->trailing_padding = par->trailing_padding; + codec->seek_preroll = par->seek_preroll; break; case AVMEDIA_TYPE_SUBTITLE: codec->width = par->width; diff --git a/libavcodec/version.h b/libavcodec/version.h index 0852b43..37a6e17 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -28,7 +28,7 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 57 -#define LIBAVCODEC_VERSION_MINOR 46 +#define LIBAVCODEC_VERSION_MINOR 47 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ -- 2.8.0.rc3.226.g39d4020
--- ffmpeg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ffmpeg.c b/ffmpeg.c index 652774f..442f818 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -3001,6 +3001,7 @@ static int transcode_init(void) enc_ctx->audio_service_type = dec_ctx->audio_service_type; enc_ctx->block_align = dec_ctx->block_align; enc_ctx->initial_padding = dec_ctx->delay; + enc_ctx->trailing_padding = dec_ctx->trailing_padding; enc_ctx->profile = dec_ctx->profile; #if FF_API_AUDIOENC_DELAY enc_ctx->delay = dec_ctx->delay; -- 2.8.0.rc3.226.g39d4020
These patches expose the encoder delay/padding parsed from an mp3's Xing header to users of lavc/lavf, and show gapless info in the stream summary string. They also change ffmpeg to pass Xing gapless metadata from input to output when using -acodec copy. trailing_padding is still not set properly when encoding with libmp3lame, causing an encode/decode round trip to add trailing silence. This is not a regression from current behavior, and will be addressed in a separate patch set. Jon Toohill (5): lavf/mp3dec: pass Xing gapless metadata to AVCodecParameters libmp3lame + mp3enc: removes decoder delay compensation lavc: show gapless info in stream summary ffmpeg: copy trailing_padding when using -acodec copy lavf/mp3enc: write trailing_padding in Xing header doc/APIchanges | 8 ++++++++ ffmpeg.c | 1 + libavcodec/avcodec.h | 11 +++++++++++ libavcodec/libmp3lame.c | 2 +- libavcodec/utils.c | 40 +++++++++++++++++++++++----------------- libavcodec/version.h | 2 +- libavformat/mp3dec.c | 2 ++ libavformat/mp3enc.c | 9 ++++++--- 8 files changed, 53 insertions(+), 22 deletions(-) -- 2.8.0.rc3.226.g39d4020
--- libavformat/mp3dec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 56c7f8c..345fa88 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -239,6 +239,8 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, mp3->start_pad = v>>12; mp3-> end_pad = v&4095; + st->codecpar->initial_padding = mp3->start_pad; + st->codecpar->trailing_padding = mp3->end_pad; st->start_skip_samples = mp3->start_pad + 528 + 1; if (mp3->frames) { st->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf; -- 2.8.0.rc3.226.g39d4020
initial_padding specifies only encoder delay, decoder delay is handled by start_skip_samples. --- doc/APIchanges | 4 ++++ libavcodec/libmp3lame.c | 2 +- libavcodec/version.h | 2 +- libavformat/mp3enc.c | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index d777dc0..ae450e1 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,10 @@ libavutil: 2015-08-28 API changes, most recent first: +2016-07-12 - xxxxxxx - lavc 57.47.100 - libmp3lame.c + Removed MP3 decoder delay from initial_padding in AVCodecContext. + initial_padding only includes the encoder delay. + 2016-04-27 - xxxxxxx - lavu 55.23.100 - log.h Add a new function av_log_format_line2() which returns number of bytes written to the target buffer. diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index 5642264..198ac94 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -137,7 +137,7 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx) } /* get encoder delay */ - avctx->initial_padding = lame_get_encoder_delay(s->gfp) + 528 + 1; + avctx->initial_padding = lame_get_encoder_delay(s->gfp); ff_af_queue_init(avctx, &s->afq); avctx->frame_size = lame_get_framesize(s->gfp); diff --git a/libavcodec/version.h b/libavcodec/version.h index 0852b43..37a6e17 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -28,7 +28,7 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 57 -#define LIBAVCODEC_VERSION_MINOR 46 +#define LIBAVCODEC_VERSION_MINOR 47 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index de63401..3b77d29 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -249,10 +249,10 @@ static int mp3_write_xing(AVFormatContext *s) avio_w8(dyn_ctx, 0); // unknown abr/minimal bitrate // encoder delay - if (par->initial_padding - 528 - 1 >= 1 << 12) { + if (par->initial_padding >= 1 << 12) { av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); } - avio_wb24(dyn_ctx, FFMAX(par->initial_padding - 528 - 1, 0)<<12); + avio_wb24(dyn_ctx, par->initial_padding << 12); avio_w8(dyn_ctx, 0); // misc avio_w8(dyn_ctx, 0); // mp3gain -- 2.8.0.rc3.226.g39d4020
On Tue, Jul 12, 2016 at 04:19:53PM -0700, Jon Toohill wrote:
initial_padding specifies only encoder delay, decoder delay is handled by start_skip_samples. --- doc/APIchanges | 4 ++++ libavcodec/libmp3lame.c | 2 +- libavcodec/version.h | 2 +- libavformat/mp3enc.c | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges index d777dc0..ae450e1 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,10 @@ libavutil: 2015-08-28
API changes, most recent first:
+2016-07-12 - xxxxxxx - lavc 57.47.100 - libmp3lame.c + Removed MP3 decoder delay from initial_padding in AVCodecContext. + initial_padding only includes the encoder delay. + 2016-04-27 - xxxxxxx - lavu 55.23.100 - log.h Add a new function av_log_format_line2() which returns number of bytes written to the target buffer. diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index 5642264..198ac94 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -137,7 +137,7 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx) }
/* get encoder delay */ - avctx->initial_padding = lame_get_encoder_delay(s->gfp) + 528 + 1; + avctx->initial_padding = lame_get_encoder_delay(s->gfp); ff_af_queue_init(avctx, &s->afq);
avctx->frame_size = lame_get_framesize(s->gfp); diff --git a/libavcodec/version.h b/libavcodec/version.h index 0852b43..37a6e17 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -28,7 +28,7 @@ #include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 57 -#define LIBAVCODEC_VERSION_MINOR 46 +#define LIBAVCODEC_VERSION_MINOR 47
master is at 50 release/3.1 is at 48 the issue described in the last patchset a moment ago ./ffmpeg -i ~/videos/matrixbench_mpeg2.mpg -acodec mp3 -vn -t 1 file.mp4 applies to teh new patch 1+2 too [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB No human being will ever know the Truth, for even if they happen to say it by chance, they would not even known they had done so. -- Xenophanes
Also adds trailing_padding to AVCodecContext to match AVCodecParameters so that it doesn't get lost when mapping between them. --- doc/APIchanges | 4 ++++ libavcodec/avcodec.h | 11 +++++++++++ libavcodec/utils.c | 40 +++++++++++++++++++++++----------------- libavcodec/version.h | 2 +- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index ae450e1..6e92cd4 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,10 @@ libavutil: 2015-08-28 API changes, most recent first: +2016-07-12 - xxxxxxx - lavc 57.48.100 - avcodec.h + Add trailing_padding to AVCodecContext to match the corresponding + field in AVCodecParameters. + 2016-07-12 - xxxxxxx - lavc 57.47.100 - libmp3lame.c Removed MP3 decoder delay from initial_padding in AVCodecContext. initial_padding only includes the encoder delay. diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 0181eb1..700c9b8 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3504,6 +3504,17 @@ typedef struct AVCodecContext { #define FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS 1 #endif + /** + * Audio only. The amount of padding (in samples) appended by the encoder to + * the end of the audio. I.e. this number of decoded samples must be + * discarded by the caller from the end of the stream to get the original + * audio without any trailing padding. + * + * - decoding: unused + * - encoding: unused + */ + int trailing_padding; + } AVCodecContext; AVRational av_codec_get_pkt_timebase (const AVCodecContext *avctx); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 402a9d8..481e09c 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -3252,6 +3252,10 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) && enc->bits_per_raw_sample != av_get_bytes_per_sample(enc->sample_fmt) * 8) snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%d bit)", enc->bits_per_raw_sample); + if (enc->initial_padding || enc->trailing_padding) { + snprintf(buf + strlen(buf), buf_size - strlen(buf), + ", delay %d, padding %d", enc->initial_padding, enc->trailing_padding); + } break; case AVMEDIA_TYPE_DATA: if (av_log_get_level() >= AV_LOG_DEBUG) { @@ -4097,14 +4101,15 @@ int avcodec_parameters_from_context(AVCodecParameters *par, par->video_delay = codec->has_b_frames; break; case AVMEDIA_TYPE_AUDIO: - par->format = codec->sample_fmt; - par->channel_layout = codec->channel_layout; - par->channels = codec->channels; - par->sample_rate = codec->sample_rate; - par->block_align = codec->block_align; - par->frame_size = codec->frame_size; - par->initial_padding = codec->initial_padding; - par->seek_preroll = codec->seek_preroll; + par->format = codec->sample_fmt; + par->channel_layout = codec->channel_layout; + par->channels = codec->channels; + par->sample_rate = codec->sample_rate; + par->block_align = codec->block_align; + par->frame_size = codec->frame_size; + par->initial_padding = codec->initial_padding; + par->trailing_padding = codec->trailing_padding; + par->seek_preroll = codec->seek_preroll; break; case AVMEDIA_TYPE_SUBTITLE: par->width = codec->width; @@ -4151,15 +4156,16 @@ int avcodec_parameters_to_context(AVCodecContext *codec, codec->has_b_frames = par->video_delay; break; case AVMEDIA_TYPE_AUDIO: - codec->sample_fmt = par->format; - codec->channel_layout = par->channel_layout; - codec->channels = par->channels; - codec->sample_rate = par->sample_rate; - codec->block_align = par->block_align; - codec->frame_size = par->frame_size; - codec->delay = - codec->initial_padding = par->initial_padding; - codec->seek_preroll = par->seek_preroll; + codec->sample_fmt = par->format; + codec->channel_layout = par->channel_layout; + codec->channels = par->channels; + codec->sample_rate = par->sample_rate; + codec->block_align = par->block_align; + codec->frame_size = par->frame_size; + codec->delay = + codec->initial_padding = par->initial_padding; + codec->trailing_padding = par->trailing_padding; + codec->seek_preroll = par->seek_preroll; break; case AVMEDIA_TYPE_SUBTITLE: codec->width = par->width; diff --git a/libavcodec/version.h b/libavcodec/version.h index 37a6e17..412fd01 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -28,7 +28,7 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 57 -#define LIBAVCODEC_VERSION_MINOR 47 +#define LIBAVCODEC_VERSION_MINOR 48 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ -- 2.8.0.rc3.226.g39d4020
--- ffmpeg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ffmpeg.c b/ffmpeg.c index 652774f..442f818 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -3001,6 +3001,7 @@ static int transcode_init(void) enc_ctx->audio_service_type = dec_ctx->audio_service_type; enc_ctx->block_align = dec_ctx->block_align; enc_ctx->initial_padding = dec_ctx->delay; + enc_ctx->trailing_padding = dec_ctx->trailing_padding; enc_ctx->profile = dec_ctx->profile; #if FF_API_AUDIOENC_DELAY enc_ctx->delay = dec_ctx->delay; -- 2.8.0.rc3.226.g39d4020
--- libavformat/mp3enc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index 3b77d29..da70d13 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -248,11 +248,14 @@ static int mp3_write_xing(AVFormatContext *s) avio_w8(dyn_ctx, 0); // unknown encoding flags avio_w8(dyn_ctx, 0); // unknown abr/minimal bitrate - // encoder delay + // encoder delay/padding if (par->initial_padding >= 1 << 12) { av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); } - avio_wb24(dyn_ctx, par->initial_padding << 12); + if (par->trailing_padding >= 1 << 12) { + av_log(s, AV_LOG_WARNING, "Too many samples of trailing padding.\n"); + } + avio_wb24(dyn_ctx, (par->initial_padding << 12) | (par->trailing_padding & 0xFFF)); avio_w8(dyn_ctx, 0); // misc avio_w8(dyn_ctx, 0); // mp3gain -- 2.8.0.rc3.226.g39d4020
participants (4)
-
James Almer -
Jon Toohill -
Michael Niedermayer -
Ronald S. Bultje