[FFmpeg-devel] Suggested Patch for timecode timebase calculation in mov.c
Hi ffmpeg developers. I am still new to attempting contributing here, so please let me know if there is a better approach for this. I am attaching a patch I would like to incorporate for calculating the stream time_base of the timecode data track in mov's. Please advise. Thanks! >From 5ae0b5a9cf9c37e11d5a3fea05c80c66b7c00c3e Mon Sep 17 00:00:00 2001 From: Jon Morley Date: Tue, 9 Sep 2014 11:48:02 -0700 Subject: [PATCH] libavformat/mov.c: Set stream time_base from frameduration/timescale Use tmcd atom's timescale and frameduration to for stream time base instead of 1/framenum. For timecode streams that have an entry for each frame 1/framenum is less accurate than frameduration/timescale. --- libavformat/mov.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index ae48c02..c300dd2 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1530,8 +1530,10 @@ static int mov_parse_stsd_data(MOVContext *c, AVIOContext *pb, tmcd_ctx->tmcd_flags = val; if (val & 1) st->codec->flags2 |= CODEC_FLAG2_DROP_FRAME_TIMECODE; -st->codec->time_base.den = st->codec->extradata[16]; /* number of frame */ -st->codec->time_base.num = 1; +int timescale = AV_RB32(st->codec->extradata + 8); +int framedur = AV_RB32(st->codec->extradata + 12); +st->codec->time_base.den = timescale; +st->codec->time_base.num = framedur; if (size > 30) { uint32_t len = AV_RB32(st->codec->extradata + 18); /* name atom length */ uint32_t format = AV_RB32(st->codec->extradata + 22); -- 1.8.5.2 (Apple Git-48) ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] Set AV_TIMECODE_FLAG_ALLOWNEGATIVE in avutil/timecode.c av_timecode_init_from_string
If the timecode value is negative it certainly seems safe to set the AV_TIMECODE_FLAG_ALLOWNEGATIVE on the AVTimecode object. >From 35ae38f9557e1ff01040d0e681e843d1727f979b Mon Sep 17 00:00:00 2001 From: Jon Morley Date: Tue, 9 Sep 2014 12:12:17 -0700 Subject: [PATCH 2/2] libavutil/timecode.c: improve flag setting when init tc from string If the string begins with a negative HH (hour) value then make sure to set the AV_TIMECODE_FLAG_ALLOW_NEGATIVE flag for the resulting tc->flags. --- libavutil/timecode.c | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavutil/timecode.c b/libavutil/timecode.c index 1dfd040..b96a4d1 100644 --- a/libavutil/timecode.c +++ b/libavutil/timecode.c @@ -201,9 +201,10 @@ int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *st } memset(tc, 0, sizeof(*tc)); -tc->flags = c != ':' ? AV_TIMECODE_FLAG_DROPFRAME : 0; // drop if ';', '.', ... -tc->rate = rate; -tc->fps = fps_from_frame_rate(rate); +tc->flags = c != ':' ? AV_TIMECODE_FLAG_DROPFRAME : 0; // drop if ';', '.', ... +tc->flags |= (hh < 0) ? AV_TIMECODE_FLAG_ALLOWNEGATIVE : 0; // neg if starts with '-' +tc->rate = rate; +tc->fps= fps_from_frame_rate(rate); ret = check_timecode(log_ctx, tc); if (ret < 0) -- 1.8.5.2 (Apple Git-48) ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] avformat/rtpdec: fix integer overflow in start_time_realtime calculation
From: Jonathan Baudanza I encountered this problem with NTP timestamps that are extremely old, like from January, 1990. Although RFC3550 suggests that the timestamps in the RTCP packets use the actual wallclock, some implementations use other clocks, such as the CLOCK_MONOTONIC on linux. I'm my case, I'm dealing with packets from mediasoup. Without this patch, start_time_realtime shows up in the distance future instead of around Jan 1900. --- libavformat/rtsp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index d8f45cf8d5..c48fa26d90 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -2320,7 +2320,7 @@ redo: } // Make real NTP start time available in AVFormatContext if (s->start_time_realtime == AV_NOPTS_VALUE) { -s->start_time_realtime = av_rescale (rtpctx->first_rtcp_ntp_time - (NTP_OFFSET << 32), 100, 1LL << 32); +s->start_time_realtime = av_rescale (rtpctx->first_rtcp_ntp_time, 100, 1LL << 32) - NTP_OFFSET_US; if (rtpctx->st) { s->start_time_realtime -= av_rescale_q (rtpctx->rtcp_ts_offset, rtpctx->st->time_base, AV_TIME_BASE_Q); -- 2.41.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] fix for colorspace minimum option value
From 616d5017d8d2e566db3deb2696cc1672f2019777 Mon Sep 17 00:00:00 2001 From: Jon Morley Date: Mon, 10 Nov 2014 10:43:42 -0800 Subject: [PATCH] options_table.h: min value for colorspace is 0 (AVCOL_SPC_RGB) The min value for colorspace should be zero and not one since the first valid index into the frame colorspace array is AVCOL_SPC_RGB which is 0. --- libavcodec/options_table.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index d617ae7..b72fbb1 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -432,7 +432,7 @@ static const AVOption avcodec_options[] = { {"iec61966_2_1", "IEC 61966-2-1",0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_IEC61966_2_1 }, INT_MIN, INT_MAX, V|E|D, "color_trc_type"}, {"bt2020_10bit", "BT.2020 - 10 bit", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_BT2020_10 },INT_MIN, INT_MAX, V|E|D, "color_trc_type"}, {"bt2020_12bit", "BT.2020 - 12 bit", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_BT2020_12 },INT_MIN, INT_MAX, V|E|D, "color_trc_type"}, -{"colorspace", "color space", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = AVCOL_SPC_UNSPECIFIED }, 1, AVCOL_SPC_NB-1, V|E|D, "colorspace_type"}, +{"colorspace", "color space", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = AVCOL_SPC_UNSPECIFIED }, 0, AVCOL_SPC_NB-1, V|E|D, "colorspace_type"}, {"rgb", "RGB", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_SPC_RGB }, INT_MIN, INT_MAX, V|E|D, "colorspace_type"}, {"bt709", "BT.709", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_SPC_BT709 }, INT_MIN, INT_MAX, V|E|D, "colorspace_type"}, {"unspecified", "Unspecified", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_SPC_UNSPECIFIED }, INT_MIN, INT_MAX, V|E|D, "colorspace_type"}, -- 1.8.5.2 (Apple Git-48) >From 616d5017d8d2e566db3deb2696cc1672f2019777 Mon Sep 17 00:00:00 2001 From: Jon Morley Date: Mon, 10 Nov 2014 10:43:42 -0800 Subject: [PATCH] options_table.h: min value for colorspace is 0 (AVCOL_SPC_RGB) The min value for colorspace should be zero and not one since the first valid index into the frame colorspace array is AVCOL_SPC_RGB which is 0. --- libavcodec/options_table.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index d617ae7..b72fbb1 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -432,7 +432,7 @@ static const AVOption avcodec_options[] = { {"iec61966_2_1", "IEC 61966-2-1",0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_IEC61966_2_1 }, INT_MIN, INT_MAX, V|E|D, "color_trc_type"}, {"bt2020_10bit", "BT.2020 - 10 bit", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_BT2020_10 },INT_MIN, INT_MAX, V|E|D, "color_trc_type"}, {"bt2020_12bit", "BT.2020 - 12 bit", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_BT2020_12 },INT_MIN, INT_MAX, V|E|D, "color_trc_type"}, -{"colorspace", "color space", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = AVCOL_SPC_UNSPECIFIED }, 1, AVCOL_SPC_NB-1, V|E|D, "colorspace_type"}, +{"colorspace", "color space", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = AVCOL_SPC_UNSPECIFIED }, 0, AVCOL_SPC_NB-1, V|E|D, "colorspace_type"}, {"rgb", "RGB", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_SPC_RGB }, INT_MIN, INT_MAX, V|E|D, "colorspace_type"}, {"bt709", "BT.709", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_SPC_BT709 }, INT_MIN, INT_MAX, V|E|D, "colorspace_type"}, {"unspecified", "Unspecified", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_SPC_UNSPECIFIED }, INT_MIN, INT_MAX, V|E|D, "colorspace_type"}, -- 1.8.5.2 (Apple Git-48) ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] Suggested Patch for timecode timebase calculation in mov.c
I never heard back about this and I think I have a new better solution now. I don't think the current mov.c timecode processing is handling the case where the timecode is in counter mode. Please read the following page 190 from: https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/qtff.pdf Specifically: "Number of frames An 8-bit integer that contains the number of frames per second for the timecode format. If the time is a counter, this is the number of frames for each counter tick." I have sample media in counter mode if it helps. I tried to send that before as well, but I think it was too large. Please let me know how else I can help with this enhancement. Feel free to send clarification questions to me. Thanks, Jon On 09/09/2014 12:01 PM, jon wrote: Hi ffmpeg developers. I am still new to attempting contributing here, so please let me know if there is a better approach for this. I am attaching a patch I would like to incorporate for calculating the stream time_base of the timecode data track in mov's. Please advise. Thanks! diff --git a/libavformat/mov.c b/libavformat/mov.c index 556411f1ef9f12097a5f779e858e815c26dc92e6..3ceb53424e597de99040d3d669f10421cc208b4d 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1658,6 +1658,13 @@ static int mov_parse_stsd_data(MOVContext *c, AVIOContext *pb, st->codec->flags2 |= CODEC_FLAG2_DROP_FRAME_TIMECODE; st->codec->time_base.den = st->codec->extradata[16]; /* number of frame */ st->codec->time_base.num = 1; +/* adjust for per frame dur in counter mode */ +if (tmcd_ctx->tmcd_flags & 0x0008) { +int timescale = AV_RB32(st->codec->extradata + 8); +int framedur = AV_RB32(st->codec->extradata + 12); +st->codec->time_base.den *= timescale; +st->codec->time_base.num *= framedur; +} if (size > 30) { uint32_t len = AV_RB32(st->codec->extradata + 18); /* name atom length */ uint32_t format = AV_RB32(st->codec->extradata + 22); ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] Suggested Patch for timecode timebase calculation in mov.c
Hi Michael, That is great! I see what you are referring to in mov_read_timecode_track(). However the text of that comment seems contradictory to me based on what I have read in the QuickTime reference I sited about the tmcd counter flag. It seemed like prior to the patch I submitted mov_parse_stsd_data() was collecting the st->codec->time_base as if the counter flag was unset. That comment text comes from commit: 35da85562d2f731855b28d4ab3b9b0679730ebf7 Perhaps Clément Bœsch has a better understanding of the difference between timecode values when the counter flag is set and when it is not. My work was based on deciphering the samples I had at my disposal in conjunction with my interpretation of the reference pdf. Thanks, Jon On 1/23/15 5:12 AM, Michael Niedermayer wrote: On Fri, Jan 23, 2015 at 04:26:59AM +0100, Michael Niedermayer wrote: On Thu, Jan 22, 2015 at 09:09:53AM -0800, jon wrote: I never heard back about this and I think I have a new better are you subscribed to ffmpeg-devel ? solution now. I don't think the current mov.c timecode processing is handling the case where the timecode is in counter mode. Please read the following page 190 from: https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/qtff.pdf Specifically: "Number of frames An 8-bit integer that contains the number of frames per second for the timecode format. If the time is a counter, this is the number of frames for each counter tick." I have sample media in counter mode if it helps. I tried to send that before as well, but I think it was too large. Please let me know how else I can help with this enhancement. Feel free to send clarification questions to me. yes, please provide a sample you can upload it via ftp see http://ffmpeg.org/bugreports.html any url that allows downloading from with wget works too thanks for the sample seems to fix/improve it patch applied ive also spotted a text in mov_read_timecode_track() about the counter flag, this probably should be updated somehow [...] ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [RFC PATCH] avformat/rtpdec: Audio level RTP extension RFC6464
From: Jonathan Baudanza libwebrtc will add audio level (in decibels) and VAD status to each RTP packet. This patch will add both values to the packet sidedata. I've been using this patch in production for about a year on live audio RTP streams to detect when users are speaking without needing to decode the audio data. --- libavcodec/avpacket.c | 1 + libavcodec/defs.h | 15 libavcodec/packet.h | 5 +++ libavformat/rtpdec.c | 87 +++ libavformat/rtpdec.h | 5 +++ libavformat/rtsp.c| 16 libavformat/rtsp.h| 2 + 7 files changed, 131 insertions(+) diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index e118bbaad1..73e0341bf7 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -305,6 +305,7 @@ const char *av_packet_side_data_name(enum AVPacketSideDataType type) case AV_PKT_DATA_IAMF_MIX_GAIN_PARAM:return "IAMF Mix Gain Parameter Data"; case AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM: return "IAMF Demixing Info Parameter Data"; case AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM: return "IAMF Recon Gain Info Parameter Data"; +case AV_PKT_DATA_SSRC_AUDIO_LEVEL: return "RTP SSRC Audio Level"; } return NULL; } diff --git a/libavcodec/defs.h b/libavcodec/defs.h index 00d840ec19..87e8814760 100644 --- a/libavcodec/defs.h +++ b/libavcodec/defs.h @@ -323,6 +323,21 @@ typedef struct AVProducerReferenceTime { int flags; } AVProducerReferenceTime; +/** + * Audio level structure from the ssrc-audio-level RTP header extension. + */ +typedef struct AVAudioLevel { +/** + * Audio level for this packet, measured in dBov: -127 - 0 + */ +int8_t level; + +/** + * Set to 1 if the encoder believes this packet contains voice. + */ +int voice; +} AVAudioLevel; + /** * Encode extradata length to a buffer. Used by xiph codecs. * diff --git a/libavcodec/packet.h b/libavcodec/packet.h index 8558ae849e..f7f1deb6e0 100644 --- a/libavcodec/packet.h +++ b/libavcodec/packet.h @@ -330,6 +330,11 @@ enum AVPacketSideDataType { */ AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT, +/** + * Audio Level and VAD data from the RTP header extension as defined by RFC 6464. + */ +AV_PKT_DATA_SSRC_AUDIO_LEVEL, + /** * The number of side data types. * This is not part of the public API/ABI in the sense that it may diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index fa7544cc07..479ea2e245 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -694,6 +694,79 @@ static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestam s->base_timestamp; } + +static const uint8_t* find_header_ext_data(int id, const uint8_t *buf, uint8_t *len) { +int buflen = (AV_RB16(buf + 2)) * 4; + +const uint8_t *p = buf + 4; +int idx = 0; +int this_id; +int this_len; + +// This is a one-byte extention format, as defined by RFC rfc5285 +if (buf[0] == 0xbe && buf[1] == 0xde) { +while (idx + 1 < buflen) { +if (p[idx] == 0) { +idx++; // skip padding +} else { +this_id = p[idx] >> 4; +this_len = (p[idx] & 0xf) + 1; + +// spec says 15 is reserved +if (this_id == 15) { +break; // reject +} + +if (this_id == id) { +if (this_len > buflen - idx - 1) { +break; // reject +} + +if (len != NULL) +*len = this_len; + +return p + idx + 1; +} + +idx += 1 + this_len; +} +} +} else if (buf[0] == 0x10 && (buf[1] & 0xff) == 0) { +// This is a two-byte extention format +while (idx + 1 < buflen) { +if (p[idx] == 0) { +idx++; // Skip padding +} else { +this_id = p[idx]; +this_len = p[idx + 1]; + +// spec says 15 is reserved +if (this_id == 15) { +break; // reject +} + +if (this_id == id) { +if (this_len > buflen - idx - 2) { +break; // reject +} + +if (len != NULL) +*len = this_len; +return p + idx + 2; +} + +idx += 2 + this_len; +} +} +} + +if (len != NULL) +*len = 0; + +return NULL; +} + + static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt, const uint8_t *buf, int len) { @@ -703,6 +776,7 @@ static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt, AVStream *st; uint32_t timestamp; int rv = 0; +
[FFmpeg-devel] [RFC PATCH] avformat/rtpdec: fix another int overflow in start_time_realtime
From: Jonathan Baudanza This was previously adjusted by me in 6b3f9c2e92b. Unfortunately, I traded one integer overflow bug for another. Currently, ntp timestamps that exceed INT64_MAX (~Jan 20, 1968) will cause an overflow when passed to av_rescale. This patch replaces av_rescale, which operates on int64_t, with ff_parse_ntp_time, which operates on uint65_t. This will give the correct values for timestamps back around the NTP epoch and present day timestamps. --- libavformat/rtsp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index c48fa26d90..5ea471b40c 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -2320,7 +2320,7 @@ redo: } // Make real NTP start time available in AVFormatContext if (s->start_time_realtime == AV_NOPTS_VALUE) { -s->start_time_realtime = av_rescale (rtpctx->first_rtcp_ntp_time, 100, 1LL << 32) - NTP_OFFSET_US; +s->start_time_realtime = ff_parse_ntp_time(rtpctx->first_rtcp_ntp_time) - NTP_OFFSET_US; if (rtpctx->st) { s->start_time_realtime -= av_rescale_q (rtpctx->rtcp_ts_offset, rtpctx->st->time_base, AV_TIME_BASE_Q); -- 2.41.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avformat/rtpdec: int overflow in start_time_realtime
From: Jonathan Baudanza This was previously adjusted by me in 6b3f9c2e92b. Unfortunately, I traded one integer overflow bug for another. Currently, NTP timestamps that exceed INT64_MAX (~Jan 20, 1968) will cause an overflow when passed to av_rescale. This patch replaces av_rescale, which operates on int64_t, with ff_parse_ntp_time, which operates on uint64_t. This will give the correct values for timestamps back around the NTP epoch and present day timestamps. --- libavformat/rtsp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index c48fa26d90..5ea471b40c 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -2320,7 +2320,7 @@ redo: } // Make real NTP start time available in AVFormatContext if (s->start_time_realtime == AV_NOPTS_VALUE) { -s->start_time_realtime = av_rescale (rtpctx->first_rtcp_ntp_time, 100, 1LL << 32) - NTP_OFFSET_US; +s->start_time_realtime = ff_parse_ntp_time(rtpctx->first_rtcp_ntp_time) - NTP_OFFSET_US; if (rtpctx->st) { s->start_time_realtime -= av_rescale_q (rtpctx->rtcp_ts_offset, rtpctx->st->time_base, AV_TIME_BASE_Q); -- 2.41.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] libavcodec/qsvenc.c: Set height and width alignment when using mjpeg_qsv
From: JonCookCubic Currently width_align and height_align are zero which cases "Error submitting the frame for encoding". This change sets the alignments. Signed-off-by: Jon Cook --- libavcodec/qsvenc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 9e416500e9..b18393532f 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -470,6 +470,9 @@ static int init_video_param_jpeg(AVCodecContext *avctx, QSVEncContext *q) q->param.mfx.Quality = av_clip(avctx->global_quality, 1, 100); q->param.mfx.RestartInterval = 0; +q->width_align = 16; +q->height_align = 16; + return 0; } -- 2.20.1.windows.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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] libavcodec/qsvenc.c: Set height and width alignment when using mjpeg_qsv
From: JonCookCubic Currently width_align and height_align are zero which cases "Error submitting the frame for encoding". This change sets the alignments. Signed-off-by: Jon Cook --- libavcodec/qsvenc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 9e416500e9..b18393532f 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -470,6 +470,9 @@ static int init_video_param_jpeg(AVCodecContext *avctx, QSVEncContext *q) q->param.mfx.Quality = av_clip(avctx->global_quality, 1, 100); q->param.mfx.RestartInterval = 0; +q->width_align = 16; +q->height_align = 16; + return 0; } -- 2.20.1.windows.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-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] libavcodec/qsvenc.c: Set height and width alignment when using mjpeg_qsv
Hi Zhong, Thanks for your reply. > IMHO If you set the aligned value, FrameInfo.Width/Height shoule > be changed to be: > >q->param.mfx.FrameInfo.Width = FFALIGN(avctx->width, q->width_align); >q->param.mfx.FrameInfo.Height = FFALIGN(avctx->height, q->height_align); Makes sense. I'll update the patch. This is my first time making changes to the code so forgive any mistakes as I find my way around. > Could you help to provide detail steps (CLI and input video) to > reproduce the issue? The command line I'm using is below along with the output without the changes applied. Input video is not important, any video will do. There is a little bit more about the problem here http://ffmpeg.org/pipermail/ffmpeg-user/2019-November/046143.html Regards, Jon $ ./ffmpeg.exe -loglevel debug -y -i C:/Users/jcook/Desktop/sample.avi -c:v mjpeg_qsv output.mp4 ffmpeg version N-95883-ga2fbdc6898 Copyright (c) 2000-2019 the FFmpeg developers built with Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27031.1 for x64 configuration: --toolchain=msvc --target-os=win64 --arch=x86_64 --prefix=/ffmpeg --enable-shared --disable-static --enable-yasm --enable-asm --enable-libmfx --enable-nonfree libavutil 56. 36.101 / 56. 36.101 libavcodec 58. 62.100 / 58. 62.100 libavformat58. 35.100 / 58. 35.100 libavdevice58. 9.101 / 58. 9.101 libavfilter 7. 67.100 / 7. 67.100 libswscale 5. 6.100 / 5. 6.100 libswresample 3. 6.100 / 3. 6.100 Splitting the commandline. Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'. Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'. Reading option '-i' ... matched as input url with argument 'C:/Users/jcook/Desktop/sample.avi'. Reading option '-c:v' ... matched as option 'c' (codec name) with argument ' mjpeg_qsv'. Reading option 'output.mp4' ... matched as output url. Finished splitting the commandline. Parsing a group of options: global . Applying option loglevel (set logging level) with argument debug. Applying option y (overwrite output files) with argument 1. Successfully parsed a group of options. Parsing a group of options: input url C:/Users/jcook/Desktop/sample.avi. Successfully parsed a group of options. Opening an input file: C:/Users/jcook/Desktop/sample.avi. [NULL @ 01E0699F8540] Opening 'C:/Users/jcook/Desktop/sample.avi' for reading [file @ 01E0699D8280] Setting default whitelist 'file,crypto' [avi @ 01E0699F8540] Format avi probed with size=2048 and score=100 [avi @ 01E0699D86C0] use odml:1 st:1 removing common factor 36 from timebase [avi @ 01E0699F8540] Before avformat_find_stream_info() pos: 4108 bytes read:142280 seeks:5 nb_streams:2 [mpeg4 @ 01E069A0AE00] Format yuv420p chosen by get_format(). [avi @ 01E0699F8540] All info found [avi @ 01E0699F8540] After avformat_find_stream_info() pos: 16409 bytes read:142280 seeks:5 frames:21 Input #0, avi, from 'C:/Users/jcook/Desktop/sample.avi': Metadata: encoder : MEncoder SVN-r33148-4.0.1 Duration: 00:00:05.56, start: 0.00, bitrate: 540 kb/s Stream #0:0, 1, 1/25: Video: mpeg4 (Simple Profile), 1 reference frame (XVID / 0x44495658), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], 0/1, 425 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc Stream #0:1, 20, 32/1225: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, fltp, 100 kb/s Successfully opened the file. Parsing a group of options: output url output.mp4. Applying option c:v (codec name) with argument mjpeg_qsv. Successfully parsed a group of options. Opening an output file: output.mp4. [file @ 01E06B51B9C0] Setting default whitelist 'file,crypto' Successfully opened the file. detected 12 logical cores Stream mapping: Stream #0:0 -> #0:0 (mpeg4 (native) -> mjpeg (mjpeg_qsv)) Stream #0:1 -> #0:1 (mp3 (mp3float) -> aac (native)) Press [q] to stop, [?] for help cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream) [graph_1_in_0_1 @ 01E069A12A40] Setting 'time_base' to value '1/44100' [graph_1_in_0_1 @ 01E069A12A40] Setting 'sample_rate' to value '44100' [graph_1_in_0_1 @ 01E069A12A40] Setting 'sample_fmt' to value 'fltp' [graph_1_in_0_1 @ 01E069A12A40] Setting 'channel_layout' to value '0x3' [graph_1_in_0_1 @ 01E069A12A40] tb:1/44100 samplefmt:fltp samplerate:44100 chlayout:0x3 [format_out_0_1 @ 01E069A2F800] Setting 'sample_fmts' to value 'fltp' [format_out_0_1 @ 01E069A2F800] Setting 'sample_rates' to value '96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025
[FFmpeg-devel] [PATCH] libavcodec/qsvenc.c: Set height and width alignment when using mjpeg_qsv
From: JonCookCubic Setting FrameInfo.Width and Height as per review comments Signed-off-by: JonCookCubic --- libavcodec/qsvenc.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 9e416500e9..40904af388 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -470,6 +470,12 @@ static int init_video_param_jpeg(AVCodecContext *avctx, QSVEncContext *q) q->param.mfx.Quality = av_clip(avctx->global_quality, 1, 100); q->param.mfx.RestartInterval = 0; +q->width_align = 16; +q->height_align = 16; + +q->param.mfx.FrameInfo.Width = FFALIGN(avctx->width, q->width_align); +q->param.mfx.FrameInfo.Height = FFALIGN(avctx->height, q->height_align); + return 0; } -- 2.20.1.windows.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-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] libavcodec/qsvenc.c: Set height and width alignment when using mjpeg_qsv
Updated patch with FrameInfo.Width and Height set as per review comments Jon On Tue, 21 Jan 2020 at 11:47, Jon Cook wrote: > Hi Zhong, > > Thanks for your reply. > > > IMHO If you set the aligned value, FrameInfo.Width/Height shoule > > be changed to be: > > > >q->param.mfx.FrameInfo.Width = FFALIGN(avctx->width, q->width_align); > >q->param.mfx.FrameInfo.Height = FFALIGN(avctx->height, > q->height_align); > > Makes sense. I'll update the patch. This is my first time making changes > to the code so forgive any mistakes as I find my way around. > > > Could you help to provide detail steps (CLI and input video) to > > reproduce the issue? > > The command line I'm using is below along with the output without the > changes applied. Input video is not important, any video will do. There is > a little bit more about the problem here > http://ffmpeg.org/pipermail/ffmpeg-user/2019-November/046143.html > > Regards, > Jon > > $ ./ffmpeg.exe -loglevel debug -y -i C:/Users/jcook/Desktop/sample.avi > -c:v mjpeg_qsv output.mp4 > ffmpeg version N-95883-ga2fbdc6898 Copyright (c) 2000-2019 the FFmpeg > developers > built with Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27031.1 > for x64 > configuration: --toolchain=msvc --target-os=win64 --arch=x86_64 > --prefix=/ffmpeg --enable-shared --disable-static --enable-yasm > --enable-asm --enable-libmfx --enable-nonfree > libavutil 56. 36.101 / 56. 36.101 > libavcodec 58. 62.100 / 58. 62.100 > libavformat58. 35.100 / 58. 35.100 > libavdevice58. 9.101 / 58. 9.101 > libavfilter 7. 67.100 / 7. 67.100 > libswscale 5. 6.100 / 5. 6.100 > libswresample 3. 6.100 / 3. 6.100 > Splitting the commandline. > Reading option '-loglevel' ... matched as option 'loglevel' (set logging > level) with argument 'debug'. > Reading option '-y' ... matched as option 'y' (overwrite output files) > with argument '1'. > Reading option '-i' ... matched as input url with argument > 'C:/Users/jcook/Desktop/sample.avi'. > Reading option '-c:v' ... matched as option 'c' (codec name) with argument > 'mjpeg_qsv'. > Reading option 'output.mp4' ... matched as output url. > Finished splitting the commandline. > Parsing a group of options: global . > Applying option loglevel (set logging level) with argument debug. > Applying option y (overwrite output files) with argument 1. > Successfully parsed a group of options. > Parsing a group of options: input url C:/Users/jcook/Desktop/sample.avi. > Successfully parsed a group of options. > Opening an input file: C:/Users/jcook/Desktop/sample.avi. > [NULL @ 01E0699F8540] Opening 'C:/Users/jcook/Desktop/sample.avi' for > reading > [file @ 01E0699D8280] Setting default whitelist 'file,crypto' > [avi @ 01E0699F8540] Format avi probed with size=2048 and score=100 > [avi @ 01E0699D86C0] use odml:1 > st:1 removing common factor 36 from timebase > [avi @ 01E0699F8540] Before avformat_find_stream_info() pos: 4108 > bytes read:142280 seeks:5 nb_streams:2 > [mpeg4 @ 01E069A0AE00] Format yuv420p chosen by get_format(). > [avi @ 01E0699F8540] All info found > [avi @ 01E0699F8540] After avformat_find_stream_info() pos: 16409 > bytes read:142280 seeks:5 frames:21 > Input #0, avi, from 'C:/Users/jcook/Desktop/sample.avi': > Metadata: > encoder : MEncoder SVN-r33148-4.0.1 > Duration: 00:00:05.56, start: 0.00, bitrate: 540 kb/s > Stream #0:0, 1, 1/25: Video: mpeg4 (Simple Profile), 1 reference frame > (XVID / 0x44495658), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], 0/1, 425 > kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc > Stream #0:1, 20, 32/1225: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, > stereo, fltp, 100 kb/s > Successfully opened the file. > Parsing a group of options: output url output.mp4. > Applying option c:v (codec name) with argument mjpeg_qsv. > Successfully parsed a group of options. > Opening an output file: output.mp4. > [file @ 01E06B51B9C0] Setting default whitelist 'file,crypto' > Successfully opened the file. > detected 12 logical cores > Stream mapping: > Stream #0:0 -> #0:0 (mpeg4 (native) -> mjpeg (mjpeg_qsv)) > Stream #0:1 -> #0:1 (mp3 (mp3float) -> aac (native)) > Press [q] to stop, [?] for help > cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless > if it occurs once at the start per stream) > [graph_1_in_0_1 @ 01E069A12A40] Setting 'time_base' to value '1/44100' > [graph_1_in_0_1 @ 0
Re: [FFmpeg-devel] [PATCH] libavcodec/qsvenc.c: Set height and width alignment when using mjpeg_qsv
Giving up on how to update the patch. Going to delete this ticket and create a new one! Jon On Tue, 21 Jan 2020 at 12:30, Jon Cook wrote: > Updated patch with FrameInfo.Width and Height set as per review comments > > Jon > > On Tue, 21 Jan 2020 at 11:47, Jon Cook wrote: > >> Hi Zhong, >> >> Thanks for your reply. >> >> > IMHO If you set the aligned value, FrameInfo.Width/Height shoule >> > be changed to be: >> > >> >q->param.mfx.FrameInfo.Width = FFALIGN(avctx->width, >> q->width_align); >> >q->param.mfx.FrameInfo.Height = FFALIGN(avctx->height, >> q->height_align); >> >> Makes sense. I'll update the patch. This is my first time making changes >> to the code so forgive any mistakes as I find my way around. >> >> > Could you help to provide detail steps (CLI and input video) to >> > reproduce the issue? >> >> The command line I'm using is below along with the output without the >> changes applied. Input video is not important, any video will do. There is >> a little bit more about the problem here >> http://ffmpeg.org/pipermail/ffmpeg-user/2019-November/046143.html >> >> Regards, >> Jon >> >> $ ./ffmpeg.exe -loglevel debug -y -i C:/Users/jcook/Desktop/sample.avi >> -c:v mjpeg_qsv output.mp4 >> ffmpeg version N-95883-ga2fbdc6898 Copyright (c) 2000-2019 the FFmpeg >> developers >> built with Microsoft (R) C/C++ Optimizing Compiler Version >> 19.16.27031.1 for x64 >> configuration: --toolchain=msvc --target-os=win64 --arch=x86_64 >> --prefix=/ffmpeg --enable-shared --disable-static --enable-yasm >> --enable-asm --enable-libmfx --enable-nonfree >> libavutil 56. 36.101 / 56. 36.101 >> libavcodec 58. 62.100 / 58. 62.100 >> libavformat58. 35.100 / 58. 35.100 >> libavdevice58. 9.101 / 58. 9.101 >> libavfilter 7. 67.100 / 7. 67.100 >> libswscale 5. 6.100 / 5. 6.100 >> libswresample 3. 6.100 / 3. 6.100 >> Splitting the commandline. >> Reading option '-loglevel' ... matched as option 'loglevel' (set logging >> level) with argument 'debug'. >> Reading option '-y' ... matched as option 'y' (overwrite output files) >> with argument '1'. >> Reading option '-i' ... matched as input url with argument >> 'C:/Users/jcook/Desktop/sample.avi'. >> Reading option '-c:v' ... matched as option 'c' (codec name) with >> argument 'mjpeg_qsv'. >> Reading option 'output.mp4' ... matched as output url. >> Finished splitting the commandline. >> Parsing a group of options: global . >> Applying option loglevel (set logging level) with argument debug. >> Applying option y (overwrite output files) with argument 1. >> Successfully parsed a group of options. >> Parsing a group of options: input url C:/Users/jcook/Desktop/sample.avi. >> Successfully parsed a group of options. >> Opening an input file: C:/Users/jcook/Desktop/sample.avi. >> [NULL @ 01E0699F8540] Opening 'C:/Users/jcook/Desktop/sample.avi' for >> reading >> [file @ 01E0699D8280] Setting default whitelist 'file,crypto' >> [avi @ 01E0699F8540] Format avi probed with size=2048 and score=100 >> [avi @ 01E0699D86C0] use odml:1 >> st:1 removing common factor 36 from timebase >> [avi @ 01E0699F8540] Before avformat_find_stream_info() pos: 4108 >> bytes read:142280 seeks:5 nb_streams:2 >> [mpeg4 @ 01E069A0AE00] Format yuv420p chosen by get_format(). >> [avi @ 01E0699F8540] All info found >> [avi @ 01E0699F8540] After avformat_find_stream_info() pos: 16409 >> bytes read:142280 seeks:5 frames:21 >> Input #0, avi, from 'C:/Users/jcook/Desktop/sample.avi': >> Metadata: >> encoder : MEncoder SVN-r33148-4.0.1 >> Duration: 00:00:05.56, start: 0.00, bitrate: 540 kb/s >> Stream #0:0, 1, 1/25: Video: mpeg4 (Simple Profile), 1 reference >> frame (XVID / 0x44495658), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], 0/1, >> 425 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc >> Stream #0:1, 20, 32/1225: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, >> stereo, fltp, 100 kb/s >> Successfully opened the file. >> Parsing a group of options: output url output.mp4. >> Applying option c:v (codec name) with argument mjpeg_qsv. >> Successfully parsed a group of options. >> Opening an output file: output.mp4. >> [file @ 01E06B51B9C0] Setting default whitelist 'file,c
[FFmpeg-devel] [PATCH] libavcodec/qsvenc.c: Set height and width alignment when encoding with mjpeg_qsv
From: JonCookCubic Currently width_align and height_align are zero when encoding with mjpeg_qsv which causes "Error submitting the frame for encoding". This patch sets the alignments. There is a little bit more about the problem here http://ffmpeg.org/pipermail/ffmpeg-user/2019-November/046143.html The following command line shows the problem (output is without the patch applied). Input video is not important, any video will do. $ ./ffmpeg.exe -loglevel debug -y -i C:/Users/jcook/Desktop/sample.avi -c:v mjpeg_qsv output.mp4 ffmpeg version N-95883-ga2fbdc6898 Copyright (c) 2000-2019 the FFmpeg developers built with Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27031.1 for x64 configuration: --toolchain=msvc --target-os=win64 --arch=x86_64 --prefix=/ffmpeg --enable-shared --disable-static --enable-yasm --enable-asm --enable-libmfx --enable-nonfree libavutil 56. 36.101 / 56. 36.101 libavcodec 58. 62.100 / 58. 62.100 libavformat58. 35.100 / 58. 35.100 libavdevice58. 9.101 / 58. 9.101 libavfilter 7. 67.100 / 7. 67.100 libswscale 5. 6.100 / 5. 6.100 libswresample 3. 6.100 / 3. 6.100 Splitting the commandline. Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'. Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'. Reading option '-i' ... matched as input url with argument 'C:/Users/jcook/Desktop/sample.avi'. Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'mjpeg_qsv'. Reading option 'output.mp4' ... matched as output url. Finished splitting the commandline. Parsing a group of options: global . Applying option loglevel (set logging level) with argument debug. Applying option y (overwrite output files) with argument 1. Successfully parsed a group of options. Parsing a group of options: input url C:/Users/jcook/Desktop/sample.avi. Successfully parsed a group of options. Opening an input file: C:/Users/jcook/Desktop/sample.avi. [NULL @ 01E0699F8540] Opening 'C:/Users/jcook/Desktop/sample.avi' for reading [file @ 01E0699D8280] Setting default whitelist 'file,crypto' [avi @ 01E0699F8540] Format avi probed with size=2048 and score=100 [avi @ 01E0699D86C0] use odml:1 st:1 removing common factor 36 from timebase [avi @ 01E0699F8540] Before avformat_find_stream_info() pos: 4108 bytes read:142280 seeks:5 nb_streams:2 [mpeg4 @ 01E069A0AE00] Format yuv420p chosen by get_format(). [avi @ 01E0699F8540] All info found [avi @ 01E0699F8540] After avformat_find_stream_info() pos: 16409 bytes read:142280 seeks:5 frames:21 Input #0, avi, from 'C:/Users/jcook/Desktop/sample.avi': Metadata: encoder : MEncoder SVN-r33148-4.0.1 Duration: 00:00:05.56, start: 0.00, bitrate: 540 kb/s Stream #0:0, 1, 1/25: Video: mpeg4 (Simple Profile), 1 reference frame (XVID / 0x44495658), yuv420p(left), 320x240 [SAR 1:1 DAR 4:3], 0/1, 425 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc Stream #0:1, 20, 32/1225: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, fltp, 100 kb/s Successfully opened the file. Parsing a group of options: output url output.mp4. Applying option c:v (codec name) with argument mjpeg_qsv. Successfully parsed a group of options. Opening an output file: output.mp4. [file @ 01E06B51B9C0] Setting default whitelist 'file,crypto' Successfully opened the file. detected 12 logical cores Stream mapping: Stream #0:0 -> #0:0 (mpeg4 (native) -> mjpeg (mjpeg_qsv)) Stream #0:1 -> #0:1 (mp3 (mp3float) -> aac (native)) Press [q] to stop, [?] for help cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream) [graph_1_in_0_1 @ 01E069A12A40] Setting 'time_base' to value '1/44100' [graph_1_in_0_1 @ 01E069A12A40] Setting 'sample_rate' to value '44100' [graph_1_in_0_1 @ 01E069A12A40] Setting 'sample_fmt' to value 'fltp' [graph_1_in_0_1 @ 01E069A12A40] Setting 'channel_layout' to value '0x3' [graph_1_in_0_1 @ 01E069A12A40] tb:1/44100 samplefmt:fltp samplerate:44100 chlayout:0x3 [format_out_0_1 @ 01E069A2F800] Setting 'sample_fmts' to value 'fltp' [format_out_0_1 @ 01E069A2F800] Setting 'sample_rates' to value '96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025|8000|7350' [AVFilterGraph @ 01E069AA7100] query_formats: 4 queried, 9 merged, 0 already done, 0 delayed cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream) Last message repeated 20 times [mpeg4 @ 01E069A2EE00] Format yuv420p chosen by get_format(). cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream) Last message repeated 28 times [graph 0 input from stream 0:0 @ 01E069A31640] Setting 'video_size' to value '320x240' [graph 0 input from stream 0:0 @ 01E069A31640] Setting 'pix_fmt' to value
[FFmpeg-devel] Patch vf_blackdetect
This patch unify vf_blackdetect with af_silencedetect. Now the logging prints black_start and black_end in separate lines. This is the same behavior like af_silencedetect and it is also more useful for monitoring streams. 0001-unify-blackdetect-with-af_silencedetect.-Is-more-use.patch Description: Binary data ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] Last Patch: vf_blackdetect
Please forget the last patch! Something is not working right. Sorry! ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] Patch vf_blackdetect
This is now the working version from my last patch. Description: This patch unify vf_blackdetect with af_silencedetect. Now the logging prints black_start and black_end in separate lines. This is the same behavior like af_silencedetect and it is also more useful for monitoring streams. Is it ok, as attachment? 0001-unify-blackdetect-with-af_silencedetect.patch Description: Binary data ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/2] lavf/mp3enc: write encoder delay/padding upon closing
--- libavformat/mp3enc.c | 34 -- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index de63401..4c97fa1 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -111,6 +111,8 @@ typedef struct MP3Context { uint64_t bag[XING_NUM_BAGS]; int initial_bitrate; int has_variable_bitrate; +int delay; +int padding; /* index of the audio stream */ int audio_stream_idx; @@ -247,12 +249,7 @@ static int mp3_write_xing(AVFormatContext *s) ffio_fill(dyn_ctx, 0, 8); // empty replaygain fields 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) { -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, 0);// empty encoder delay/padding avio_w8(dyn_ctx, 0); // misc avio_w8(dyn_ctx, 0); // mp3gain @@ -345,10 +342,24 @@ static int mp3_write_audio_packet(AVFormatContext *s, AVPacket *pkt) #endif if (mp3->xing_offset) { +uint8_t *side_data = NULL; +int side_data_size = 0; + mp3_xing_add_frame(mp3, pkt); mp3->audio_size += pkt->size; mp3->audio_crc = av_crc(av_crc_get_table(AV_CRC_16_ANSI_LE), mp3->audio_crc, pkt->data, pkt->size); + +side_data = av_packet_get_side_data(pkt, +AV_PKT_DATA_SKIP_SAMPLES, +&side_data_size); +if (side_data && side_data_size >= 10) { +mp3->padding = FFMAX(AV_RL32(side_data + 4) + 528 + 1, 0); +if (!mp3->delay) +mp3->delay = FFMAX(AV_RL32(side_data) - 528 - 1, 0); +} else { +mp3->padding = 0; +} } } @@ -422,6 +433,17 @@ static void mp3_update_xing(AVFormatContext *s) } } +/* write encoder delay/padding */ +if (mp3->delay >= 1 << 12) { +mp3->delay = (1 << 12) - 1; +av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); +} +if (mp3->padding >= 1 << 12) { +mp3->padding = (1 << 12) - 1; +av_log(s, AV_LOG_WARNING, "Too many samples of trailing padding.\n"); +} +AV_WB24(mp3->xing_frame + mp3->xing_offset + 141, (mp3->delay << 12) + mp3->padding); + AV_WB32(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 8, mp3->audio_size); AV_WB16(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 4, mp3->audio_crc); -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/2] lavc/libmp3lame: send encoder delay/padding in packet side data
--- libavcodec/libmp3lame.c | 27 ++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index 5642264..e55aa85 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -50,6 +50,7 @@ typedef struct LAMEContext { int reservoir; int joint_stereo; int abr; +int delay_sent; float *samples_flt[2]; AudioFrameQueue afq; AVFloatDSPContext *fdsp; @@ -185,7 +186,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, { LAMEContext *s = avctx->priv_data; MPADecodeHeader hdr; -int len, ret, ch; +int len, ret, ch, discard_padding; int lame_result; uint32_t h; @@ -269,6 +270,30 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts, &avpkt->duration); +discard_padding = avctx->frame_size - avpkt->duration; +// Check if subtraction resulted in an overflow +if ((discard_padding < avctx->frame_size) != (avpkt->duration > 0)) { +av_log(avctx, AV_LOG_ERROR, "discard padding overflow\n"); +av_packet_unref(avpkt); +av_free(avpkt); +return AVERROR(EINVAL); +} +if ((!s->delay_sent && avctx->initial_padding > 0) || discard_padding > 0) { +uint8_t* side_data = av_packet_new_side_data(avpkt, + AV_PKT_DATA_SKIP_SAMPLES, + 10); +if(!side_data) { +av_packet_unref(avpkt); +av_free(avpkt); +return AVERROR(ENOMEM); +} +if (!s->delay_sent) { +AV_WL32(side_data, avctx->initial_padding); +s->delay_sent = 1; +} +AV_WL32(side_data + 4, discard_padding); +} + avpkt->size = len; *got_packet_ptr = 1; } -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 0/2] Fix gapless encoding/remuxing for MP3
Round trip wav->mp3->wav now preserves the correct number of samples. Remuxing mp3->mp3 with -c:a copy also preserves any existing gapless metadata in the Info tag. The code in libmp3lame.c to set AV_PKT_DATA_SKIP_SAMPLES was mostly copied from libopusenc.c. Jon Toohill (2): lavc/libmp3lame: send encoder delay/padding in packet side data lavf/mp3enc: write encoder delay/padding upon closing libavcodec/libmp3lame.c | 27 ++- libavformat/mp3enc.c| 34 -- 2 files changed, 54 insertions(+), 7 deletions(-) -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/5] lavf/mp3dec: pass Xing gapless metadata to AVCodecParameters
--- 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 5/5] lavf/mp3enc: write trailing_padding in Xing header
--- 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 4/5] ffmpeg: copy trailing_padding when using -acodec copy
--- 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/5] libmp3lame + mp3enc: removes decoder delay compensation
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 - xxx - 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 - xxx - 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 0/2] Minor fixes for encoder padding
These patches backport the trailing_padding field to AVCodecContext, add gapless information to the stream summary string, and fix some cases where trailing_padding was being lost. I'll continue working on supporting initial_padding and trailing_padding for MP3 encoding/decoding in a separate patch set. Jon Toohill (2): lavc: add trailing_padding to AVCodecContext to match AVCodecParameters. ffmpeg: copy trailing_padding when using -acodec copy doc/APIchanges | 4 ffmpeg.c | 1 + libavcodec/avcodec.h | 11 +++ libavcodec/utils.c | 40 +++- libavcodec/version.h | 2 +- 5 files changed, 40 insertions(+), 18 deletions(-) -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/2] lavc: add trailing_padding to AVCodecContext to match AVCodecParameters.
Shows encoder delay/padding in the stream summary if they are set. --- 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 209ab41..74145b2 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,10 @@ libavutil: 2015-08-28 API changes, most recent first: +2016-08-15 - xxx - lavc 57.53.100 - avcodec.h + Add trailing_padding to AVCodecContext to match the corresponding + field in AVCodecParameters. + 2016-08-04 - xxx - lavf 57.46.100 - avformat.h Add av_get_frame_filename2() diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 06c2b89..b43ee5a 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3524,6 +3524,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 783f62c..6f4d553 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -3258,6 +3258,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) { @@ -4103,14 +4107,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; @@ -4157,15 +4162,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 a697261..cdfc4f9 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 52 +#define LIBAVCODEC_VERSION_MINOR 53 #define LIBAVCODEC_VERSION
[FFmpeg-devel] [PATCH 2/2] ffmpeg: copy trailing_padding when using -acodec copy
--- ffmpeg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ffmpeg.c b/ffmpeg.c index bae515d..49a1b03 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/4] ffmpeg: re-copy codec contexts after encoding
This preserves changes to fields of AVCodecContext that get updated during encoding, such as trailing_padding (which may not be known until encoding is complete). --- ffmpeg.c | 15 +++ 1 file changed, 15 insertions(+) diff --git a/ffmpeg.c b/ffmpeg.c index df55a49..1e973f5 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -4243,6 +4243,21 @@ static int transcode(void) term_exit(); +/* update output codec contexts after encoding */ +for (i = 0; i < nb_output_streams; i++) { +ost = output_streams[i]; +if (ost->encoding_needed) { +ret = avcodec_copy_context( +output_files[ost->file_index]->ctx->streams[ost->index]->codec, +ost->enc_ctx); +if (ret < 0) { +av_log(ost, AV_LOG_ERROR, "Error copying final codec context: %s\n", av_err2str(ret)); +if (exit_on_error) +exit_program(1); +} +} +} + /* write the trailer if needed and close file */ for (i = 0; i < nb_output_files; i++) { os = output_files[i]->ctx; -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/4] lavc/libmp3lame: set trailing_padding after flushing encoder
--- libavcodec/libmp3lame.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index 5642264..1566921 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -218,6 +218,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } else { lame_result = lame_encode_flush(s->gfp, s->buffer + s->buffer_index, s->buffer_size - s->buffer_index); +avctx->trailing_padding = FFMAX(lame_get_encoder_padding(s->gfp) - 528 - 1, 0); } if (lame_result < 0) { if (lame_result == -1) { -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 0/4] Handle trailing_padding in MP3 Info tag
Trimming trailing_padding samples from the end of the track is not yet implemented. Jon Toohill (4): ffmpeg: re-copy codec contexts after encoding lavc/libmp3lame: set trailing_padding after flushing encoder lavf/mp3enc: write encoder delay/padding upon closing lavf/mp3dec: read encoder delay/padding from Info tag ffmpeg.c| 15 +++ libavcodec/libmp3lame.c | 1 + libavformat/mp3dec.c| 2 ++ libavformat/mp3enc.c| 20 +--- 4 files changed, 31 insertions(+), 7 deletions(-) -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 4/4] lavf/mp3dec: read encoder delay/padding from Info tag
--- libavformat/mp3dec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 56c7f8c..9cc85a3 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 + 528 + 1; +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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 3/4] lavf/mp3enc: write encoder delay/padding upon closing
trailing_padding is not known before encoding. --- libavformat/mp3enc.c | 20 +--- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index de63401..433b070 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -247,12 +247,7 @@ static int mp3_write_xing(AVFormatContext *s) ffio_fill(dyn_ctx, 0, 8); // empty replaygain fields 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) { -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, 0);// empty encoder delay/padding avio_w8(dyn_ctx, 0); // misc avio_w8(dyn_ctx, 0); // mp3gain @@ -381,7 +376,7 @@ static void mp3_update_xing(AVFormatContext *s) AVReplayGain *rg; uint16_t tag_crc; uint8_t *toc; -int i, rg_size; +int i, rg_size, delay, padding; /* replace "Xing" identification string with "Info" for CBR files. */ if (!mp3->has_variable_bitrate) @@ -422,6 +417,17 @@ static void mp3_update_xing(AVFormatContext *s) } } +/* write encoder delay/padding */ +delay = FFMAX(s->streams[0]->codec->initial_padding - 528 - 1, 0); +padding = s->streams[0]->codec->trailing_padding; +if (delay >= 1 << 12) { +av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); +} +if (padding >= 1 << 12) { +av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); +} +AV_WB24(mp3->xing_frame + mp3->xing_offset + 141, (delay << 12) + padding); + AV_WB32(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 8, mp3->audio_size); AV_WB16(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 4, mp3->audio_crc); -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 4/4] lavf/mp3dec: read encoder delay/padding from Info tag
A similar concern was raised in a previous related patch: http://ffmpeg.org/pipermail/ffmpeg-devel/2016-May/194690.html I think the resolution at the time was to go ahead with using both, since both are used widely and serve slightly different purposes, although I do agree that it's confusing. I think I could use AV_PKT_DATA_SKIP_SAMPLES here, and change mp3enc to use that to fill out the Info tag. But that only seems worthwhile to me if there is a general consensus to move to just AV_PKT_DATA_SKIP_SAMPLES (and deprecate/remove initial_padding and trailing_padding). If there's a concrete case where knowing trailing_padding at the start of a stream is necessary, then that's not possible, but I'm pretty new to this and don't know of one. Thoughts? Jon Toohill | Google Play Music | jtooh...@google.com | (650) 215-0770 On Mon, Sep 26, 2016 at 11:30 AM, wm4 wrote: > On Mon, 26 Sep 2016 10:13:39 -0700 > Jon Toohill wrote: > > > --- > > libavformat/mp3dec.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c > > index 56c7f8c..9cc85a3 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 + 528 + 1; > > +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; > > I'm somewhat suspicious about this, because mp3dec.c uses > AV_PKT_DATA_SKIP_SAMPLES to communicate delay/padding > (libavformat/utils.c turns the start_skip_samples field into side > data). So I'm not quite convinced is this mess of FFmpeg and Libav API > mixture is healthy. Opinions welcome. > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 0/4] Handle trailing_padding in MP3 Info tag
Trimming trailing_padding samples from the end of the track is not yet implemented. Jon Toohill (4): ffmpeg: re-copy codec parameters after encoding lavc/libmp3lame: set trailing_padding after flushing encoder lavf/mp3enc: write encoder delay/padding upon closing lavf/mp3dec: read encoder delay/padding from Info tag ffmpeg.c| 15 +++ libavcodec/libmp3lame.c | 1 + libavformat/mp3dec.c| 2 ++ libavformat/mp3enc.c| 20 +--- 4 files changed, 31 insertions(+), 7 deletions(-) -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/4] lavc/libmp3lame: set trailing_padding after flushing encoder
--- libavcodec/libmp3lame.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index 5642264..1566921 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -218,6 +218,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } else { lame_result = lame_encode_flush(s->gfp, s->buffer + s->buffer_index, s->buffer_size - s->buffer_index); +avctx->trailing_padding = FFMAX(lame_get_encoder_padding(s->gfp) - 528 - 1, 0); } if (lame_result < 0) { if (lame_result == -1) { -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/4] ffmpeg: re-copy codec contexts after encoding
This preserves changes to fields of AVCodecContext that get updated during encoding, such as trailing_padding (which may not be known until encoding is complete). --- ffmpeg.c | 15 +++ 1 file changed, 15 insertions(+) diff --git a/ffmpeg.c b/ffmpeg.c index df55a49..1e973f5 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -4243,6 +4243,21 @@ static int transcode(void) term_exit(); +/* update output codec contexts after encoding */ +for (i = 0; i < nb_output_streams; i++) { +ost = output_streams[i]; +if (ost->encoding_needed) { +ret = avcodec_copy_context( +output_files[ost->file_index]->ctx->streams[ost->index]->codec, +ost->enc_ctx); +if (ret < 0) { +av_log(ost, AV_LOG_ERROR, "Error copying final codec context: %s\n", av_err2str(ret)); +if (exit_on_error) +exit_program(1); +} +} +} + /* write the trailer if needed and close file */ for (i = 0; i < nb_output_files; i++) { os = output_files[i]->ctx; -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/4] ffmpeg: re-copy codec parameters after encoding
This preserves changes to fields of AVCodecParameters that get updated during encoding, such as trailing_padding (which may not be known until encoding is complete). --- ffmpeg.c | 15 +++ 1 file changed, 15 insertions(+) diff --git a/ffmpeg.c b/ffmpeg.c index d0f247e..0cdc762 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -4255,6 +4255,21 @@ static int transcode(void) term_exit(); +/* update output codec parameters after encoding */ +for (i = 0; i < nb_output_streams; i++) { +ost = output_streams[i]; +if (ost->encoding_needed) { +ret = avcodec_parameters_from_context( + output_files[ost->file_index]->ctx->streams[ost->index]->codecpar, +ost->enc_ctx); +if (ret < 0) { +av_log(ost, AV_LOG_ERROR, "Error copying final codec context: %s\n", av_err2str(ret)); +if (exit_on_error) +exit_program(1); +} +} +} + /* write the trailer if needed and close file */ for (i = 0; i < nb_output_files; i++) { os = output_files[i]->ctx; -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 2/4] lavc/libmp3lame: set trailing_padding after flushing encoder
On Tue, Sep 27, 2016 at 1:04 AM, Carl Eugen Hoyos wrote: > 2016-09-26 19:13 GMT+02:00 Jon Toohill >: > > > +avctx->trailing_padding = FFMAX(lame_get_encoder_padding(s->gfp) > - 528 - 1, 0); > > Can you confirm that this function exists in lame 3.98.3? > I downloaded the source tarball for lame 3.98 and found it exists there. Is that sufficient? > > Thank you, Carl Eugen > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 3/4] lavf/mp3enc: write encoder delay/padding upon closing
trailing_padding is not known before encoding. --- libavformat/mp3enc.c | 20 +--- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index de63401..37608f1 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -247,12 +247,7 @@ static int mp3_write_xing(AVFormatContext *s) ffio_fill(dyn_ctx, 0, 8); // empty replaygain fields 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) { -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, 0);// empty encoder delay/padding avio_w8(dyn_ctx, 0); // misc avio_w8(dyn_ctx, 0); // mp3gain @@ -381,7 +376,7 @@ static void mp3_update_xing(AVFormatContext *s) AVReplayGain *rg; uint16_t tag_crc; uint8_t *toc; -int i, rg_size; +int i, rg_size, delay, padding; /* replace "Xing" identification string with "Info" for CBR files. */ if (!mp3->has_variable_bitrate) @@ -422,6 +417,17 @@ static void mp3_update_xing(AVFormatContext *s) } } +/* write encoder delay/padding */ +delay = FFMAX(s->streams[0]->codecpar->initial_padding - 528 - 1, 0); +padding = s->streams[0]->codecpar->trailing_padding; +if (delay >= 1 << 12) { +av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); +} +if (padding >= 1 << 12) { +av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); +} +AV_WB24(mp3->xing_frame + mp3->xing_offset + 141, (delay << 12) + padding); + AV_WB32(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 8, mp3->audio_size); AV_WB16(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 4, mp3->audio_crc); -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 4/4] lavf/mp3dec: read encoder delay/padding from Info tag
--- libavformat/mp3dec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 56c7f8c..9cc85a3 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 + 528 + 1; +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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 0/4] Handle trailing_padding in MP3 Info tag
Oops, forgot to send this in reply to the previous thread. Should I re-send? http://ffmpeg.org/pipermail/ffmpeg-devel/2016-September/200092.html On Wed, Sep 28, 2016 at 11:28 AM, Jon Toohill wrote: > Trimming trailing_padding samples from the end of the track is not yet > implemented. > > Jon Toohill (4): > ffmpeg: re-copy codec parameters after encoding > lavc/libmp3lame: set trailing_padding after flushing encoder > lavf/mp3enc: write encoder delay/padding upon closing > lavf/mp3dec: read encoder delay/padding from Info tag > > ffmpeg.c| 15 +++ > libavcodec/libmp3lame.c | 1 + > libavformat/mp3dec.c| 2 ++ > libavformat/mp3enc.c| 20 +--- > 4 files changed, 31 insertions(+), 7 deletions(-) > > -- > 2.8.0.rc3.226.g39d4020 > > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/4] ffmpeg: re-copy codec contexts after encoding
This was sent in error, please disregard. Jon Toohill | Google Play Music | jtooh...@google.com | (650) 215-0770 On Wed, Sep 28, 2016 at 11:28 AM, Jon Toohill wrote: > This preserves changes to fields of AVCodecContext that get > updated during encoding, such as trailing_padding (which > may not be known until encoding is complete). > --- > ffmpeg.c | 15 +++ > 1 file changed, 15 insertions(+) > > diff --git a/ffmpeg.c b/ffmpeg.c > index df55a49..1e973f5 100644 > --- a/ffmpeg.c > +++ b/ffmpeg.c > @@ -4243,6 +4243,21 @@ static int transcode(void) > > term_exit(); > > +/* update output codec contexts after encoding */ > +for (i = 0; i < nb_output_streams; i++) { > +ost = output_streams[i]; > +if (ost->encoding_needed) { > +ret = avcodec_copy_context( > +output_files[ost->file_index]->ctx->streams[ost->index]-> > codec, > +ost->enc_ctx); > +if (ret < 0) { > +av_log(ost, AV_LOG_ERROR, "Error copying final codec > context: %s\n", av_err2str(ret)); > +if (exit_on_error) > +exit_program(1); > +} > +} > +} > + > /* write the trailer if needed and close file */ > for (i = 0; i < nb_output_files; i++) { > os = output_files[i]->ctx; > -- > 2.8.0.rc3.226.g39d4020 > > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/3] lavc/libmp3lame: send encoder padding in side data of final packet
--- libavcodec/libmp3lame.c | 21 - 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index 5642264..a1bf122 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -185,7 +185,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, { LAMEContext *s = avctx->priv_data; MPADecodeHeader hdr; -int len, ret, ch; +int len, ret, ch, discard_padding; int lame_result; uint32_t h; @@ -269,6 +269,25 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts, &avpkt->duration); +discard_padding = avctx->frame_size - avpkt->duration; +// Check if subtraction resulted in an overflow +if ((discard_padding < avctx->frame_size) != (avpkt->duration > 0)) { +av_packet_unref(avpkt); +av_free(avpkt); +return AVERROR(EINVAL); +} +if (discard_padding > 0) { +uint8_t* side_data = av_packet_new_side_data(avpkt, + AV_PKT_DATA_SKIP_SAMPLES, + 10); +if(!side_data) { +av_packet_unref(avpkt); +av_free(avpkt); +return AVERROR(ENOMEM); +} +AV_WL32(side_data + 4, discard_padding); +} + avpkt->size = len; *got_packet_ptr = 1; } -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/3] lavf/mp3enc: write encoder delay/padding upon closing
--- libavformat/mp3enc.c | 32 +--- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index de63401..48cb0b4 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -111,6 +111,7 @@ typedef struct MP3Context { uint64_t bag[XING_NUM_BAGS]; int initial_bitrate; int has_variable_bitrate; +int trailing_padding; /* index of the audio stream */ int audio_stream_idx; @@ -247,12 +248,7 @@ static int mp3_write_xing(AVFormatContext *s) ffio_fill(dyn_ctx, 0, 8); // empty replaygain fields 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) { -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, 0);// empty encoder delay/padding avio_w8(dyn_ctx, 0); // misc avio_w8(dyn_ctx, 0); // mp3gain @@ -345,10 +341,22 @@ static int mp3_write_audio_packet(AVFormatContext *s, AVPacket *pkt) #endif if (mp3->xing_offset) { +uint8_t *side_data = NULL; +int side_data_size = 0; + mp3_xing_add_frame(mp3, pkt); mp3->audio_size += pkt->size; mp3->audio_crc = av_crc(av_crc_get_table(AV_CRC_16_ANSI_LE), mp3->audio_crc, pkt->data, pkt->size); + +side_data = av_packet_get_side_data(pkt, +AV_PKT_DATA_SKIP_SAMPLES, +&side_data_size); +if (side_data && side_data_size >= 10) { +mp3->trailing_padding = AV_RL32(side_data + 4); +} else { +mp3->trailing_padding = 0; +} } } @@ -381,7 +389,7 @@ static void mp3_update_xing(AVFormatContext *s) AVReplayGain *rg; uint16_t tag_crc; uint8_t *toc; -int i, rg_size; +int i, rg_size, delay; /* replace "Xing" identification string with "Info" for CBR files. */ if (!mp3->has_variable_bitrate) @@ -422,6 +430,16 @@ static void mp3_update_xing(AVFormatContext *s) } } +/* write encoder delay/padding */ +delay = FFMAX(s->streams[0]->codecpar->initial_padding - 528 - 1, 0); +if (delay >= 1 << 12) { +av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); +} +if (mp3->trailing_padding >= 1 << 12) { +av_log(s, AV_LOG_WARNING, "Too many samples of trailing padding.\n"); +} +AV_WB24(mp3->xing_frame + mp3->xing_offset + 141, (delay << 12) + mp3->trailing_padding); + AV_WB32(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 8, mp3->audio_size); AV_WB16(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 4, mp3->audio_crc); -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 0/3] Fix gapless encoding/decoding for MP3
Round trip wav->mp3->wav now preserves the correct number of samples. Remuxing mp3->mp3 with -c:a copy also preserves any existing gapless metadata in the Info tag. The code in libmp3lame.c to set AV_PKT_DATA_SKIP_SAMPLES was mostly copied from libopusenc.c. Jon Toohill (3): lavc/libmp3lame: send encoder padding in side data of final packet lavf/mp3enc: write encoder delay/padding upon closing lavf/mp3dec: read encoder delay/padding from Info tag libavcodec/libmp3lame.c | 21 - libavformat/mp3dec.c | 3 ++- libavformat/mp3enc.c | 32 +--- tests/ref/fate/audiomatch-square-mp3 | 2 +- tests/ref/fate/gapless-mp3 | 10 +- 5 files changed, 53 insertions(+), 15 deletions(-) -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 3/3] lavf/mp3dec: read encoder delay/padding from Info tag
Muxers can check AVCodecParameters.initial_padding for the encoder+decoder delay, and read the AV_PKT_DATA_SKIP_SAMPLES side data from the last packet for the encoder padding. This change also fixes the first_discard_sample calculation which erroneously included the decoder delay. Decoder delay is already accounted for in st->skip_samples. The affected FATE tests have been updated accordingly. --- libavformat/mp3dec.c | 3 ++- tests/ref/fate/audiomatch-square-mp3 | 2 +- tests/ref/fate/gapless-mp3 | 10 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 56c7f8c..e8b2428 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -239,9 +239,10 @@ 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 + 528 + 1; 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; +st->first_discard_sample = -mp3->end_pad + mp3->frames * (int64_t)spf; st->last_discard_sample = mp3->frames * (int64_t)spf; } if (!st->start_time) diff --git a/tests/ref/fate/audiomatch-square-mp3 b/tests/ref/fate/audiomatch-square-mp3 index 8de55c2..05176a0 100644 --- a/tests/ref/fate/audiomatch-square-mp3 +++ b/tests/ref/fate/audiomatch-square-mp3 @@ -1 +1 @@ -presig: 0 postsig:0 c: 0.9447 lenerr:0 +presig: 0 postsig:-529 c: 0.9334 lenerr:-529 diff --git a/tests/ref/fate/gapless-mp3 b/tests/ref/fate/gapless-mp3 index ebe7bfa..8b80bfc 100644 --- a/tests/ref/fate/gapless-mp3 +++ b/tests/ref/fate/gapless-mp3 @@ -1,5 +1,5 @@ -37534a3bcc3ef306e8c5ebfcfedfc41c *tests/data/fate/gapless-mp3.out-1 -c96c3ae7bd3300fd2f4debac222de5b7 -0cd1cdbcfd5cdbf6270cd98219bf31cd *tests/data/fate/gapless-mp3.out-2 -c96c3ae7bd3300fd2f4debac222de5b7 -9d3d8ba8a61b534f2d02ee648d6a8229 *tests/data/fate/gapless-mp3.out-3 +81695be427d45e8be4d527a6b2af2a85 *tests/data/fate/gapless-mp3.out-1 +c7879a827ab017364774069268d9a267 +62d074296f8c84a5f86a6afdd7bab459 *tests/data/fate/gapless-mp3.out-2 +c7879a827ab017364774069268d9a267 +e931f3fe1ba25e0d5eece4977c4061a9 *tests/data/fate/gapless-mp3.out-3 -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 3/3] lavf/mp3dec: read encoder delay/padding from Info tag
On Tue, Oct 4, 2016 at 7:19 AM, wm4 wrote: > On Mon, 3 Oct 2016 17:45:08 -0700 > Jon Toohill wrote: > > > Muxers can check AVCodecParameters.initial_padding for the > > encoder+decoder delay, and read the AV_PKT_DATA_SKIP_SAMPLES > > side data from the last packet for the encoder padding. > > > > This change also fixes the first_discard_sample calculation > > which erroneously included the decoder delay. Decoder delay > > is already accounted for in st->skip_samples. The affected > > FATE tests have been updated accordingly. > > --- > > libavformat/mp3dec.c | 3 ++- > > tests/ref/fate/audiomatch-square-mp3 | 2 +- > > tests/ref/fate/gapless-mp3 | 10 +- > > 3 files changed, 8 insertions(+), 7 deletions(-) > > > > diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c > > index 56c7f8c..e8b2428 100644 > > --- a/libavformat/mp3dec.c > > +++ b/libavformat/mp3dec.c > > @@ -239,9 +239,10 @@ 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 + 528 + 1; > > 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; > > +st->first_discard_sample = -mp3->end_pad + mp3->frames * > (int64_t)spf; > > How does mixing these even make sense? > mp3enc.c already uses initial_padding for the encoder delay, and as you previously pointed out, mp3dec.c already uses AV_PKT_START_SKIP_SAMPLES for the encoder delay. I'm not attempting to solve the inconsistency in this patch set. > > st->last_discard_sample = mp3->frames * (int64_t)spf; > > } > > if (!st->start_time) > > diff --git a/tests/ref/fate/audiomatch-square-mp3 > b/tests/ref/fate/audiomatch-square-mp3 > > index 8de55c2..05176a0 100644 > > --- a/tests/ref/fate/audiomatch-square-mp3 > > +++ b/tests/ref/fate/audiomatch-square-mp3 > > @@ -1 +1 @@ > > -presig: 0 postsig:0 c: 0.9447 lenerr:0 > > +presig: 0 postsig:-529 c: 0.9334 lenerr:-529 > > diff --git a/tests/ref/fate/gapless-mp3 b/tests/ref/fate/gapless-mp3 > > index ebe7bfa..8b80bfc 100644 > > --- a/tests/ref/fate/gapless-mp3 > > +++ b/tests/ref/fate/gapless-mp3 > > @@ -1,5 +1,5 @@ > > -37534a3bcc3ef306e8c5ebfcfedfc41c *tests/data/fate/gapless-mp3.out-1 > > -c96c3ae7bd3300fd2f4debac222de5b7 > > -0cd1cdbcfd5cdbf6270cd98219bf31cd *tests/data/fate/gapless-mp3.out-2 > > -c96c3ae7bd3300fd2f4debac222de5b7 > > -9d3d8ba8a61b534f2d02ee648d6a8229 *tests/data/fate/gapless-mp3.out-3 > > +81695be427d45e8be4d527a6b2af2a85 *tests/data/fate/gapless-mp3.out-1 > > +c7879a827ab017364774069268d9a267 > > +62d074296f8c84a5f86a6afdd7bab459 *tests/data/fate/gapless-mp3.out-2 > > +c7879a827ab017364774069268d9a267 > > +e931f3fe1ba25e0d5eece4977c4061a9 *tests/data/fate/gapless-mp3.out-3 > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 3/3] lavf/mp3dec: read encoder delay/padding from Info tag
On Tue, Oct 4, 2016 at 9:10 AM, Michael Niedermayer wrote: > On Mon, Oct 03, 2016 at 05:45:08PM -0700, Jon Toohill wrote: > > Muxers can check AVCodecParameters.initial_padding for the > > encoder+decoder delay, and read the AV_PKT_DATA_SKIP_SAMPLES > > side data from the last packet for the encoder padding. > > > > This change also fixes the first_discard_sample calculation > > which erroneously included the decoder delay. Decoder delay > > is already accounted for in st->skip_samples. The affected > > FATE tests have been updated accordingly. > > --- > > libavformat/mp3dec.c | 3 ++- > > tests/ref/fate/audiomatch-square-mp3 | 2 +- > > tests/ref/fate/gapless-mp3 | 10 +- > > 3 files changed, 8 insertions(+), 7 deletions(-) > > > > diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c > > index 56c7f8c..e8b2428 100644 > > --- a/libavformat/mp3dec.c > > +++ b/libavformat/mp3dec.c > > @@ -239,9 +239,10 @@ 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 + 528 + 1; > > 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; > > +st->first_discard_sample = -mp3->end_pad + mp3->frames * > (int64_t)spf; > > st->last_discard_sample = mp3->frames * (int64_t)spf; > > } > > if (!st->start_time) > > diff --git a/tests/ref/fate/audiomatch-square-mp3 > b/tests/ref/fate/audiomatch-square-mp3 > > index 8de55c2..05176a0 100644 > > --- a/tests/ref/fate/audiomatch-square-mp3 > > +++ b/tests/ref/fate/audiomatch-square-mp3 > > @@ -1 +1 @@ > > -presig: 0 postsig:0 c: 0.9447 lenerr:0 > > +presig: 0 postsig:-529 c: 0.9334 lenerr:-529 > > isnt this exactly correct before and wrong after this change ? > > zero signal before and zero signal after the original is what one would > expect and equal length and high correlation > > every number that changes gets worse > Michael - you're right, this patch is incorrect currently. I had mistakenly convinced myself that mp3dec.c was overcompensating for the decoder delay. I also found that LAME itself writes the encoder padding + decoder delay into the trailing padding field (e.g. for an input where 468 samples of padding are added by the encoder, the Info tag contains the value 997). I'll send a revised patch set. > [...] > > -- > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB > > Never trust a computer, one day, it may think you are the virus. -- Compn > > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 3/3] lavf/mp3dec: read encoder delay/padding from Info tag
On Wed, Oct 5, 2016 at 10:40 AM, Jon Toohill wrote: > On Tue, Oct 4, 2016 at 7:19 AM, wm4 wrote: > >> On Mon, 3 Oct 2016 17:45:08 -0700 >> Jon Toohill wrote: >> >> > Muxers can check AVCodecParameters.initial_padding for the >> > encoder+decoder delay, and read the AV_PKT_DATA_SKIP_SAMPLES >> > side data from the last packet for the encoder padding. >> > >> > This change also fixes the first_discard_sample calculation >> > which erroneously included the decoder delay. Decoder delay >> > is already accounted for in st->skip_samples. The affected >> > FATE tests have been updated accordingly. >> > --- >> > libavformat/mp3dec.c | 3 ++- >> > tests/ref/fate/audiomatch-square-mp3 | 2 +- >> > tests/ref/fate/gapless-mp3 | 10 +- >> > 3 files changed, 8 insertions(+), 7 deletions(-) >> > >> > diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c >> > index 56c7f8c..e8b2428 100644 >> > --- a/libavformat/mp3dec.c >> > +++ b/libavformat/mp3dec.c >> > @@ -239,9 +239,10 @@ 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 + 528 + 1; >> > 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; >> > +st->first_discard_sample = -mp3->end_pad + mp3->frames * >> (int64_t)spf; >> >> How does mixing these even make sense? >> > > mp3enc.c already uses initial_padding for the encoder delay, and as you > previously pointed out, mp3dec.c already uses AV_PKT_START_SKIP_SAMPLES for > the encoder delay. I'm not attempting to solve the inconsistency in this > patch set. > err, *mp3dec.c already uses AV_PKT_DATA_SKIP_SAMPLES for the encoder padding. Sorry for the confusion. > > >> > st->last_discard_sample = mp3->frames * (int64_t)spf; >> > } >> > if (!st->start_time) >> > diff --git a/tests/ref/fate/audiomatch-square-mp3 >> b/tests/ref/fate/audiomatch-square-mp3 >> > index 8de55c2..05176a0 100644 >> > --- a/tests/ref/fate/audiomatch-square-mp3 >> > +++ b/tests/ref/fate/audiomatch-square-mp3 >> > @@ -1 +1 @@ >> > -presig: 0 postsig:0 c: 0.9447 lenerr:0 >> > +presig: 0 postsig:-529 c: 0.9334 lenerr:-529 >> > diff --git a/tests/ref/fate/gapless-mp3 b/tests/ref/fate/gapless-mp3 >> > index ebe7bfa..8b80bfc 100644 >> > --- a/tests/ref/fate/gapless-mp3 >> > +++ b/tests/ref/fate/gapless-mp3 >> > @@ -1,5 +1,5 @@ >> > -37534a3bcc3ef306e8c5ebfcfedfc41c *tests/data/fate/gapless-mp3.out-1 >> > -c96c3ae7bd3300fd2f4debac222de5b7 >> > -0cd1cdbcfd5cdbf6270cd98219bf31cd *tests/data/fate/gapless-mp3.out-2 >> > -c96c3ae7bd3300fd2f4debac222de5b7 >> > -9d3d8ba8a61b534f2d02ee648d6a8229 *tests/data/fate/gapless-mp3.out-3 >> > +81695be427d45e8be4d527a6b2af2a85 *tests/data/fate/gapless-mp3.out-1 >> > +c7879a827ab017364774069268d9a267 >> > +62d074296f8c84a5f86a6afdd7bab459 *tests/data/fate/gapless-mp3.out-2 >> > +c7879a827ab017364774069268d9a267 >> > +e931f3fe1ba25e0d5eece4977c4061a9 *tests/data/fate/gapless-mp3.out-3 >> ___ >> ffmpeg-devel mailing list >> ffmpeg-devel@ffmpeg.org >> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >> > > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 3/3] lavf/mp3dec: read encoder delay/padding from Info tag
On Wed, Oct 5, 2016 at 11:03 AM, wm4 wrote: > On Wed, 5 Oct 2016 10:42:13 -0700 > Jon Toohill wrote: > > > On Wed, Oct 5, 2016 at 10:40 AM, Jon Toohill > wrote: > > > > > On Tue, Oct 4, 2016 at 7:19 AM, wm4 wrote: > > > > > >> On Mon, 3 Oct 2016 17:45:08 -0700 > > >> Jon Toohill wrote: > > >> > > >> > Muxers can check AVCodecParameters.initial_padding for the > > >> > encoder+decoder delay, and read the AV_PKT_DATA_SKIP_SAMPLES > > >> > side data from the last packet for the encoder padding. > > >> > > > >> > This change also fixes the first_discard_sample calculation > > >> > which erroneously included the decoder delay. Decoder delay > > >> > is already accounted for in st->skip_samples. The affected > > >> > FATE tests have been updated accordingly. > > >> > --- > > >> > libavformat/mp3dec.c | 3 ++- > > >> > tests/ref/fate/audiomatch-square-mp3 | 2 +- > > >> > tests/ref/fate/gapless-mp3 | 10 +- > > >> > 3 files changed, 8 insertions(+), 7 deletions(-) > > >> > > > >> > diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c > > >> > index 56c7f8c..e8b2428 100644 > > >> > --- a/libavformat/mp3dec.c > > >> > +++ b/libavformat/mp3dec.c > > >> > @@ -239,9 +239,10 @@ 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 + 528 + 1; > > >> > 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; > > >> > +st->first_discard_sample = -mp3->end_pad + mp3->frames > * > > >> (int64_t)spf; > > >> > > >> How does mixing these even make sense? > > >> > > > > > > mp3enc.c already uses initial_padding for the encoder delay, and as you > > > previously pointed out, mp3dec.c already uses > AV_PKT_START_SKIP_SAMPLES for > > > the encoder delay. I'm not attempting to solve the inconsistency in > this > > > patch set. > > > > > > > err, *mp3dec.c already uses AV_PKT_DATA_SKIP_SAMPLES for the encoder > > padding. Sorry for the confusion. > > > > Not solving the inconsistency is problematic - but the worse issue is > that you seem to introduce inconsistencies. In my current opinion, the > packet side data and the initial_padding fields do the same (i.e. > duplicated API), so only one of them can or should be used. Your patch > seems to require the decoder to use them both, though. > That's a fair point; I'll send a revised patch set that doesn't change mp3dec.c. Note that I don't think I can get away from having libmp3lame.c set AVCodecContext.initial_padding, since that field is used by the AudioFrameQueue (and other encoders rely on it as well). ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 0/2] Fix gapless encoding/remuxing for MP3
Round trip wav->mp3->wav now preserves the correct number of samples. Remuxing mp3->mp3 with -c:a copy also preserves any existing gapless metadata in the Info tag. The code in libmp3lame.c to set AV_PKT_DATA_SKIP_SAMPLES was mostly copied from libopusenc.c. Jon Toohill (2): lavc/libmp3lame: send encoder delay/padding in packet side data lavf/mp3enc: write encoder delay/padding upon closing libavcodec/libmp3lame.c | 26 +- libavformat/mp3enc.c| 34 +++--- 2 files changed, 52 insertions(+), 8 deletions(-) -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/2] lavc/libmp3lame: send encoder delay/padding in packet side data
--- libavcodec/libmp3lame.c | 26 +- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index 5642264..b3ba0d8 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -50,6 +50,7 @@ typedef struct LAMEContext { int reservoir; int joint_stereo; int abr; +int delay_sent; float *samples_flt[2]; AudioFrameQueue afq; AVFloatDSPContext *fdsp; @@ -185,7 +186,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, { LAMEContext *s = avctx->priv_data; MPADecodeHeader hdr; -int len, ret, ch; +int len, ret, ch, discard_padding; int lame_result; uint32_t h; @@ -269,6 +270,29 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts, &avpkt->duration); +discard_padding = avctx->frame_size - avpkt->duration; +// Check if subtraction resulted in an overflow +if ((discard_padding < avctx->frame_size) != (avpkt->duration > 0)) { +av_packet_unref(avpkt); +av_free(avpkt); +return AVERROR(EINVAL); +} +if ((!s->delay_sent && avctx->initial_padding > 0) || discard_padding > 0) { +uint8_t* side_data = av_packet_new_side_data(avpkt, + AV_PKT_DATA_SKIP_SAMPLES, + 10); +if(!side_data) { +av_packet_unref(avpkt); +av_free(avpkt); +return AVERROR(ENOMEM); +} +if (!s->delay_sent) { +AV_WL32(side_data, avctx->initial_padding); +s->delay_sent = 1; +} +AV_WL32(side_data + 4, discard_padding); +} + avpkt->size = len; *got_packet_ptr = 1; } -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/2] lavf/mp3enc: write encoder delay/padding upon closing
--- libavformat/mp3enc.c | 34 +++--- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index de63401..ddf4b93 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -111,6 +111,8 @@ typedef struct MP3Context { uint64_t bag[XING_NUM_BAGS]; int initial_bitrate; int has_variable_bitrate; +int delay; +int padding; /* index of the audio stream */ int audio_stream_idx; @@ -247,12 +249,7 @@ static int mp3_write_xing(AVFormatContext *s) ffio_fill(dyn_ctx, 0, 8); // empty replaygain fields 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) { -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, 0);// empty encoder delay/padding avio_w8(dyn_ctx, 0); // misc avio_w8(dyn_ctx, 0); // mp3gain @@ -345,10 +342,24 @@ static int mp3_write_audio_packet(AVFormatContext *s, AVPacket *pkt) #endif if (mp3->xing_offset) { +uint8_t *side_data = NULL; +int side_data_size = 0; + mp3_xing_add_frame(mp3, pkt); mp3->audio_size += pkt->size; mp3->audio_crc = av_crc(av_crc_get_table(AV_CRC_16_ANSI_LE), mp3->audio_crc, pkt->data, pkt->size); + +side_data = av_packet_get_side_data(pkt, +AV_PKT_DATA_SKIP_SAMPLES, +&side_data_size); +if (side_data && side_data_size >= 10) { +mp3->padding = AV_RL32(side_data + 4) + 528 + 1; +if (!mp3->delay) +mp3->delay = FFMAX(AV_RL32(side_data) - 528 - 1, 0); +} else { +mp3->padding = 0; +} } } @@ -381,7 +392,7 @@ static void mp3_update_xing(AVFormatContext *s) AVReplayGain *rg; uint16_t tag_crc; uint8_t *toc; -int i, rg_size; +int i, rg_size, delay; /* replace "Xing" identification string with "Info" for CBR files. */ if (!mp3->has_variable_bitrate) @@ -422,6 +433,15 @@ static void mp3_update_xing(AVFormatContext *s) } } +/* write encoder delay/padding */ +if (mp3->delay >= 1 << 12) { +av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); +} +if (mp3->padding >= 1 << 12) { +av_log(s, AV_LOG_WARNING, "Too many samples of trailing padding.\n"); +} +AV_WB24(mp3->xing_frame + mp3->xing_offset + 141, (mp3->delay << 12) + mp3->padding); + AV_WB32(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 8, mp3->audio_size); AV_WB16(mp3->xing_frame + mp3->xing_offset + XING_SIZE - 4, mp3->audio_crc); -- 2.8.0.rc3.226.g39d4020 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] dh option in nnedi3
Hello All, sorry for that question - I know is open source and we can add option by ours self, but my knowledge is to limited for that. Is it possible to integrate the dh (double high) option from vapoursynth nnedi3 filter to the ffmpeg nnedi filter? I have start copy parts from the sources, but I hang from line 709 on in the ffmpeg version. Regards Jonathan ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/2] lavf/mp3dec: pass Xing gapless metadata to AVCodecParameters
From: Jon Toohill --- 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/2] lavc: show gapless info in stream summary
From: Jon Toohill 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 0/2] Pass Xing gapless metadata to users during mp3 parsing
Forgot to fix the author line in those patches, it should read "Jon Toohill " 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 | jtooh...@google.com | (650) 215-0770 On Tue, May 24, 2016 at 3:52 PM, Jon Toohill 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 > > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/2] lavc: show gapless info in stream summary
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 - xxx - lavc 57.43.100 - avcodec.h + Add trailing_padding to AVCodecContext to match the corresponding + field in AVCodecParameters. + 2016-04-27 - xxx - 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
[FFmpeg-devel] [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 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/2] lavf/mp3dec: pass Xing gapless metadata to AVCodecParameters
--- 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/2] lavf/mp3dec: pass Xing gapless metadata to AVCodecParameters
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 | jtooh...@google.com | (650) 215-0770 On Thu, May 26, 2016 at 7:51 PM, Michael Niedermayer 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 > > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/2] lavf/mp3dec: pass Xing gapless metadata to AVCodecParameters
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 | jtooh...@google.com | (650) 215-0770 On Wed, Jun 1, 2016 at 5:58 PM, Jon Toohill 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 | jtooh...@google.com | (650) 215-0770 > > On Thu, May 26, 2016 at 7:51 PM, Michael Niedermayer < > mich...@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 >> >> > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 0/3] 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. 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/3] lavf/mp3dec: pass Xing gapless metadata to AVCodecParameters
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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/3] lavc: show gapless info in stream summary
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 - xxx - lavc 57.47.100 - avcodec.h + Add trailing_padding to AVCodecContext to match the corresponding + field in AVCodecParameters. + 2016-04-27 - xxx - 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 LIBA
[FFmpeg-devel] [PATCH 3/3] ffmpeg: copy trailing_padding when using -acodec copy
--- 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/3] lavf/mp3dec: pass Xing gapless metadata to AVCodecParameters
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 | jtooh...@google.com | (650) 215-0770 On Fri, Jun 17, 2016 at 5:32 PM, Michael Niedermayer 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 > > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 0/5] 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. 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 3/5] lavc: show gapless info in stream summary
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 - xxx - lavc 57.48.100 - avcodec.h + Add trailing_padding to AVCodecContext to match the corresponding + field in AVCodecParameters. + 2016-07-12 - xxx - 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/versi
[FFmpeg-devel] I dont know asm too well =( but I have a tip: mem+sync and machine learning
i got this idea from postresql, a very small sql database server i see ffmpeg is broken down into optimized asm libraries for embedding in c etc programs, and i know a few things about asm, ie, hardware registers on cpu+, pump in data into a register, get data out, think it goes down the system bus but i was thinking someone could implement an upload to memory feature when uploading/decoding (kinda like a buffer, maybe a queue? add matrix field of vid, range of tiles, algorithm.. pop when done, algorithm etc , ) video and audio using asm, and implement a sync mechanism (basically a queue of registers from the matrice with data you need to process for stuff like deinterlace or fast moving video ) dont know how av is synced, maybe you can implement a buffer and a stream pointer system? you can do (i surmise) scale_cuda_register_with_image img, offset or upload to memory scale_cuda register_with_image image, offset upscale_cuda_register_with_image image, offset sync you can also use machine learning, which deals with matrices and i think hardware estimation of certain numbers it can also work well in writing/reading files, but now that i think of it c/dma allows you to upload data to the memory and access it until its freed, but you can do stuff like stream data into pointers, maybe that helps, would like it wont give a major preformance gain, but im hoping for the best hopefully that works, ffmpeg is good software! cant wait to hit usenet B) ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] fix for decklink_common.cpp
Hello everybody, on the Zeranoe forum we find out that there is two bugs in the decklink_common.cpp file. I build I patch and want to send them now to you. I hope is all right, I never did before a git format-patch... Regards! Jonathan fix-device_list-and-COM-initialization-failed_in decklink_common.patch Description: Binary data ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] fix for decklink_common.cpp
Hello Carl, that means that the patch is at the moment not useful?! This code comes from the decklink sdk and there was also the FAILED() defined, I think. I have the code from here: http://ffmpeg.zeranoe.com/forum/viewtopic.php?f=10&t=1823&start=10#p7580 and there they say it works. When is ok for you, I copy your answer to the zeranoe forum, then they can help me to fix it. 2014-12-02 16:45 GMT+01:00 Carl Eugen Hoyos : > Jon bae gmail.com> writes: > > > I hope is all right, I never did before a > > git format-patch... > > You used git format-patch perfectly, thank you. > > Your patch introduces tabs, they cannot be committed > to FFmpeg. You can find tabs with "tools/patcheck", > a script that is part of the source. > > Please do not replace av_log() with fprintf(). > Please do not move opening braces, just leave them > where they are now. > Please keep the indentation at four spaces. > > Assuming that the "free" fix is unrelated to the > remaining patch, please make it separate. > > (I don't know where FAILED() is defined and > therefore cannot comment on the actual patch and > if it can be simplified.) > > Thank you, Carl Eugen > > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] Patch for heap corruption run time error in decklink_common.cpp
Ok here a second run, I try to follow the instruction from Carl Eugen. This is the first patch for decklink_common.cpp. It fix this error: Unhandled exception at 0x76FA4102 (ntdll.dll) in ffmpeg.exe: 0xC374: A heap has been corrupted (parameters: 0x7701B4B0). Regards Jonathan >From e9bc8e910f515af4030054df3e6feb308f3208aa Mon Sep 17 00:00:00 2001 From: Jonathan Baecker Date: Tue, 2 Dec 2014 20:10:41 +0100 Subject: [PATCH 1/2] heap corruption run time error in decklink_common Signed-off-by: Jonathan Baecker --- libavdevice/decklink_common.cpp | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp index 9a9e44b..8eff910 100644 --- a/libavdevice/decklink_common.cpp +++ b/libavdevice/decklink_common.cpp @@ -69,9 +69,12 @@ static char *dup_wchar_to_utf8(wchar_t *w) } #define DECKLINK_STROLECHAR * #define DECKLINK_STRDUP dup_wchar_to_utf8 +#define DECKLINK_FREE(s) SysFreeString(s) #else #define DECKLINK_STRconst char * #define DECKLINK_STRDUP av_strdup +/* free() is needed for a string returned by the DeckLink SDL. */ +#define DECKLINK_FREE(s) free((void *) s) #endif HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName) @@ -81,8 +84,7 @@ HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName) if (hr != S_OK) return hr; *displayName = DECKLINK_STRDUP(tmpDisplayName); -/* free() is needed for a string returned by the DeckLink SDL. */ -free((void *) tmpDisplayName); +DECKLINK_FREE(tmpDisplayName); return hr; } -- 2.2.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] Patch for device list error in decklink_common.cpp
Here is the other patch for decklink_common.cpp. It fix the error: COM initialization failed [decklink @ 02e5b520] Could not create DeckLink iterator dummy: Immediate exit request Regards Jonathan >From 203eba2fad14dd6d84552d6c22899792e80b53bb Mon Sep 17 00:00:00 2001 From: Jonathan Baecker Date: Tue, 2 Dec 2014 20:12:38 +0100 Subject: [PATCH 2/2] device list error in decklink_common Signed-off-by: Jonathan Baecker --- libavdevice/decklink_common.cpp | 24 ++-- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp index 8eff910..8f7e32a 100644 --- a/libavdevice/decklink_common.cpp +++ b/libavdevice/decklink_common.cpp @@ -42,16 +42,20 @@ IDeckLinkIterator *CreateDeckLinkIteratorInstance(void) { IDeckLinkIterator *iter; -if (CoInitialize(NULL) != S_OK) { -av_log(NULL, AV_LOG_ERROR, "COM initialization failed.\n"); -return NULL; -} - -if (CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, - IID_IDeckLinkIterator, (void**) &iter) != S_OK) { -av_log(NULL, AV_LOG_ERROR, "DeckLink drivers not installed.\n"); -return NULL; -} +HRESULT result; +/* Initialize COM on this thread */ +result = CoInitialize(NULL); +if (FAILED(result)) { +av_log(NULL, AV_LOG_ERROR, "COM initialization failed.\n"); +return NULL; +} + +/* Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system */ +result = CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, IID_IDeckLinkIterator, (void**)&iter); +if (FAILED(result)) { +av_log(NULL, AV_LOG_ERROR, "DeckLink drivers not installed.\n"); +return NULL; +} return iter; } -- 2.2.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] Patch for device list error in decklink_common.cpp
Thanks Ramiro for the correction! Here is the new patch. (Is it better to post directly the patch, or is ok as a attachment?) Regards Jonathan 2014-12-02 22:19 GMT+01:00 Ramiro Polla : > > On 02.12.2014 20:30, Jon bae wrote: > >> Here is the other patch for decklink_common.cpp. It fix the error: >> >> COM initialization failed >> [decklink @ 02e5b520] Could not create DeckLink iterator >> dummy: Immediate exit request >> > > From 203eba2fad14dd6d84552d6c22899792e80b53bb Mon Sep 17 00:00:00 2001 >> From: Jonathan Baecker >> Date: Tue, 2 Dec 2014 20:12:38 +0100 >> Subject: [PATCH 2/2] device list error in decklink_common >> >> Signed-off-by: Jonathan Baecker >> --- >> libavdevice/decklink_common.cpp | 24 ++-- >> 1 file changed, 14 insertions(+), 10 deletions(-) >> >> diff --git a/libavdevice/decklink_common.cpp >> b/libavdevice/decklink_common.cpp >> index 8eff910..8f7e32a 100644 >> --- a/libavdevice/decklink_common.cpp >> +++ b/libavdevice/decklink_common.cpp >> @@ -42,16 +42,20 @@ IDeckLinkIterator *CreateDeckLinkIteratorInstance >> (void) >> { >> IDeckLinkIterator *iter; >> >> -if (CoInitialize(NULL) != S_OK) { >> -av_log(NULL, AV_LOG_ERROR, "COM initialization failed.\n"); >> -return NULL; >> -} >> - >> -if (CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, >> - IID_IDeckLinkIterator, (void**) &iter) != S_OK) >> { >> -av_log(NULL, AV_LOG_ERROR, "DeckLink drivers not installed.\n"); >> -return NULL; >> -} >> +HRESULT result; >> +/* Initialize COM on this thread */ >> +result = CoInitialize(NULL); >> +if (FAILED(result)) { >> +av_log(NULL, AV_LOG_ERROR, "COM initialization failed.\n"); >> +return NULL; >> +} >> + >> +/* Create an IDeckLinkIterator object to enumerate all DeckLink >> cards in the system */ >> +result = CoCreateInstance(CLSID_CDeckLinkIterator, NULL, >> CLSCTX_ALL, IID_IDeckLinkIterator, (void**)&iter); >> +if (FAILED(result)) { >> +av_log(NULL, AV_LOG_ERROR, "DeckLink drivers not installed.\n"); >> +return NULL; >> +} >> >> return iter; >> } >> -- >> 2.2.0 >> > > This code is Copyright (c) Blackmagic Design. Try just changing the check > for CoInitialize(NULL) from "!= S_OK" to "< 0". > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > 0001-fix-COM-initialization-failed.patch Description: Binary data ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] Patch for device list error in decklink_common.cpp
2014-12-03 15:46 GMT+01:00 Ramiro Polla : > > On 03.12.2014 12:06, Jon bae wrote: > >> Thanks Ramiro for the correction! >> Here is the new patch. (Is it better to post directly the patch, or is ok >> as a attachment?) >> > > Attachment is better. But please avoid top-posting in this mailing-list. > > > 2014-12-02 22:19 GMT+01:00 Ramiro Polla : >> >>> On 02.12.2014 20:30, Jon bae wrote: >>> >>>> Here is the other patch for decklink_common.cpp. It fix the error: >>>> >>>> COM initialization failed >>>> [decklink @ 02e5b520] Could not create DeckLink iterator >>>> dummy: Immediate exit request >>>> >>>> >>> From 203eba2fad14dd6d84552d6c22899792e80b53bb Mon Sep 17 00:00:00 2001 >>> >>>> From: Jonathan Baecker >>>> Date: Tue, 2 Dec 2014 20:12:38 +0100 >>>> Subject: [PATCH 2/2] device list error in decklink_common >>>> >>>> Signed-off-by: Jonathan Baecker >>>> --- >>>> libavdevice/decklink_common.cpp | 24 ++-- >>>> 1 file changed, 14 insertions(+), 10 deletions(-) >>>> >>>> diff --git a/libavdevice/decklink_common.cpp >>>> b/libavdevice/decklink_common.cpp >>>> index 8eff910..8f7e32a 100644 >>>> --- a/libavdevice/decklink_common.cpp >>>> +++ b/libavdevice/decklink_common.cpp >>>> @@ -42,16 +42,20 @@ IDeckLinkIterator *CreateDeckLinkIteratorInstance >>>> (void) >>>> { >>>> IDeckLinkIterator *iter; >>>> >>>> -if (CoInitialize(NULL) != S_OK) { >>>> -av_log(NULL, AV_LOG_ERROR, "COM initialization failed.\n"); >>>> -return NULL; >>>> -} >>>> - >>>> -if (CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, >>>> - IID_IDeckLinkIterator, (void**) &iter) != >>>> S_OK) >>>> { >>>> -av_log(NULL, AV_LOG_ERROR, "DeckLink drivers not >>>> installed.\n"); >>>> -return NULL; >>>> -} >>>> +HRESULT result; >>>> +/* Initialize COM on this thread */ >>>> +result = CoInitialize(NULL); >>>> +if (FAILED(result)) { >>>> +av_log(NULL, AV_LOG_ERROR, "COM initialization failed.\n"); >>>> +return NULL; >>>> +} >>>> + >>>> +/* Create an IDeckLinkIterator object to enumerate all DeckLink >>>> cards in the system */ >>>> +result = CoCreateInstance(CLSID_CDeckLinkIterator, NULL, >>>> CLSCTX_ALL, IID_IDeckLinkIterator, (void**)&iter); >>>> +if (FAILED(result)) { >>>> +av_log(NULL, AV_LOG_ERROR, "DeckLink drivers not >>>> installed.\n"); >>>> +return NULL; >>>> +} >>>> >>>> return iter; >>>> } >>>> -- >>>> 2.2.0 >>>> >>>> >>> This code is Copyright (c) Blackmagic Design. Try just changing the check >>> for CoInitialize(NULL) from "!= S_OK" to "< 0". >>> >> > > From 3c3d5dda659fe30c68a81b0a711cb09bcb5be443 Mon Sep 17 00:00:00 2001 >> From: Jonathan Baecker >> Date: Wed, 3 Dec 2014 12:03:12 +0100 >> Subject: [PATCH] fix COM initialization failed >> >> Signed-off-by: Jonathan Baecker >> --- >> libavdevice/decklink_common.cpp | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/libavdevice/decklink_common.cpp >> b/libavdevice/decklink_common.cpp >> index 6899bd2..4252552 100644 >> --- a/libavdevice/decklink_common.cpp >> +++ b/libavdevice/decklink_common.cpp >> @@ -42,13 +42,13 @@ IDeckLinkIterator *CreateDeckLinkIteratorInstance >> (void) >> { >> IDeckLinkIterator *iter; >> >> -if (CoInitialize(NULL) != S_OK) { >> +if (CoInitialize(NULL) < 0) { >> av_log(NULL, AV_LOG_ERROR, "COM initialization failed.\n"); >> return NULL; >> } >> > > if (CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, >> - IID_IDeckLinkIterator, (void**) &iter) != S_OK) >> { >> + IID_IDeckLinkIterator, (void**) &iter) < 0) { >> av_log(NULL, AV_LOG_ERROR, "DeckLink drivers not installed.\n"); >> return NULL; >> } >> > > The CoCreateInstance check doesn't need to be changed. Ok finally... Here now only the first line changed. Sorry for the mess, I 'm not the right person for that. 0001-fix-COM-initialization-failed.patch Description: Binary data ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] Question about supported_fps in libavutil/timecode.c::check_fps
Currently check_fps has the following logic: static int check_fps(int fps) { int i; static const int supported_fps[] = {24, 25, 30, 48, 50, 60}; for (i = 0; i < FF_ARRAY_ELEMS(supported_fps); i++) if (fps == supported_fps[i]) return 0; return -1; } I am starting to see more and more movies with fps rates in excess of this list from modified GoPro files and other raw camera sources. I was originally adding more entries as the sources came rolling in because I could not see any issue in how this was getting called later with that approach. I still don't see the drawback of adding more, but I am tired of adding a new rate every time I encounter one in the wild. I was curious if it wouldn't make more sense to change the logic to the following: static int check_fps(int fps) { int i; static const int supported_fps_bases[] = {24, 25, 30}; for (i = 0; i < FF_ARRAY_ELEMS(supported_fps_bases); i++) if (fps % supported_fps_bases[i] == 0) return 0; return -1; } If that makes sense to you, then I will submit a patch. Please let me know if I have overlooked some other usage/meaning of check_fps that I am overlooking. Thanks, Jon ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] Question about supported_fps in libavutil/timecode.c::check_fps
Patch attached for consideration. On 1/23/15 8:03 AM, jon morley wrote: Currently check_fps has the following logic: static int check_fps(int fps) { int i; static const int supported_fps[] = {24, 25, 30, 48, 50, 60}; for (i = 0; i < FF_ARRAY_ELEMS(supported_fps); i++) if (fps == supported_fps[i]) return 0; return -1; } I am starting to see more and more movies with fps rates in excess of this list from modified GoPro files and other raw camera sources. I was originally adding more entries as the sources came rolling in because I could not see any issue in how this was getting called later with that approach. I still don't see the drawback of adding more, but I am tired of adding a new rate every time I encounter one in the wild. I was curious if it wouldn't make more sense to change the logic to the following: static int check_fps(int fps) { int i; static const int supported_fps_bases[] = {24, 25, 30}; for (i = 0; i < FF_ARRAY_ELEMS(supported_fps_bases); i++) if (fps % supported_fps_bases[i] == 0) return 0; return -1; } If that makes sense to you, then I will submit a patch. Please let me know if I have overlooked some other usage/meaning of check_fps that I am overlooking. Thanks, Jon ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >From 73e5339ec76305d34214b5e84dc5a38673f784b7 Mon Sep 17 00:00:00 2001 From: Jon Morley Date: Fri, 23 Jan 2015 08:43:33 -0800 Subject: [PATCH] libavutil/timecode.c: Extend check_fps logic to handle high frame rates QuickTime sources continue to push higher and higher frame rates. This change moves away from explictly testing incoming fps values towards ensuring the incoming value is evenly divisable by 24, 25, or 30. --- libavutil/timecode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavutil/timecode.c b/libavutil/timecode.c index 1dfd040..c10895c 100644 --- a/libavutil/timecode.c +++ b/libavutil/timecode.c @@ -141,10 +141,10 @@ char *av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit) static int check_fps(int fps) { int i; -static const int supported_fps[] = {24, 25, 30, 48, 50, 60}; +static const int supported_fps_bases[] = {24, 25, 30}; -for (i = 0; i < FF_ARRAY_ELEMS(supported_fps); i++) -if (fps == supported_fps[i]) +for (i = 0; i < FF_ARRAY_ELEMS(supported_fps_bases); i++) +if (fps % supported_fps_bases[i] == 0) return 0; return -1; } -- 1.8.5.2 (Apple Git-48) ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] Question about supported_fps in libavutil/timecode.c::check_fps
Hi Clément, That is a good point! I am attaching an additional patch to remove those cases even before entering the mod test loop. Now the logic should look like this: static int check_fps(int fps) { if (fps <= 0) return -1; int i; static const int supported_fps_bases[] = {24, 25, 30}; for (i = 0; i < FF_ARRAY_ELEMS(supported_fps_bases); i++) if (fps % supported_fps_bases[i] == 0) return 0; return -1; } I am still really curious to know if switching to this division (modulo) test breaks the "spirit" of check_fps. I could not find anywhere that benefited from the explicit list the method currently used, but that doesn't mean it isn't out there. Thanks, Jon On 1/24/15 2:27 AM, Clément Bœsch wrote: On Fri, Jan 23, 2015 at 08:48:37AM -0800, jon morley wrote: Patch attached for consideration. On 1/23/15 8:03 AM, jon morley wrote: Currently check_fps has the following logic: static int check_fps(int fps) { int i; static const int supported_fps[] = {24, 25, 30, 48, 50, 60}; for (i = 0; i < FF_ARRAY_ELEMS(supported_fps); i++) if (fps == supported_fps[i]) return 0; return -1; } I am starting to see more and more movies with fps rates in excess of this list from modified GoPro files and other raw camera sources. I was originally adding more entries as the sources came rolling in because I could not see any issue in how this was getting called later with that approach. I still don't see the drawback of adding more, but I am tired of adding a new rate every time I encounter one in the wild. I was curious if it wouldn't make more sense to change the logic to the following: static int check_fps(int fps) { int i; static const int supported_fps_bases[] = {24, 25, 30}; for (i = 0; i < FF_ARRAY_ELEMS(supported_fps_bases); i++) if (fps % supported_fps_bases[i] == 0) return 0; return -1; } If that makes sense to you, then I will submit a patch. Please let me know if I have overlooked some other usage/meaning of check_fps that I am overlooking. Thanks, Jon ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel From 73e5339ec76305d34214b5e84dc5a38673f784b7 Mon Sep 17 00:00:00 2001 From: Jon Morley Date: Fri, 23 Jan 2015 08:43:33 -0800 Subject: [PATCH] libavutil/timecode.c: Extend check_fps logic to handle high frame rates QuickTime sources continue to push higher and higher frame rates. This change moves away from explictly testing incoming fps values towards ensuring the incoming value is evenly divisable by 24, 25, or 30. --- libavutil/timecode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavutil/timecode.c b/libavutil/timecode.c index 1dfd040..c10895c 100644 --- a/libavutil/timecode.c +++ b/libavutil/timecode.c @@ -141,10 +141,10 @@ char *av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit) static int check_fps(int fps) { int i; -static const int supported_fps[] = {24, 25, 30, 48, 50, 60}; +static const int supported_fps_bases[] = {24, 25, 30}; -for (i = 0; i < FF_ARRAY_ELEMS(supported_fps); i++) -if (fps == supported_fps[i]) +for (i = 0; i < FF_ARRAY_ELEMS(supported_fps_bases); i++) +if (fps % supported_fps_bases[i] == 0) return 0; return -1; I don't think you want to accept fps ≤ 0 [...] ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel From 0a72d78992bbeb6c2536285397149cceb64b05d8 Mon Sep 17 00:00:00 2001 From: Jon Morley Date: Sat, 24 Jan 2015 07:28:40 -0800 Subject: [PATCH 2/2] libavutil/timecode.c: check_fps must reject rates at or below zero An earlier change to check_fps's logic which now confirms that the incoming evaluation fps is evenly divisable by a list of supported rates leaves open the possibility of accepting zero and negative frame rates. This change removes that posibility. --- libavutil/timecode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavutil/timecode.c b/libavutil/timecode.c index c10895c..446e2d5 100644 --- a/libavutil/timecode.c +++ b/libavutil/timecode.c @@ -140,6 +140,8 @@ char *av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit) static int check_fps(int fps) { +if (fps <= 0) return -1; + int i; static const int supported_fps_bases[] = {24, 25, 30}; -- 1.8.5.2 (Apple Git-48) ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] Question about supported_fps in libavutil/timecode.c::check_fps
Hi Clément, I am sorry I was rude. That was not my intention. I was attempting to follow these directions from the ffmpeg.org page: "You can use the FFmpeg libraries in your commercial program, but you are encouraged to publish any patch you make. In this case the best way to proceed is to send your patches to the ffmpeg-devel mailing list following the guidelines illustrated in the remainder of this document." I will stick to mailing patches exclusively in the future. Patches reflecting your suggestions attached. Sincerely, Jon On 1/24/15 8:21 AM, Clément Bœsch wrote: On Sat, Jan 24, 2015 at 07:40:38AM -0800, jon morley wrote: Hi Clément, Hi, That is a good point! I am attaching an additional patch to remove those cases even before entering the mod test loop. Now the logic should look like this: static int check_fps(int fps) { if (fps <= 0) return -1; int i; static const int supported_fps_bases[] = {24, 25, 30}; You can't put statements before declarations, some compilers will choke on it. Also, please squash it with the previous patch since it wasn't applied yet. for (i = 0; i < FF_ARRAY_ELEMS(supported_fps_bases); i++) if (fps % supported_fps_bases[i] == 0) return 0; return -1; } I am still really curious to know if switching to this division (modulo) test breaks the "spirit" of check_fps. I could not find anywhere that benefited from the explicit list the method currently used, but that doesn't mean it isn't out there. I'm more concerned about how the rest of the code will behave. Typically, av_timecode_adjust_ntsc_framenum2() could benefit from some improvements (checking if fps % 30, and deducing drop_frames and frames_per_10mins accordingly) if you allow such thing. Then you might need to adjust check_timecode() as well to allow the drop frame for the other % 30. Thanks, Jon [...] Note: please do not top post on this mailing list, it is considered rude. Regards, ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >From 95f1fb3695f086de1baa301015985742d688a159 Mon Sep 17 00:00:00 2001 From: Jon Morley Date: Sat, 24 Jan 2015 12:18:50 -0800 Subject: [PATCH] libavutil/timecode.c: Add support for frame rates beyond 60 fps Instead of looking for specifically supported frame rates this collection of changes checks to see if the given rates are evenly divisible by supported common factors. --- libavutil/timecode.c | 33 - 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/libavutil/timecode.c b/libavutil/timecode.c index 1dfd040..c2469c0 100644 --- a/libavutil/timecode.c +++ b/libavutil/timecode.c @@ -33,18 +33,15 @@ int av_timecode_adjust_ntsc_framenum2(int framenum, int fps) { -/* only works for NTSC 29.97 and 59.94 */ +int factor = 1; int drop_frames = 0; int d, m, frames_per_10mins; -if (fps == 30) { -drop_frames = 2; -frames_per_10mins = 17982; -} else if (fps == 60) { -drop_frames = 4; -frames_per_10mins = 35964; -} else -return framenum; +if (fps < 30 || fps % 30 != 0) return framenum; + +factor = fps / 30; +drop_frames = factor * 2; +frames_per_10mins = factor * 17982; d = framenum / frames_per_10mins; m = framenum % frames_per_10mins; @@ -141,10 +138,12 @@ char *av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit) static int check_fps(int fps) { int i; -static const int supported_fps[] = {24, 25, 30, 48, 50, 60}; +static const int supported_fps_multiples[] = {24, 25, 30}; + +if (fps <= 0) return -1; -for (i = 0; i < FF_ARRAY_ELEMS(supported_fps); i++) -if (fps == supported_fps[i]) +for (i = 0; i < FF_ARRAY_ELEMS(supported_fps_multiples); i++) +if (fps % supported_fps_multiples[i] == 0) return 0; return -1; } @@ -155,8 +154,8 @@ static int check_timecode(void *log_ctx, AVTimecode *tc) av_log(log_ctx, AV_LOG_ERROR, "Timecode frame rate must be specified\n"); return AVERROR(EINVAL); } -if ((tc->flags & AV_TIMECODE_FLAG_DROPFRAME) && tc->fps != 30 && tc->fps != 60) { -av_log(log_ctx, AV_LOG_ERROR, "Drop frame is only allowed with 3/1001 or 6/1001 FPS\n"); +if ((tc->flags & AV_TIMECODE_FLAG_DROPFRAME) && tc->fps % 30 != 0) { +av_log(log_ctx, AV_LOG_ERROR, "Drop frame is only allowed in frame rates evenly divisible by 30 FPS\n"); return AVERROR(EINVAL); } if (check_fps(tc->fps) < 0) { @@ -201,9 +200,9 @@ int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *st } memset(tc, 0, sizeof(*tc)); -tc->flags = c !
[FFmpeg-devel] libavformat/movenc.c: Correct color range when writing DNxHD atoms
>From 0097277471810ab1d9d737c64a57c2278a039153 Mon Sep 17 00:00:00 2001 From: Jon Morley Date: Tue, 27 Jan 2015 11:10:27 -0800 Subject: [PATCH] libavformat/movenc.c: Correct color range when writing DNxHD atoms The meaning of the color range values in the AVdn.ACLR atom was swapped. This change makes the selection explicit and correctly mapped. --- libavformat/movenc.c | 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index d7ae5f0..dfe4c27 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -1039,10 +1039,13 @@ static int mov_write_avid_tag(AVIOContext *pb, MOVTrack *track) ffio_wfourcc(pb, "ACLR"); ffio_wfourcc(pb, "0001"); if (track->enc->color_range == AVCOL_RANGE_MPEG) { /* Legal range (16-235) */ -avio_wb32(pb, 1); /* Corresponds to 709 in official encoder */ -} else { /* Full range (0-255) */ -avio_wb32(pb, 2); /* Corresponds to RGB in official encoder */ +avio_wb32(pb, 2); /* Corresponds to 709 in official encoder */ +} else if (track->enc->color_range == AVCOL_RANGE_JPEG) { /* Full range (0-255) */ +avio_wb32(pb, 1); /* Corresponds to RGB in official encoder */ +} else { +avio_wb32(pb, 0); /* Unspecified */ } + avio_wb32(pb, 0); /* unknown */ avio_wb32(pb, 24); /* size */ -- 1.8.5.2 (Apple Git-48) ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] libavformat/movenc.c: Correct color range when writing DNxHD atoms
Hi Kevin, Michael, I appreciate your replies. I have been having a really hard time finding a definitive reference on the matter. So far all I have are a handful of customer sample files created from various sources including some Avid products. The reason I finally made the patch was because the (dead) libquicktime and (dying/dead) Apple's QuicktTime 7 libraries have the opposite interpretation. My plan was to continue searching for a reference on the matter before replying. If you have a way to ask Avid that would obviously be the best. Though it seems like their QuickTime component for QuickTime 7 is making files with the opposite values of ffmpeg at the moment. I will continue my testing/searching as well. Thanks guys! On 1/28/15 12:44 AM, Kevin Wheatley wrote: On Tue, Jan 27, 2015 at 9:27 PM, Michael Niedermayer wrote: On Tue, Jan 27, 2015 at 11:15:40AM -0800, jon morley wrote: movenc.c |9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) 6317011578bca8bf065f5bd4de2dfce803557e81 0001-libavformat-movenc.c-Correct-color-range-when-writin.patch From 0097277471810ab1d9d737c64a57c2278a039153 Mon Sep 17 00:00:00 2001 From: Jon Morley Date: Tue, 27 Jan 2015 11:10:27 -0800 Subject: [PATCH] libavformat/movenc.c: Correct color range when writing DNxHD atoms The meaning of the color range values in the AVdn.ACLR atom was swapped. This change makes the selection explicit and correctly mapped. --- libavformat/movenc.c | 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) breaks "make fate" you need to update the checksums also please explain in the commit message what referece you used to know which is the correct value Jon, Michael, this may or may not be the correct setting, I've generated a few different range encodings from different apps and found there is some inconsistency (who'd have thought QuickTime could be ambiguous) in what different apps do, I thought that the values might need to be switched too, however files generated with an Avid appear to suggest ffmpeg's current behavior might be correct (for encoding). I'm going to try get some form of official statement/info direct from Avid, mean while I'm going to go find a few more encoders from third parties and see what they do. Kevin ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel