Opened 2 years ago
Last modified 2 years ago
#10038 new defect
Wrong duration / speed in audio recording made with ffmpeg -f avfoundation
Reported by: | Raimondas | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | undetermined |
Version: | git-master | Keywords: | avfoundation |
Cc: | Raimondas | Blocked By: | |
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
Summary of the bug:
recorded ~10 seconds of audio, the result audio file is ~5 second long, plays approx. twice as fast:
... [q] command received. Exiting. size= 1822kB time=00:00:10.74 bitrate=1389.7kbits/s speed=0.999x
ffprobe on resulting file outputs:
... Duration: 00:00:04.86, bitrate: 3072 kb/s
How to reproduce:
% ffmpeg -f avfoundation -i :0 -acodec pcm_f32le t1.wav ffmpeg versions 5.0 and 5.1.2 built on Macos 12.6 and 10.10.5
-report log attached.
This seems to be related to sampling rate, i.e., if input sampling rate is 192kHz, the recording plays 4x too fast, if input sampling rate is 48kHz, or 44.1KHz recording times and recording duration reported by ffprobe are a closer match.
Sampling rate in output file is always correct. Bit depth does not make difference, changing output format from WAV to FLAC does not make difference.
Recordings are made on Mac Pro laptops of various generations, either straight from MacBook Pro Microphone or from external ADC attached via Firewire/Lightning port. Sample rate change made on Audio MIDI Setup for the microphone or on the external ADC.
Attachments (4)
Change History (8)
by , 2 years ago
Attachment: | ffmpeg-20221114-184010.log added |
---|
comment:1 by , 2 years ago
Keywords: | audio removed |
---|---|
Version: | 5.1.2 → unspecified |
comment:2 by , 2 years ago
Retested with current Git head build, same problem:
- recorded ~20 sec of audio with MacBook Pro Microphone sampling rate set to 96k
- resulting wav file is ~10 sec long
There is a bitrate discrepancy.
ffmpeg output:
./ffmpeg -debug 1 -f avfoundation -i ":0" -acodec pcm_s24le 96-24.wav (7:08 0) ffmpeg version N-109088-g52f7adfbde Copyright (c) 2000-2022 the FFmpeg developers built with Apple clang version 13.0.0 (clang-1300.0.29.30) configuration: libavutil 57. 42.100 / 57. 42.100 libavcodec 59. 52.102 / 59. 52.102 libavformat 59. 34.101 / 59. 34.101 libavdevice 59. 8.101 / 59. 8.101 libavfilter 8. 50.100 / 8. 50.100 libswscale 6. 8.112 / 6. 8.112 libswresample 4. 9.100 / 4. 9.100 matched as AVOption 'debug' with argument '1'. Reading option '-f' ... matched as option 'f' (force format) with argument 'avfoundation'. Reading option '-i' ... matched as input url with argument ':0'. Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'pcm_s24le'. Reading option '96-24.wav' ... matched as output url. Finished splitting the commandline. Parsing a group of options: global . Successfully parsed a group of options. Parsing a group of options: input url :0. Applying option f (force format) with argument avfoundation. Successfully parsed a group of options. Opening an input file: :0. [avfoundation @ 0x15ae05270] audio device 'MacBook Pro Microphone' opened [avfoundation @ 0x15ae05270] All info found Input #0, avfoundation, from ':0': Duration: N/A, start: 337270.763406, bitrate: 3072 kb/s Stream #0:0, 1, 1/1000000: Audio: pcm_f32le, 96000 Hz, mono, flt, 3072 kb/s Successfully opened the file. Parsing a group of options: output url 96-24.wav. Applying option acodec (force audio codec ('copy' to copy stream)) with argument pcm_s24le. Successfully parsed a group of options. Opening an output file: 96-24.wav. [file @ 0x15ba06460] Setting default whitelist 'file,crypto,data' Successfully opened the file. Stream mapping: Stream #0:0 -> #0:0 (pcm_f32le (native) -> pcm_s24le (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) Last message repeated 2 times [avfoundation @ 0x15ae05270] Thread message queue blocking; consider raising the thread_queue_size option (current value: 1) detected 10 logical cores [graph_0_in_0_0 @ 0x15ae28440] Setting 'time_base' to value '1/96000' [graph_0_in_0_0 @ 0x15ae28440] Setting 'sample_rate' to value '96000' [graph_0_in_0_0 @ 0x15ae28440] Setting 'sample_fmt' to value 'flt' [graph_0_in_0_0 @ 0x15ae28440] Setting 'channel_layout' to value 'mono' [graph_0_in_0_0 @ 0x15ae28440] tb:1/96000 samplefmt:flt samplerate:96000 chlayout:mono [format_out_0_0 @ 0x15ae1be20] Setting 'sample_fmts' to value 's32' [auto_aresample_0 @ 0x15ae15b20] Setting 'output_sample_bits' to value '24' [format_out_0_0 @ 0x15ae1be20] auto-inserting filter 'auto_aresample_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_0' [AVFilterGraph @ 0x15ae142c0] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed [auto_aresample_0 @ 0x15ae15b20] [SWR @ 0x140018000] Using fltp internally between filters [auto_aresample_0 @ 0x15ae15b20] ch:1 chl:mono fmt:flt r:96000Hz -> ch:1 chl:mono fmt:s32 r:96000Hz Output #0, wav, to '96-24.wav': Metadata: ISFT : Lavf59.34.101 Stream #0:0, 0, 1/96000: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 96000 Hz, mono, s32, 2304 kb/s Metadata: encoder : Lavc59.52.102 pcm_s24le size= 2560kB time=00:00:20.75 bitrate=1010.6kbits/s speed= 1x [q] command received. Exiting. All streams finished for output file #0 Terminating muxer thread 0 [AVIOContext @ 0x15ba064e0] Statistics: 2678894 bytes written, 4 seeks, 13 writeouts size= 2616kB time=00:00:20.81 bitrate=1029.8kbits/s speed=0.999x video:0kB audio:2616kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.003808% Input file #0 (:0): Input stream #0:0 (audio): 1744 packets read (3571712 bytes); 1744 frames decoded (892928 samples); Total: 1744 packets (3571712 bytes) demuxed Output file #0 (96-24.wav): Output stream #0:0 (audio): 1744 frames encoded (892928 samples); 1744 packets muxed (2678784 bytes); Total: 1744 packets (2678784 bytes) muxed 1744 frames successfully decoded, 0 decoding errors Terminating demuxer thread 0
ffprobe output
./ffprobe 96-24.wav (7:09 0) ffprobe version N-109088-g52f7adfbde Copyright (c) 2007-2022 the FFmpeg developers built with Apple clang version 13.0.0 (clang-1300.0.29.30) configuration: libavutil 57. 42.100 / 57. 42.100 libavcodec 59. 52.102 / 59. 52.102 libavformat 59. 34.101 / 59. 34.101 libavdevice 59. 8.101 / 59. 8.101 libavfilter 8. 50.100 / 8. 50.100 libswscale 6. 8.112 / 6. 8.112 libswresample 4. 9.100 / 4. 9.100 Input #0, wav, from '96-24.wav': Metadata: encoder : Lavf59.34.101 Duration: 00:00:09.30, bitrate: 2304 kb/s Stream #0:0: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 96000 Hz, mono, s32 (24 bit), 2304 kb/s
comment:3 by , 2 years ago
Version: | unspecified → git-master |
---|
comment:4 by , 2 years ago
The crux of the problem may be that capture? encoding? happens at some arbitrary, lower bitrate, but output file bitrate matches the expected bitrate for sampling rate.
Here's capture at 192k:
... Input #0, avfoundation, from ':0': Duration: N/A, start: 12238.164484, bitrate: 12288 kb/s Stream #0:0, 1, 1/1000000: Audio: pcm_f32le, 192000 Hz, stereo, flt, 12288 kb/s ... Output #0, wav, to '192-24.wav': Metadata: ISFT : Lavf59.27.100 Stream #0:0, 0, 1/192000: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 192000 Hz, stereo, s32, 9216 kb/s Metadata: encoder : Lavc59.37.100 pcm_s24le size= 2904kB time=00:00:09.99 bitrate=2380.9kbits/s speed=0.999x
and at 44.1k:
... Input #0, avfoundation, from ':0': Duration: N/A, start: 12528.771497, bitrate: 2822 kb/s Stream #0:0, 1, 1/1000000: Audio: pcm_f32le, 44100 Hz, stereo, flt, 2822 kb/s ... Output #0, wav, to '44-24.wav': Metadata: ISFT : Lavf59.27.100 Stream #0:0, 0, 1/44100: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s32, 2116 kb/s Metadata: encoder : Lavc59.37.100 pcm_s24le size= 2512kB time=00:00:10.00 bitrate=2057.9kbits/s speed=0.998x
attaching logs for 3 recordings, at 192, 96, 44.1k, all showing the same problem
by , 2 years ago
Attachment: | 192-ffmpeg-20221115-101408.log added |
---|
by , 2 years ago
Attachment: | 96-ffmpeg-20221115-101734.log added |
---|
by , 2 years ago
Attachment: | 44-ffmpeg-20221115-101859.log added |
---|
Please test current FFmpeg git head to make this a valid ticket.