Opened 8 years ago

Last modified 19 months ago

#6158 open defect

ffmpeg does not detect/decode MQA encoded FLAC properly

Reported by: Nomis101 Owned by:
Priority: wish Component: avcodec
Version: git-master Keywords: MQA, FLAC
Cc: Christoph Anton Mitterer Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

I have some FLAC encapsulated MQA files from a high-res online music dealer. I've tried to convert this files using ffmpeg to ALAC files (for iTunes). The original sample rate of the MQA is 96000 Hz. So the resulting ALAC file should be the same. But ffmpeg does not detect the MQA stream properly and just decodes the 48000 Hz FLAC into ALAC. I've used the latest git version, this is the logging console output:

ffmpeg -v 9 -loglevel 99 -i /Users/Downloads/07\ After\ Midnight\ \(with\ Special\ Guest\ JJ\ Cale\)\ \(Live\ in\ San\ Diego\).mqa.flac -vn -acodec alac /Users/Downloads/07\ After\ Midnight\ \(with\ Special\ Guest\ JJ\ Cale\)\ \(Live\ in\ San\ Diego\).mqa.m4a
ffmpeg version N-83545-g6baee21eb7 Copyright (c) 2000-2017 the FFmpeg developers

built with Apple LLVM version 8.1.0 (clang-802.0.27.2)
configuration:
libavutil 55. 47.100 / 55. 47.100
libavcodec 57. 80.100 / 57. 80.100
libavformat 57. 66.102 / 57. 66.102
libavdevice 57. 2.100 / 57. 2.100
libavfilter 6. 73.100 / 6. 73.100
libswscale 4. 3.101 / 4. 3.101
libswresample 2. 4.100 / 2. 4.100

Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with argument '9'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument '99'.
Reading option '-i' ... matched as input url with argument '/Users/Downloads/07 After Midnight (with Special Guest JJ Cale) (Live in San Diego).mqa.flac'.
Reading option '-vn' ... matched as option 'vn' (disable video) with argument '1'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'alac'.
Reading option '/Users/Downloads/07 After Midnight (with Special Guest JJ Cale) (Live in San Diego).mqa.m4a' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument 9.
Successfully parsed a group of options.
Parsing a group of options: input url /Users/Downloads/07 After Midnight (with Special Guest JJ Cale) (Live in San Diego).mqa.flac.
Successfully parsed a group of options.
Opening an input file: /Users/Downloads/07 After Midnight (with Special Guest JJ Cale) (Live in San Diego).mqa.flac.
[file @ 0x7fabbac0e540] Setting default whitelist 'file,crypto'
Probing flac score:50 size:2048
[flac @ 0x7fabbb800000] Format flac probed with size=2048 and score=50
[flac @ 0x7fabbb800000] Before avformat_find_stream_info() pos: 457534 bytes read:159021 seeks:1 nb_streams:2
[mjpeg @ 0x7fabbb846200] marker=d8 avail_size_in_buf=123856
[mjpeg @ 0x7fabbb846200] marker parser used 0 bytes (0 bits)
[mjpeg @ 0x7fabbb846200] marker=e0 avail_size_in_buf=123854
[mjpeg @ 0x7fabbb846200] marker parser used 16 bytes (128 bits)
[mjpeg @ 0x7fabbb846200] marker=ed avail_size_in_buf=123836
[mjpeg @ 0x7fabbb846200] marker parser used 55 bytes (440 bits)
[mjpeg @ 0x7fabbb846200] marker=e2 avail_size_in_buf=123778
[mjpeg @ 0x7fabbb846200] marker parser used 6331 bytes (50648 bits)
[mjpeg @ 0x7fabbb846200] marker=c0 avail_size_in_buf=117444
[mjpeg @ 0x7fabbb846200] Changing bps from 0 to 8
[mjpeg @ 0x7fabbb846200] sof0: picture: 600x600
[mjpeg @ 0x7fabbb846200] component 0 2:2 id: 0 quant:0
[mjpeg @ 0x7fabbb846200] component 1 1:1 id: 1 quant:1
[mjpeg @ 0x7fabbb846200] component 2 1:1 id: 2 quant:1
[mjpeg @ 0x7fabbb846200] pix fmt id 22111100
[mjpeg @ 0x7fabbb846200] marker parser used 17 bytes (136 bits)
[mjpeg @ 0x7fabbb846200] marker=c4 avail_size_in_buf=117425
[mjpeg @ 0x7fabbb846200] marker parser used 0 bytes (0 bits)
[mjpeg @ 0x7fabbb846200] marker=c4 avail_size_in_buf=117392
[mjpeg @ 0x7fabbb846200] marker parser used 0 bytes (0 bits)
[mjpeg @ 0x7fabbb846200] marker=c4 avail_size_in_buf=117209
[mjpeg @ 0x7fabbb846200] marker parser used 0 bytes (0 bits)
[mjpeg @ 0x7fabbb846200] marker=c4 avail_size_in_buf=117176
[mjpeg @ 0x7fabbb846200] marker parser used 0 bytes (0 bits)
[mjpeg @ 0x7fabbb846200] marker=db avail_size_in_buf=116993
[mjpeg @ 0x7fabbb846200] index=0
[mjpeg @ 0x7fabbb846200] qscale[0]: 1
[mjpeg @ 0x7fabbb846200] marker parser used 67 bytes (536 bits)
[mjpeg @ 0x7fabbb846200] marker=db avail_size_in_buf=116924
[mjpeg @ 0x7fabbb846200] index=1
[mjpeg @ 0x7fabbb846200] qscale[1]: 2
[mjpeg @ 0x7fabbb846200] marker parser used 67 bytes (536 bits)
[mjpeg @ 0x7fabbb846200] marker=dd avail_size_in_buf=116855
[mjpeg @ 0x7fabbb846200] marker parser used 0 bytes (0 bits)
[mjpeg @ 0x7fabbb846200] escaping removed 686 bytes
[mjpeg @ 0x7fabbb846200] marker=da avail_size_in_buf=116849
[mjpeg @ 0x7fabbb846200] marker parser used 116163 bytes (929304 bits)
[mjpeg @ 0x7fabbb846200] marker=d9 avail_size_in_buf=0
[mjpeg @ 0x7fabbb846200] decode frame unused 0 bytes
[flac @ 0x7fabbb808c00] sample/frame number mismatch in adjacent frames

Last message repeated 20 times

[flac @ 0x7fabbb800000] All info found
[flac @ 0x7fabbb800000] stream 0: start_time: 0.000 duration: 343.525
[flac @ 0x7fabbb800000] stream 1: start_time: 0.000 duration: 343.525
[flac @ 0x7fabbb800000] format: start_time: 0.000 duration: 343.525 bitrate=1722 kb/s
[flac @ 0x7fabbb800000] After avformat_find_stream_info() pos: 618302 bytes read:322861 seeks:1 frames:2
Input #0, flac, from '/Users/Downloads/07 After Midnight (with Special Guest JJ Cale) (Live in San Diego).mqa.flac':

Metadata:

TITLE : After Midnight (with Special Guest JJ Cale)
ARTIST : Eric Clapton
album_artist : Eric Clapton
ALBUM : Live in San Diego (with Special Guest JJ Cale)
track : 7
disc : 1
DATE : 2016-09-30
COMPOSER : JJ Cale
GENRE : Rock
COPYRIGHT : 2016 EPC Enterprises LLP, under exclusive license to Reprise Records
LABEL : Reprise, Warner Brothers
ISRC : USRE11600308
PUBLISHER : 2016 EPC Enterprises LLP, under exclusive license to Reprise Records
TRACKTOTAL : 16
DISCTOTAL : 1
ENCODER : MQAEncode v1.1, 2.2.0+485 (0b66124), F8EC1703-7616-45E5-B81E-D60821434062, Oct 24 2016 23:01:32
GRID : A10302B0003533923W
ICPN : 093624917601
MQAENCODER : MQAEncode v1.1, 2.2.0+485 (0b66124), F8EC1703-7616-45E5-B81E-D60821434062, Oct 24 2016 23:01:32
ORIGINALSAMPLERATE: 96000
TOTALTRACKS : 16
REPLAYGAIN_REFERENCE_LOUDNESS: 89.0 dB
REPLAYGAIN_TRACK_GAIN: -6.96 dB
REPLAYGAIN_TRACK_PEAK: 0.99999952
REPLAYGAIN_ALBUM_GAIN: -7.89 dB
REPLAYGAIN_ALBUM_PEAK: 1.00000000

Duration: 00:05:43.52, start: 0.000000, bitrate: 1722 kb/s

Stream #0:0, 1, 1/48000: Audio: flac, 48000 Hz, stereo, s32 (24 bit)
Side data:

replaygain: track gain - -6.960000, track peak - 0.000023, album gain - -7.890000, album peak - 0.000023,

Stream #0:1, 1, 1/90000: Video: mjpeg, 1 reference frame, yuvj420p(pc, bt470bg/unknown/unknown, center), 600x600 [SAR 72:72 DAR 1:1], 0/1, 90k tbr, 90k tbn, 90k tbc
Metadata:

comment : Cover (front)

Successfully opened the file.
Parsing a group of options: output url /Users/Downloads/07 After Midnight (with Special Guest JJ Cale) (Live in San Diego).mqa.m4a.
Applying option vn (disable video) with argument 1.
Applying option acodec (force audio codec ('copy' to copy stream)) with argument alac.
Successfully parsed a group of options.
Opening an output file: /Users/Downloads/07 After Midnight (with Special Guest JJ Cale) (Live in San Diego).mqa.m4a.
[file @ 0x7fabbad02620] Setting default whitelist 'file,crypto'
Successfully opened the file.
detected 8 logical cores
[graph_0_in_0_0 @ 0x7fabbaf003a0] Setting 'time_base' to value '1/48000'
[graph_0_in_0_0 @ 0x7fabbaf003a0] Setting 'sample_rate' to value '48000'
[graph_0_in_0_0 @ 0x7fabbaf003a0] Setting 'sample_fmt' to value 's32'
[graph_0_in_0_0 @ 0x7fabbaf003a0] Setting 'channel_layout' to value '0x3'
[graph_0_in_0_0 @ 0x7fabbaf003a0] tb:1/48000 samplefmt:s32 samplerate:48000 chlayout:0x3
[format_out_0_0 @ 0x7fabbaf008e0] Setting 'sample_fmts' to value 's32p|s16p'
[format_out_0_0 @ 0x7fabbaf008e0] Setting 'channel_layouts' to value '0x4|0x3|0x7|0x107|0x37|0x3f|0x13f|0xff'
[format_out_0_0 @ 0x7fabbaf008e0] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_0'
[AVFilterGraph @ 0x7fabbad00160] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
[auto_resampler_0 @ 0x7fabbd2000c0] picking s32p out of 2 ref:s32
[auto_resampler_0 @ 0x7fabbd2000c0] [SWR @ 0x7fabbb89d400] Using s32p internally between filters
[auto_resampler_0 @ 0x7fabbd2000c0] ch:2 chl:stereo fmt:s32 r:48000Hz -> ch:2 chl:stereo fmt:s32p r:48000Hz
Output #0, ipod, to '/Users/Downloads/07 After Midnight (with Special Guest JJ Cale) (Live in San Diego).mqa.m4a':

Metadata:

TITLE : After Midnight (with Special Guest JJ Cale)
ARTIST : Eric Clapton
album_artist : Eric Clapton
ALBUM : Live in San Diego (with Special Guest JJ Cale)
track : 7
disc : 1
DATE : 2016-09-30
COMPOSER : JJ Cale
GENRE : Rock
COPYRIGHT : 2016 EPC Enterprises LLP, under exclusive license to Reprise Records
LABEL : Reprise, Warner Brothers
ISRC : USRE11600308
PUBLISHER : 2016 EPC Enterprises LLP, under exclusive license to Reprise Records
TRACKTOTAL : 16
DISCTOTAL : 1
REPLAYGAIN_ALBUM_PEAK: 1.00000000
GRID : A10302B0003533923W
ICPN : 093624917601
MQAENCODER : MQAEncode v1.1, 2.2.0+485 (0b66124), F8EC1703-7616-45E5-B81E-D60821434062, Oct 24 2016 23:01:32
ORIGINALSAMPLERATE: 96000
TOTALTRACKS : 16
REPLAYGAIN_REFERENCE_LOUDNESS: 89.0 dB
REPLAYGAIN_TRACK_GAIN: -6.96 dB
REPLAYGAIN_TRACK_PEAK: 0.99999952
REPLAYGAIN_ALBUM_GAIN: -7.89 dB
encoder : Lavf57.66.102
Stream #0:0, 0, 1/48000: Audio: alac (alac / 0x63616C61), 48000 Hz, stereo, s32p (24 bit), 128 kb/s
Metadata:

encoder : Lavc57.80.100 alac

Stream mapping:

Stream #0:0 -> #0:0 (flac (native) -> alac (native))

Press [q] to stop, ? for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)

Last message repeated 2 times

[NULL @ 0x7fabbb808c00] sample/frame number mismatch in adjacent frames

Last message repeated 2 times

cur_dts is invalid (this is harmless if it occurs once at the start per stream)
[NULL @ 0x7fabbb808c00] sample/frame number mismatch in adjacent frames

Last message repeated 2 times

cur_dts is invalid (this is harmless if it occurs once at the start per stream)
[NULL @ 0x7fabbb808c00] sample/frame number mismatch in adjacent frames

Last message repeated 2 times

cur_dts is invalid (this is harmless if it occurs once at the start per stream)
[NULL @ 0x7fabbb808c00] sample/frame number mismatch in adjacent frames

Last message repeated 2 times

cur_dts is invalid (this is harmless if it occurs once at the start per stream)
[NULL @ 0x7fabbb808c00] sample/frame number mismatch in adjacent frames

Last message repeated 2 times

cur_dts is invalid (this is harmless if it occurs once at the start per stream)
[NULL @ 0x7fabbb808c00] sample/frame number mismatch in adjacent frames

Last message repeated 2 times

cur_dts is invalid (this is harmless if it occurs once at the start per stream)
[NULL @ 0x7fabbb808c00] sample/frame number mismatch in adjacent frames

Last message repeated 2 times

cur_dts is invalid (this is harmless if it occurs once at the start per stream)
[NULL @ 0x7fabbb808c00] sample/frame number mismatch in adjacent frames

Last message repeated 2219 times

[NULL @ 0x7fabbb808c00] sample/frame number mismatch in adjacent frames

Last message repeated 2216 times

[NULL @ 0x7fabbb808c00] sample/frame number mismatch in adjacent frames

Last message repeated 2264 times

[NULL @ 0x7fabbb808c00] sample/frame number mismatch in adjacent frames

Last message repeated 2228 times

[NULL @ 0x7fabbb808c00] sample/frame number mismatch in adjacent frames

Last message repeated 2219 times

[NULL @ 0x7fabbb808c00] sample/frame number mismatch in adjacent frames

Last message repeated 875 times

[flac @ 0x7fabbb800000] first_dts 0 not matching first dts 16453632 (pts 16453632, duration 4096) in the queue
No more output streams to write to, finishing.
size= 72545kB time=00:05:43.55 bitrate=1729.8kbits/s speed= 127x
video:0kB audio:72528kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.024329%
Input file #0 (/Users/Downloads/07 After Midnight (with Special Guest JJ Cale) (Live in San Diego).mqa.flac):

Input stream #0:0 (audio): 4026 packets read (73487373 bytes); 4026 frames decoded (16489182 samples);
Input stream #0:1 (video): 1 packets read (123858 bytes);
Total: 4027 packets (73611231 bytes) demuxed

Output file #0 (/Users/Downloads/07 After Midnight (with Special Guest JJ Cale) (Live in San Diego).mqa.m4a):

Output stream #0:0 (audio): 4026 frames encoded (16489182 samples); 4026 packets muxed (74268327 bytes);
Total: 4026 packets (74268327 bytes) muxed

4026 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x7fabbad02720] Statistics: 28 seeks, 4048 writeouts
[AVIOContext @ 0x7fabbac0e920] Statistics: 73646394 bytes read, 1 seeks

(because the music file is under copyright, I can not attach a sample here)

Change History (16)

comment:1 by Hendrik, 8 years ago

Priority: normalwish

MQA is a closed proprietary format that piggy-backs on top of FLAC, somewhat similar to the concepts behind HDCD, so chances of it being supported are slim.

comment:2 by Carl Eugen Hoyos, 8 years ago

Component: ffmpegundetermined
Resolution: needs_more_info
Status: newclosed

Please reopen this ticket if you can provide a sample file.

comment:3 by Nomis101, 8 years ago

Resolution: needs_more_info
Status: closedreopened

Because of copyright reasons I can not attach my sample file, but you can find some MQA stereo files here: http://www.2l.no/hires/

comment:4 by Carl Eugen Hoyos, 8 years ago

in reply to:  4 comment:5 by Nomis101, 8 years ago

Replying to cehoyos:

What is the expected output for http://www.lindberg.no/hires/mqa/2L-056_03_stereo_DXD_mqa.flac ?

According to the metadata I suspect the output of this file should be
352800 Hz, stereo, s32 (24 bit)

comment:6 by Carl Eugen Hoyos, 8 years ago

What I meant was: Please provide the expected output (file) for this input file.

comment:7 by Nomis101, 8 years ago

I do not have the expected output (file) for this input file. There are currently only some software players for the MQA format (Audirvana 3.0, Amarra 4.0, ROON, Tidal), but no converter. So I don't have the possibility to convert this file into the expected output. Thats why I was hoping ffmpeg could be the first tool be able to do so.

comment:8 by Elon Musk, 7 years ago

Component: undeterminedavcodec

comment:9 by AprilHare, 6 years ago

Although I am unsure how to capture the expected output the free Pine Player (available in the Mac App Store) appears to support MQA. https://itunes.apple.com/us/app/pine-player/id1112075769?mt=12

comment:10 by Nomis101, 6 years ago

I tried the Pine player. It displayes a MQA badge if I play my MQA files. But if I export the opened audio file from the Pine Player, I get the exact same file like in every other player.

comment:12 by Christoph Anton Mitterer, 3 years ago

Cc: Christoph Anton Mitterer added

comment:13 by Christoph Anton Mitterer, 3 years ago

Just for the records, there's also: https://code.videolan.org/mansr/mqa ... which looks like it would be a reverse engineering effort, though there is no documentation.

comment:14 by Balling, 3 years ago

That is not a decoder, Christoph. This is just a dlopen wrapper around arm7 (32 bit) lib that can play it. https://pinkfishmedia.net/forum/threads/mqa.254199/page-86

But that is only sw unwrap, the first one.

Last edited 3 years ago by Balling (previous) (diff)

comment:15 by Balling, 3 years ago

Okay, i was a little wrong, it can unfold but also
mqarender can render it. Still library is needed.

comment:16 by Balling, 19 months ago

Status: reopenedopen

I managed to finally hack the second unfold in. But 3rd unfold will not work and for 44100 24 bit files with ORIGINALSAMPLERATE 44100 the first unfold will work but the second will produce the same file with b stage metadata still (it is removed for normal files that result in 192khz 2nd unfold). Even then by default mqarender will render at x2 frequency, and that will corrupt the wav file. The opposite problem is for 3rd unfold files, with -r 352800 it will corrupt the file, without -r everything is good, but the frequency is 1/2 of 352800.

The command one should use is (after unpacking rootfs with everything, not just one library into lib). Yes, this uses ld linker as executable. I use new library from web.archive https://0x0.st/HzxT.tar.bz2

./lib/lib/ld-linux-armhf.so.3 --library-path /home/dextop/Downloads/mqa-master/lib/lib:/home/dextop/Downloads/mqa-master/lib/usr/lib '/home/dextop/Downloads/mqa-master/arm/mqarender' ./outp7.wav rendered7.wav

There are some interesting points about making it so only 2nd unfold will be permissable, this library also removes the need for arm device:

https://github.com/yuv418/libbluos_ssc_ipc/commit/d273239216ba8aa454b14f310d163319df10989f

I also opened an issue upstream: https://code.videolan.org/mansr/mqa/-/issues/2

Last edited 19 months ago by Balling (previous) (diff)
Note: See TracTickets for help on using tickets.