0

I'm trying to convert some audio files from FLAC to ALAC (m4a) using ffmpeg. For my environment (Apple & Sonos), the lowest common denominator seems to be as follows:

ALAC (.m4a) encoding at 44.1kHz, & bit depth = 16 bits

The problem I'm having is that the output file produced by ffmpeg has a bit depth of '32p'; i.e. sample_fmt=s32p

I've done the conversion with several sets of arguments, but the results are the same. I've been unable to find anything that explains why this might be. Here's one of the commands I've tried:

$ file='01 Jubilee.flac'
$ ffmpeg -i "$file" -acodec alac -ar 44100 -sample_fmt:0 s16 -c:v png "${file/%.flac/.16.m4a}" 

I've run ffprobe on the input file to determine its format:

$ ffprobe -i "$file" -show_streams  

Which (in summary) yields:

Stream #0:0: Audio: flac, 176400 Hz, stereo, s32 (24 bit)
Stream #0:1: Video: mjpeg (Progressive), yuvj444p(pc, bt470bg/unknown/unknown), 450x446 [SAR 72:72 DAR 225:223], 90k tbr, 90k tbn, 90k tbc (attached pic)

... and on the output file:

$ ffprobe -i "${file/%.flac/.16.m4a}" -show_streams

Which (in summary) yields:

Stream #0:0(und): Audio: alac (alac / 0x63616C61), 44100 Hz, stereo, s32p (24 bit), 1564 kb/s (default)
Metadata:
  handler_name    : SoundHandler
Stream #0:1: Video: png, rgb24(pc), 450x446 [SAR 1:1 DAR 225:223], 90k tbr, 90k tbn, 90k tbc (attached pic)  

[STREAM]
index=0
codec_name=alac
codec_long_name=ALAC (Apple Lossless Audio Codec)
profile=unknown
codec_type=audio
codec_time_base=1/44100
codec_tag_string=alac
codec_tag=0x63616c61
sample_fmt=s32p
sample_rate=44100

... 

etc, etc

I've posted only a small snippet of the ffprobe output, but can provide all of it if needed. Also, my ffmpeg version:

$ ffmpeg -version
ffmpeg version git-2020-01-13-7225479 Copyright (c) 2000-2020 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.8)

Finally, here's the output of the ffmpeg conversion above:

$ ffmpeg -v info -hide_banner -i "$file" -acodec alac -ar 44100 -sample_fmt:0 s16 -c:v png "${file/%.flac/.16.m4a}"
Input #0, flac, from '01 Jubilee.flac':
  Metadata:
    track           : 1
    TITLE           : Jubilee
    ARTIST          : Bill Charlap Trio
    album_artist    : Bill Charlap Trio
    ALBUM           : Stardust The Music Of Hoagy Carmichael
    DATE            : 2003
    GENRE           : Jazz
    TRACKTOTAL      : 11
    disc            : 1
    DISCTOTAL       : 1
    ALBUM ARTIST    : Bill Charlap Trio
  Duration: 00:02:23.17, start: 0.000000, bitrate: 6176 kb/s
    Stream #0:0: Audio: flac, 176400 Hz, stereo, s32 (24 bit)
    Stream #0:1: Video: mjpeg (Progressive), yuvj444p(pc, bt470bg/unknown/unknown), 450x446 [SAR 72:72 DAR 225:223], 90k tbr, 90k tbn, 90k tbc (attached pic)
    Metadata:
      comment         : Cover (front)
File '01 Jubilee.16.m4a' already exists. Overwrite? [y/N] y
Stream mapping:
  Stream #0:1 -> #0:0 (mjpeg (native) -> png (native))
  Stream #0:0 -> #0:1 (flac (native) -> alac (native))
Press [q] to stop, [?] for help
[swscaler @ 0x10dc6b000] deprecated pixel format used, make sure you did set range correctly
[ipod @ 0x7fc3a1002200] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2
Output #0, ipod, to '01 Jubilee.16.m4a':
  Metadata:
    track           : 1
    TITLE           : Jubilee
    ARTIST          : Bill Charlap Trio
    album_artist    : Bill Charlap Trio
    ALBUM           : Stardust The Music Of Hoagy Carmichael
    DATE            : 2003
    GENRE           : Jazz
    TRACKTOTAL      : 11
    disc            : 1
    DISCTOTAL       : 1
    ALBUM ARTIST    : Bill Charlap Trio
    encoder         : Lavf58.35.102
    Stream #0:0: Video: png, rgb24(progressive), 450x446 [SAR 1:1 DAR 225:223], q=2-31, 200 kb/s, 90k fps, 90k tbn, 90k tbc (attached pic)
    Metadata:
      comment         : Cover (front)
      encoder         : Lavc58.65.103 png
    Stream #0:1: Audio: alac (alac / 0x63616C61), 44100 Hz, stereo, s32p (24 bit), 128 kb/s
    Metadata:
      encoder         : Lavc58.65.103 alac
frame=    1 fps=0.8 q=-0.0 Lsize=   27745kB time=00:02:23.22 bitrate=1587.0kbits/s speed= 113x    
video:396kB audio:27342kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.026342%
1

This works here.

ffmpeg -i in -c:a alac -ar 44100 -sample_fmt s16p -c:v png -vsync 0 out.m4a

Note that ALAC encoder checks if the raw frame is 16-bit planar

| improve this answer | |
  • Ah! I did not realize that ALAC used planar encoding (s16p, s32p). Still it seems that the s16 option would provide ffmpeg with enough of a clue to 'do the right thing' given that it knows the conversion is to ALAC. But in any case, this seems to have resolved the issue as Sonos now plays it. – Seamus Jan 22 at 14:50
  • The user supplied -pix_fmt or -sample_fmt is taken as a directive rather than a hint. – Gyan Jan 22 at 15:23
  • Not sure I agree that it's taken as a directive... it defaulted to s32p when the argument was s16. The files played in every music app I have except Sonos. Just sayin'... – Seamus Jan 22 at 19:46
  • 1
    The option is specified as -sample_fmt:0 s16 but the first output stream is the image, so it is ignored. Since, effectively, no format has been set for the audio output stream, ffmpeg selects s32p as the input audio is s32 – Gyan Jan 23 at 16:41
  • 1
    Encoding options apply to output streams and the stream mapping identifies that order. If the command has -map , then the order of maps decides output stream order. If not, it's always video, audio, subtitles. – Gyan Jan 24 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.