diff mbox

[FFmpeg-devel,v2,4/5] avformat/chromaprint: Fix writing raw fingerprint

Message ID 20191006054950.30374-4-andriy.gelman@gmail.com
State Accepted
Commit e14f5fd0a6983838b5fe3c6ad1c2ec2f2d8e49df
Headers show

Commit Message

Andriy Gelman Oct. 6, 2019, 5:49 a.m. UTC
From: Andriy Gelman <andriy.gelman@gmail.com>

The pointer fp after the call to chromaprint_get_raw_fingerpoint() points to an array of uint32_t whereas the current code assumed just a char stream. Thus when writing the raw fingerprint, the output would be truncated by a factor of 4. This is fixed in the commit.

For reference the declaration of the function from chromaprint.h is:
int chromaprint_get_raw_fingerprint(ChromaprintContext *ctx, uint32_t **fingerprint, int *size);
---
 libavformat/chromaprint.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andriy Gelman Oct. 15, 2019, 7:41 p.m. UTC | #1
On Sun, 06. Oct 01:49, Andriy Gelman wrote:
> From: Andriy Gelman <andriy.gelman@gmail.com>
> 
> The pointer fp after the call to chromaprint_get_raw_fingerpoint() points to an array of uint32_t whereas the current code assumed just a char stream. Thus when writing the raw fingerprint, the output would be truncated by a factor of 4. This is fixed in the commit.
> 
> For reference the declaration of the function from chromaprint.h is:
> int chromaprint_get_raw_fingerprint(ChromaprintContext *ctx, uint32_t **fingerprint, int *size);
> ---
>  libavformat/chromaprint.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/chromaprint.c b/libavformat/chromaprint.c
> index a4c0b97d99..faa92ca0db 100644
> --- a/libavformat/chromaprint.c
> +++ b/libavformat/chromaprint.c
> @@ -136,7 +136,7 @@ static int write_trailer(AVFormatContext *s)
>  
>      switch (cpr->fp_format) {
>      case FINGERPRINT_RAW:
> -        avio_write(pb, fp, size);
> +        avio_write(pb, fp, size * 4); //fp points to array of uint32_t
>          break;
>      case FINGERPRINT_COMPRESSED:
>      case FINGERPRINT_BASE64:
> -- 
> 2.23.0

ping 

To reproduce the error, we can compare the results to fpcalc (chromaprint
utility https://acoustid.org/chromaprint) 

$ ffmpeg -f lavfi -i sine=d=4 -f s16le testsample.raw 
$ fpcalc -format s16le -raw -plain testsample.raw
558758263,558758263,558758263,558758263,558758263,558758263,558758263,558758263,558758263,558758263,558758263

#with ffmpeg (need to typecast output bytesteam to uint32 to compare) 
$ ffmpeg -f lavfi -i sine=d=4 -f s16le -f chromaprint -fp_format raw fingerprint.raw
$ python3 -c "import numpy; print(numpy.fromfile(\"fingerprint.raw\", dtype=numpy.uint32))" 
[558758263 558758263]

Applying this commit makes the outputs same size
Gyan Oct. 15, 2019, 7:51 p.m. UTC | #2
On 16-10-2019 01:11 AM, Andriy Gelman wrote:
> On Sun, 06. Oct 01:49, Andriy Gelman wrote:
>> From: Andriy Gelman <andriy.gelman@gmail.com>
>>
>> The pointer fp after the call to chromaprint_get_raw_fingerpoint() points to an array of uint32_t whereas the current code assumed just a char stream. Thus when writing the raw fingerprint, the output would be truncated by a factor of 4. This is fixed in the commit.
>>
>> For reference the declaration of the function from chromaprint.h is:
>> int chromaprint_get_raw_fingerprint(ChromaprintContext *ctx, uint32_t **fingerprint, int *size);
>> ---
>>   libavformat/chromaprint.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavformat/chromaprint.c b/libavformat/chromaprint.c
>> index a4c0b97d99..faa92ca0db 100644
>> --- a/libavformat/chromaprint.c
>> +++ b/libavformat/chromaprint.c
>> @@ -136,7 +136,7 @@ static int write_trailer(AVFormatContext *s)
>>   
>>       switch (cpr->fp_format) {
>>       case FINGERPRINT_RAW:
>> -        avio_write(pb, fp, size);
>> +        avio_write(pb, fp, size * 4); //fp points to array of uint32_t
>>           break;
>>       case FINGERPRINT_COMPRESSED:
>>       case FINGERPRINT_BASE64:
>> -- 
>> 2.23.0
> ping
Will check and apply.

Gyan
Gyan Oct. 16, 2019, 5:09 a.m. UTC | #3
On 16-10-2019 01:21 AM, Gyan wrote:
>
>
> On 16-10-2019 01:11 AM, Andriy Gelman wrote:
>> On Sun, 06. Oct 01:49, Andriy Gelman wrote:
>>> From: Andriy Gelman <andriy.gelman@gmail.com>
>>>
>>> The pointer fp after the call to chromaprint_get_raw_fingerpoint() 
>>> points to an array of uint32_t whereas the current code assumed just 
>>> a char stream. Thus when writing the raw fingerprint, the output 
>>> would be truncated by a factor of 4. This is fixed in the commit.
>>>
>>> For reference the declaration of the function from chromaprint.h is:
>>> int chromaprint_get_raw_fingerprint(ChromaprintContext *ctx, 
>>> uint32_t **fingerprint, int *size);
>>> ---
>>>   libavformat/chromaprint.c | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/libavformat/chromaprint.c b/libavformat/chromaprint.c
>>> index a4c0b97d99..faa92ca0db 100644
>>> --- a/libavformat/chromaprint.c
>>> +++ b/libavformat/chromaprint.c
>>> @@ -136,7 +136,7 @@ static int write_trailer(AVFormatContext *s)
>>>         switch (cpr->fp_format) {
>>>       case FINGERPRINT_RAW:
>>> -        avio_write(pb, fp, size);
>>> +        avio_write(pb, fp, size * 4); //fp points to array of uint32_t
>>>           break;
>>>       case FINGERPRINT_COMPRESSED:
>>>       case FINGERPRINT_BASE64:
>>> -- 
>>> 2.23.0
>> ping
> Will check and apply.

Pushed as  e14f5fd0a6983838b5fe3c6ad1c2ec2f2d8e49df

Thanks,
Gyan
diff mbox

Patch

diff --git a/libavformat/chromaprint.c b/libavformat/chromaprint.c
index a4c0b97d99..faa92ca0db 100644
--- a/libavformat/chromaprint.c
+++ b/libavformat/chromaprint.c
@@ -136,7 +136,7 @@  static int write_trailer(AVFormatContext *s)
 
     switch (cpr->fp_format) {
     case FINGERPRINT_RAW:
-        avio_write(pb, fp, size);
+        avio_write(pb, fp, size * 4); //fp points to array of uint32_t
         break;
     case FINGERPRINT_COMPRESSED:
     case FINGERPRINT_BASE64: