1

I have gotten a set of FLAC (audio) files from a friend. I copied them to my Sonos music library, and got set to enjoy a nice album. Unfortunately, Sonos would not play the files. As a result I have been getting to know ffmpeg.

Sonos' complaint with the FLAC files was that it was "encoded at an unsupported sample rate". With rolling eyes and shaking head, I note that the free VLC media player happily plays these files, but the product I've paid for (Sonos) - does not. But I digress...

ffprobe revealed that the FLAC files contain both an Audio channel and a Video channel:

$ ffprobe -hide_banner  -show_streams "/path/to/Myaudio.flac"


    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)  

Cool! I guess this is how some audio players are able to display the 'album artwork' when they play a song? Note also that the Audio stream is reported at 176400 Hz! Apparently I'm out of touch; I thought that 44.1khz sampling rate effectively removed all of the 'sampling artifacts' we could hear. Anyway, I learned that Sonos would support a max of 48kHz sampling rate, and this (the 176.4kHz rate) is what Sonos was unhappy about. I used ffmpeg to 'dumb it down' for them:

$ ffmpeg -i "/path/to/Myaudio.flac" -sample_fmt s32 -ar 48000 "/path/to/Myaudio48K.flac"

This seemed to work - at least I got a FLAC file that Sonos would play. However, I also got what looks like a warning of some sort:

[swscaler @ 0x108e0d000] deprecated pixel format used, make sure you did set range correctly
[flac @ 0x7feefd812a00] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2

A bit more research turned up this answer which I don't quite understand, and then in a comment says, "not to worry" - at least wrt the swscaler part of the warning.

And that (finally) brings me to my questions:

1.a. What framerate, muxer & other specifications make a graphic compatible with a majority of programs that use the graphic?

1.b. How should I use ffmpeg to modify the Video channel to set these specifications (ref. Q 1.a.)?

2.a. How do I remove the Video channel from the .flac audio file?

2.b. How do I add a Video channel into a .flac file?

EDIT:

I asked the above (4) questions after failing to accomplish a 'direct' conversion (a single ffmpeg command) from FLAC at 176.4 kHz to ALAC (.m4a) at 48 kHz (max supported by Sonos). I reasoned that an 'incremental' approach through a series of conversions might get me there. With the advantage of hindsight, I now see I should have posted my original failed direct conversion incantation... we live and learn.

That said, the accepted answer below meets my final objective to convert a FLAC file encoded at 176.4kHz to an ALAC (.m4a) at 48kHz, and preserve the cover art/video channel.

  • I wouldn't worry about either of those. It's not really a video stream, that's just how the JPEG is being interpreted for the sake of FFmpeg to use in video contexts. The warnings are just artifacts of this quirk. I haven't tested, but you can try `-vn` to remove the "video" stream from the output. I don't know offhand how to properly add a JPEG to the FLAC/Ogg metadata from FFmpeg. – Brad Jan 14 '20 at 00:09
  • @Brad: Unfortunately, I can't ignore it. When I try to convert FLAC to ALAC, I get a terminal failure due to the "Video", `stream 0:1`. The error is: `[ipod @ 0x7fc022002800] Could not find tag for codec h264 in stream #0, codec not currently supported in container`, `Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument`, `Error initializing output stream 0:1`, `Conversion failed!` –  Jan 14 '20 at 05:00
  • ALAC is an unrelated format with different capabilities. Are you trying to use FLAC now or ALAC? If ALAC, please update your question or post a new question. And, please include the full FFmpeg command and its full output. – Brad Jan 14 '20 at 05:06
  • @Brad: Yeah... I was trying to keep my question (and my approach to this) "simple". I'm trying to satisfy Sonos and iTunes limitations. Sonos doesn't support > 48K sampling rate, iTunes doesn't support FLAC, both support ALAC. So, plan was to do this in 2 steps: 1. FLAC-to-FLAC@48K, 2. FLAC@48K-to-ALAC. Step 1 works as I've shown above; Step 2 fails. My Q's (1 & 2) were in hope of either inserting a compliant graphic, or removing it altogether. –  Jan 14 '20 at 05:20
  • Why not just go straight to ALAC? No need for both steps. Also, did you try the `-vn` parameter I suggested? – Brad Jan 14 '20 at 05:22
  • @Brad: I did try to go straight to ALAC initially. The issues with the graphic persuaded me to try an 'end-around' :) That, and I was curious if I could make Sonos happy w/ lower sampling rate (I did). I didn't try `-vn` because 1) couldn't confirm it was correct syntax, 2) prefer a solution which retains the graphic. –  Jan 14 '20 at 05:25
  • All `-vn` does is disables the video streams in the output. That should prevent the cover art from passing through to the output. I don't know offhand how to properly embed that cover art... I'd have to go dig up some old code to see how I did it last time. Perhaps tomorrow, if someone else hasn't answered your question yet. – Brad Jan 14 '20 at 05:31
  • @Brad: Much appreciated... It's late & I'm done with this for today. I've found some stuff on [removing a graphic](https://stackoverflow.com/questions/38161697/how-to-remove-one-track-from-video-file-using-ffmpeg), and on [adding a graphic](https://stackoverflow.com/questions/18710992/how-to-add-album-art-with-ffmpeg). Still have no idea why it doesn't like the graphic as it is. –  Jan 14 '20 at 05:38
  • I think the issue is that it's getting treated as an MJPEG video track, rather than a binary attachment of sorts instead. – Brad Jan 14 '20 at 05:40
  • @Brad: I'm still grinding gears on this... [According to this bug report](https://trac.ffmpeg.org/ticket/2798) `ffmpeg` may have an open issue wrt placing a graphic/artwork in ALAC/m4a files. If I'm reading this correctly, the issue was partially fixed, but the fix did not address m4a and m4v files. [Potential alternative solutions are discussed here.](https://stackoverflow.com/questions/17798709/ffmpeg-how-to-embed-cover-art-image-to-m4a) –  Jan 15 '20 at 00:28

1 Answers1

2

What framerate, muxer & other specifications make a graphic compatible with a majority of programs that use the graphic?

A cover art is just a single frame so framerate has no relevance in this case. However, you don't want a video stream, it has to remain a single image, so -vsync 0 should be added. Muxer is simply the specific term for the packager as used in media file processing. It is decided by the choice of format e.g. FLAC, WAV..etc. What's important is the codec for the cover art; usually, it's PNG or JPEG. For FLAC, PNG is the default codec.

How do I remove the Video channel from the .flac audio file

ffmpeg -i "/path/to/Myaudio.flac" -vn -c copy "/path/to/Myaudio48K.flac"

(All this does is skip any video in the input and copy everything else)

How do I add a Video channel into a .flac file?

To add cover art to audio-only formats, like MP3, FLAC..etc, the video stream has to have a disposition of attached picture. So,

ffmpeg -i "/path/to/Myaudio.flac" -i coverimage -sample_fmt s32 -ar 48000 -disposition:v attached_pic -vsync 0 "/path/to/Myaudio48K.flac"

For direct conversion to ALAC, use

ffmpeg -i "/path/to/Myaudio.flac" -i coverimage -ar 48000 -c:a alac -disposition:v attached_pic -vsync 0 -c:v png "/path/to/Myaudio48K.m4a"
Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Please see the UPDATE in my Q. Conversion to ALAC still fails. –  Jan 14 '20 at 10:19
  • For conversion to ALAC in m4a, you would add `-c:v png` to my last command. – Gyan Jan 14 '20 at 10:22
  • ? The last command doesn't seem to have anything in it that would cause the file to be converted from FLAC to ALAC... what am I missing? Do I not need the sequence `-acodec alac` in the command? –  Jan 14 '20 at 10:29
  • Sorry, added new cmd – Gyan Jan 14 '20 at 10:32
  • Result: `coverimage: No such file or directory` But now that I look at your first command, it seems you've assumed I added `coverimage` in that step. I didn't do this as there was already artwork in the FLAC file as I received it. What is `coverimage` exactly? –  Jan 14 '20 at 10:48
  • 1
    Your Q was *How do I add a Video channel into a .flac file?* which implies it doesn't already have one. If it does, skip `-i coverimage` – Gyan Jan 14 '20 at 12:05
  • This still doesn't work. The command (less `i coverimage`) fails as follows: `[alac @ 0x7fb01d808c00] Specified sample format s32 is invalid or not supported` `Error initializing output stream 0:1 -- Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height` `Conversion failed!` –  Jan 14 '20 at 21:20
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/205968/discussion-between-seamus-and-gyan). –  Jan 14 '20 at 21:33
  • This business of placing a graphic/artwork in ALAC/m4a files may not be possible for `ffmpeg` [according to this bug report.](https://trac.ffmpeg.org/ticket/2798) If I'm reading this correctly, the issue was partially fixed, but the fix did not address m4a and m4v files. [Potential alternative solutions are discussed here.](https://stackoverflow.com/questions/17798709/ffmpeg-how-to-embed-cover-art-image-to-m4a) –  Jan 15 '20 at 00:16
  • Works here. Make sure you're using the latest version of ffmpeg. – Gyan Jan 15 '20 at 04:56
  • Downloaded a couple of days ago... $ 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) –  Jan 15 '20 at 06:15
  • Probably the same one you did before you edited your command line :) I would have thought that deserved a mention, but no worries. It ran without error. Thanks for your help, and thanks for your patience. –  Jan 15 '20 at 06:34