jonghwanhyeon / python-ffmpeg

A python binding for FFmpeg which provides sync and async APIs
MIT License
302 stars 52 forks source link

pytest failure: test_output_via_stdout and test_asyncio_output_via_stdout #22

Closed xiota closed 1 year ago

xiota commented 1 year ago

When running pytest, I see the following assertion errors:

----- test_output_via_stdout -----
   ...
>       assert abs(float(source["format"]["duration"]) - float(target["format"]["duration"])) <= epsilon
E       AssertionError: assert 0.30054999999999943 <= 0.25
E        +  where 0.30054999999999943 = abs((7.72424 - 8.02479))
E        +    where 7.72424 = float('7.724240')
E        +    and   8.02479 = float('8.024790')

test_pipe.py:62: AssertionError

----- test_asyncio_output_via_stdout -----
   ...
E       AssertionError: assert 0.30054999999999943 <= 0.25
E        +  where 0.30054999999999943 = abs((7.72424 - 8.02479))
E        +    where 7.72424 = float('7.724240')
E        +    and   8.02479 = float('8.024790')

test_asyncio_pipe.py:66: AssertionError

I ran the following to try to figure out what might be happening:

$ ffmpeg -i assets/brewing.wav assets/brewing.aac
   ...
$ diff -U 0 <(ffprobe -i assets/brewing.wav 2>&1) <(ffprobe -i assets/brewing.aac 2>&1)
--- /proc/self/fd/11    ...
+++ /proc/self/fd/12    ...
@@ -12,5 +12,4 @@
-Input #0, wav, from 'assets/brewing.wav':
-  Metadata:
-    encoder         : Lavf58.29.100
-  Duration: 00:00:07.72, bitrate: 1411 kb/s
-  Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 2 channels, s16, 1411 kb/s
+[aac @ 0x563a16423c00] Estimating duration from bitrate, this may be inaccurate
+Input #0, aac, from 'assets/brewing.aac':
+  Duration: 00:00:08.02, bitrate: 126 kb/s
+  Stream #0:0: Audio: aac (LC), 44100 Hz, stereo, fltp, 126 kb/s

Apparently, aac files do not contain timing information, so the duration has to be estimated inaccurately.

jonghwanhyeon commented 1 year ago

Fixed with commit 22fefac949b3e521a695b961ab096da8f4ef59e3