[issue1455] MP3 from AIF puts noise to the end of the file
Justin Ruggles justin.rugg...@gmail.com added the comment: Baptiste Coudurier wrote: Baptiste Coudurier baptiste.coudur...@gmail.com added the comment: On 10/11/09 1:02 PM, Justin Ruggles wrote: Justin Rugglesjustin.rugg...@gmail.com added the comment: trying to replace the file with new file... -- nosy: -jbr _ FFmpeg issue trackeriss...@roundup.ffmpeg.org https://roundup.ffmpeg.org/roundup/ffmpeg/issue1455 _ aiff_data_size_2.patch diff --git a/libavformat/aiff.c b/libavformat/aiff.c index 570e05d..9501a7b 100644 --- a/libavformat/aiff.c +++ b/libavformat/aiff.c @@ -46,6 +46,10 @@ static const AVCodecTag codec_aiff_tags[] = { #define AIFF0 #define AIFF_C_VERSION1 0xA2805140 +typedef struct { +int64_t data_end; +} AIFFInputContext; + AIFFContext There is already an AIFFOutputContext in the same file. I chose to name the new struct AIFFInputContext to distinguish between the two. I guess I could also merge them, even though the fields used are mutually exclusive between the muxer and demuxer. Well, really it would be good to split the file, but that's a different issue... _ FFmpeg issue tracker iss...@roundup.ffmpeg.org https://roundup.ffmpeg.org/roundup/ffmpeg/issue1455 _
[issue1455] MP3 from AIF puts noise to the end of the file
Baptiste Coudurier baptiste.coudur...@gmail.com added the comment: On 10/12/2009 3:06 PM, Justin Ruggles wrote: Justin Rugglesjustin.rugg...@gmail.com added the comment: Baptiste Coudurier wrote: Baptiste Coudurierbaptiste.coudur...@gmail.com added the comment: On 10/11/09 1:02 PM, Justin Ruggles wrote: Justin Rugglesjustin.rugg...@gmail.com added the comment: trying to replace the file with new file... -- nosy: -jbr _ FFmpeg issue trackeriss...@roundup.ffmpeg.org https://roundup.ffmpeg.org/roundup/ffmpeg/issue1455 _ aiff_data_size_2.patch diff --git a/libavformat/aiff.c b/libavformat/aiff.c index 570e05d..9501a7b 100644 --- a/libavformat/aiff.c +++ b/libavformat/aiff.c @@ -46,6 +46,10 @@ static const AVCodecTag codec_aiff_tags[] = { #define AIFF0 #define AIFF_C_VERSION1 0xA2805140 +typedef struct { +int64_t data_end; +} AIFFInputContext; + AIFFContext There is already an AIFFOutputContext in the same file. I chose to name the new struct AIFFInputContext to distinguish between the two. I guess I could also merge them, even though the fields used are mutually exclusive between the muxer and demuxer. Right, name is fine then. Well, really it would be good to split the file, but that's a different issue... Definitely welcome :) _ FFmpeg issue tracker iss...@roundup.ffmpeg.org https://roundup.ffmpeg.org/roundup/ffmpeg/issue1455 _
[issue1455] MP3 from AIF puts noise to the end of the file
Justin Ruggles justin.rugg...@gmail.com added the comment: fixed in r20219. -- status: open - closed substatus: analyzed - fixed _ FFmpeg issue tracker iss...@roundup.ffmpeg.org https://roundup.ffmpeg.org/roundup/ffmpeg/issue1455 _
[issue1455] MP3 from AIF puts noise to the end of the file
Justin Ruggles justin.rugg...@gmail.com added the comment: trying to replace the file with new file... -- nosy: -jbr _ FFmpeg issue tracker iss...@roundup.ffmpeg.org https://roundup.ffmpeg.org/roundup/ffmpeg/issue1455 _diff --git a/libavformat/aiff.c b/libavformat/aiff.c index 570e05d..9501a7b 100644 --- a/libavformat/aiff.c +++ b/libavformat/aiff.c @@ -46,6 +46,10 @@ static const AVCodecTag codec_aiff_tags[] = { #define AIFF0 #define AIFF_C_VERSION1 0xA2805140 +typedef struct { +int64_t data_end; +} AIFFInputContext; + static enum CodecID aiff_codec_get_id(int bps) { if (bps = 8) @@ -314,6 +318,7 @@ static int aiff_read_header(AVFormatContext *s, unsigned version = AIFF_C_VERSION1; ByteIOContext *pb = s-pb; AVStream * st; +AIFFInputContext *ctx = s-priv_data; /* check FORM header */ filesize = get_tag(pb, tag); @@ -366,6 +371,7 @@ static int aiff_read_header(AVFormatContext *s, get_meta(s, comment , size); break; case MKTAG('S', 'S', 'N', 'D'): /* Sampled sound chunk */ +ctx-data_end = url_ftell(pb) + size; offset = get_be32(pb); /* Offset of sound data */ get_be32(pb); /* BlockSize... don't care */ offset += url_ftell(pb);/* Compute absolute data offset */ @@ -420,10 +426,18 @@ static int aiff_read_packet(AVFormatContext *s, AVPacket *pkt) { AVStream *st = s-streams[0]; +AIFFInputContext *ctx = s-priv_data; +int64_t max_size; int res; +/* calculate size of remaining data */ +max_size = ctx-data_end - url_ftell(s-pb); +if (max_size = 0) +return AVERROR_EOF; + /* Now for that packet */ -res = av_get_packet(s-pb, pkt, (MAX_SIZE / st-codec-block_align) * st-codec-block_align); +max_size = FFMIN(max_size, (MAX_SIZE / st-codec-block_align) * st-codec-block_align); +res = av_get_packet(s-pb, pkt, max_size); if (res 0) return res; @@ -436,7 +450,7 @@ static int aiff_read_packet(AVFormatContext *s, AVInputFormat aiff_demuxer = { aiff, NULL_IF_CONFIG_SMALL(Audio IFF), -0, +sizeof(AIFFInputContext), aiff_probe, aiff_read_header, aiff_read_packet,
[issue1455] MP3 from AIF puts noise to the end of the file
Baptiste Coudurier baptiste.coudur...@gmail.com added the comment: On 10/11/09 1:02 PM, Justin Ruggles wrote: Justin Rugglesjustin.rugg...@gmail.com added the comment: trying to replace the file with new file... -- nosy: -jbr _ FFmpeg issue trackeriss...@roundup.ffmpeg.org https://roundup.ffmpeg.org/roundup/ffmpeg/issue1455 _ aiff_data_size_2.patch diff --git a/libavformat/aiff.c b/libavformat/aiff.c index 570e05d..9501a7b 100644 --- a/libavformat/aiff.c +++ b/libavformat/aiff.c @@ -46,6 +46,10 @@ static const AVCodecTag codec_aiff_tags[] = { #define AIFF0 #define AIFF_C_VERSION1 0xA2805140 +typedef struct { +int64_t data_end; +} AIFFInputContext; + AIFFContext static enum CodecID aiff_codec_get_id(int bps) { if (bps= 8) @@ -314,6 +318,7 @@ static int aiff_read_header(AVFormatContext *s, unsigned version = AIFF_C_VERSION1; ByteIOContext *pb = s-pb; AVStream * st; +AIFFInputContext *ctx = s-priv_data; I think I prefer *aif or *aiff for the variable name. Patch is fine besides. Thanks for the fix. _ FFmpeg issue tracker iss...@roundup.ffmpeg.org https://roundup.ffmpeg.org/roundup/ffmpeg/issue1455 _
[issue1455] MP3 from AIF puts noise to the end of the file
Justin Ruggles justin.rugg...@gmail.com added the comment: The issue is that the SSND chunk does not have to be the last chunk in the AIFF file, but the AIFF demuxer reads audio data until the end of the file. The attached patch determines the audio data size so that aiff_read_packet() does not return data past the end of the SSND chunk. -- nosy: +jbr substatus: open - analyzed _ FFmpeg issue tracker iss...@roundup.ffmpeg.org https://roundup.ffmpeg.org/roundup/ffmpeg/issue1455 _diff --git a/libavformat/aiff.c b/libavformat/aiff.c index 570e05d..66088da 100644 --- a/libavformat/aiff.c +++ b/libavformat/aiff.c @@ -46,6 +46,12 @@ static const AVCodecTag codec_aiff_tags[] = { #define AIFF0 #define AIFF_C_VERSION1 0xA2805140 +typedef struct { +int64_t data_offset; +int64_t data_size; +int max_packet_size; +} AIFFInputContext; + static enum CodecID aiff_codec_get_id(int bps) { if (bps = 8) @@ -314,6 +320,7 @@ static int aiff_read_header(AVFormatContext *s, unsigned version = AIFF_C_VERSION1; ByteIOContext *pb = s-pb; AVStream * st; +AIFFInputContext *ctx = s-priv_data; /* check FORM header */ filesize = get_tag(pb, tag); @@ -368,7 +375,9 @@ static int aiff_read_header(AVFormatContext *s, case MKTAG('S', 'S', 'N', 'D'): /* Sampled sound chunk */ offset = get_be32(pb); /* Offset of sound data */ get_be32(pb); /* BlockSize... don't care */ +ctx-data_size = size - (8 + offset); offset += url_ftell(pb);/* Compute absolute data offset */ +ctx-data_offset = offset; if (st-codec-block_align)/* Assume COMM already parsed */ goto got_sound; if (url_is_streamed(pb)) { @@ -420,10 +429,23 @@ static int aiff_read_packet(AVFormatContext *s, AVPacket *pkt) { AVStream *st = s-streams[0]; +AIFFInputContext *ctx = s-priv_data; +int64_t max_size, pos; int res; +/* calculate size of remaining data */ +pos = url_ftell(s-pb); +if (pos ctx-data_offset) { +url_fseek(s-pb, ctx-data_offset, SEEK_SET); +pos = ctx-data_offset; +} +max_size = ctx-data_size - (pos - ctx-data_offset); +if (max_size = 0) +return AVERROR_EOF; + /* Now for that packet */ -res = av_get_packet(s-pb, pkt, (MAX_SIZE / st-codec-block_align) * st-codec-block_align); +max_size = FFMIN(max_size, (MAX_SIZE / st-codec-block_align) * st-codec-block_align); +res = av_get_packet(s-pb, pkt, max_size); if (res 0) return res; @@ -436,7 +458,7 @@ static int aiff_read_packet(AVFormatContext *s, AVInputFormat aiff_demuxer = { aiff, NULL_IF_CONFIG_SMALL(Audio IFF), -0, +sizeof(AIFFInputContext), aiff_probe, aiff_read_header, aiff_read_packet,
[issue1455] MP3 from AIF puts noise to the end of the file
Reimar Döffinger b...@reimardoeffinger.de added the comment: On Sat, Oct 10, 2009 at 05:50:50PM +, Justin Ruggles wrote: --- a/libavformat/aiff.c +++ b/libavformat/aiff.c @@ -46,6 +46,12 @@ static const AVCodecTag codec_aiff_tags[] = { #define AIFF0 #define AIFF_C_VERSION1 0xA2805140 +typedef struct { +int64_t data_offset; I'd expect you could reuse AVFormatContext-data_offset, unless you want to support multiple SSND chunks but I expect the current code not to work well for that anyway... @@ -368,7 +375,9 @@ static int aiff_read_header(AVFormatContext *s, case MKTAG('S', 'S', 'N', 'D'): /* Sampled sound chunk */ offset = get_be32(pb); /* Offset of sound data */ get_be32(pb); /* BlockSize... don't care */ +ctx-data_size = size - (8 + offset); offset += url_ftell(pb);/* Compute absolute data offset */ +ctx-data_offset = offset; if (st-codec-block_align)/* Assume COMM already parsed */ goto got_sound; if (url_is_streamed(pb)) { @@ -420,10 +429,23 @@ static int aiff_read_packet(AVFormatContext *s, AVPacket *pkt) { AVStream *st = s-streams[0]; +AIFFInputContext *ctx = s-priv_data; +int64_t max_size, pos; int res; +/* calculate size of remaining data */ +pos = url_ftell(s-pb); +if (pos ctx-data_offset) { +url_fseek(s-pb, ctx-data_offset, SEEK_SET); +pos = ctx-data_offset; +} +max_size = ctx-data_size - (pos - ctx-data_offset); +if (max_size = 0) +return AVERROR_EOF; Why not just have a single data_end field? And what is the purpose of the pos ctx-data_offset check anyway? Also I wonder if/how well this works with multiple SSND chunks and seeking (probably not that important, but a nice-to-have). -- title: AIFF demuxer puts noise to the end of the file - MP3 from AIF puts noise to the end of the file _ FFmpeg issue tracker iss...@roundup.ffmpeg.org https://roundup.ffmpeg.org/roundup/ffmpeg/issue1455 _
[issue1455] MP3 from AIF puts noise to the end of the file
Reimar Döffinger b...@reimardoeffinger.de added the comment: On Sat, Oct 10, 2009 at 06:40:36PM +, Justin Ruggles wrote: And what is the purpose of the pos ctx-data_offset check anyway? It was to handle the case when the file is seeked to before the start of data. But if AVFormatContext-data_offset is used as you suggested, this should be handled in pcm_read_seek(). If you do not set data_offset, it is already automatically set to the current position after read_headers, so check there you really need to do anything at all. Also I wonder if/how well this works with multiple SSND chunks and seeking (probably not that important, but a nice-to-have). Right now it doesn't work for demuxing, much less seeking, with multiple SSND chunks. The patch does not change that. But yes, it should be fixed to handle it properly. Now if I only had a sample... It might not be allowed. If not even demuxing works currently, just ignore this possibility for now I'd say. _ FFmpeg issue tracker iss...@roundup.ffmpeg.org https://roundup.ffmpeg.org/roundup/ffmpeg/issue1455 _
[issue1455] MP3 from AIF puts noise to the end of the file
New submission from Jeff Harmon jhar...@colorhythm.com: the following command line on Mac OS X Leopard 10.5.8 running FFMpeg 0.5_5 from MacPorts: ffmpeg -i filename.aif -acodec libmp3lame -ab 160k -ac2 -f mp3 preview.mp3 produces excellent results pretty much all the time so far in our testing - even on a couple other AIFs - but on this AIF, which plays perfectly in Quicktime/iTunes, it adds a bunch of noise at the end of the file. Perhaps this reveals a problem in the code, maybe in my setup? File '22.050kHz-705kbps-16bit-Stereo.aif' not attached - you can download it from https://roundup.ffmpeg.org/roundup/ffmpeg/file550. -- files: 22.050kHz-705kbps-16bit-Stereo.aif messages: 7341 priority: normal status: new substatus: new title: MP3 from AIF puts noise to the end of the file type: bug _ FFmpeg issue tracker iss...@roundup.ffmpeg.org https://roundup.ffmpeg.org/roundup/ffmpeg/issue1455 _
[issue1455] MP3 from AIF puts noise to the end of the file
Carl Eugen Hoyos ceho...@rainbow.studorg.tuwien.ac.at added the comment: Noise at the end of test.wav. ffmpeg -i 22.050kHz-705kbps-16bit-Stereo.aif test.wav FFmpeg version SVN-r20167, Copyright (c) 2000-2009 Fabrice Bellard, et al. built on Oct 5 2009 10:24:47 with icc 1110 configuration: --cc=/opt/intel/Compiler/11.1/056/bin/intel64/icc --cpu=core2 --enable-gpl --extra-cflags=-parallel --extra-ldflags=-parallel --enable-postproc --enable-avfilter --enable-pthreads --enable-nonfree --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libdirac --enable-libfaac --enable-libfaad --enable-libgsm --enable-libmp3lame --extra-cflags='-I/usr/include/openjpeg -I/usr/include/gsm' --enable-libopenjpeg --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libxvid --enable-libx264 libavutil 50. 3. 0 / 50. 3. 0 libavcodec52.36. 0 / 52.36. 0 libavformat 52.39. 0 / 52.39. 0 libavdevice 52. 2. 0 / 52. 2. 0 libavfilter0. 5. 0 / 0. 5. 0 libswscale 0. 7. 1 / 0. 7. 1 libpostproc 51. 2. 0 / 51. 2. 0 [aiff @ 0x145bf90]max_analyze_duration reached Input #0, aiff, from '22.050kHz-705kbps-16bit-Stereo.aif': Duration: 00:00:04.87, start: 0.00, bitrate: 1295 kb/s Stream #0.0: Audio: pcm_s16be, 22050 Hz, 2 channels, s16, 705 kb/s Output #0, wav, to 'test.wav': Stream #0.0: Audio: pcm_s16le, 22050 Hz, 2 channels, s16, 705 kb/s Stream mapping: Stream #0.0 - #0.0 Press [q] to stop encoding Multiple frames in a packet from stream 0 [pcm_s16be @ 0x1465340]invalid PCM packet Error while decoding stream #0.0 size= 770kB time=8.94 bitrate= 705.6kbits/s video:0kB audio:770kB global headers:0kB muxing overhead 0.005577% -- status: new - open substatus: new - open _ FFmpeg issue tracker iss...@roundup.ffmpeg.org https://roundup.ffmpeg.org/roundup/ffmpeg/issue1455 _