13

I'm rying to convert flac audio file into alac audio file. I'm using ffmpeg command in mac os terminal after installing ffmpeg using command brew install ffmpeg.

After running following command

for name in *.flac; do ffmpeg -nostdin -i "$name" -acodec alac "${name%.*}.m4a"; done

I am getting the following error:

Stream mapping:
  Stream #0:1 -> #0:0 (mjpeg (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (flac (native) -> alac (native))
[ipod @ 0x7fa5c6800000] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2
[libx264 @ 0x7fa5c5804a00] using SAR=1/1
[libx264 @ 0x7fa5c5804a00] MB rate (77760000) > level limit (16711680)
[libx264 @ 0x7fa5c5804a00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7fa5c5804a00] profile High, level 6.2
[libx264 @ 0x7fa5c5804a00] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[ipod @ 0x7fa5c6800000] 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!

Is the problem located in stream #0:1?

Should I be using

-c:a alac

instead of

-acodec alac
Superkoira
  • 595
  • 1
  • 5
  • 12
  • Share full log. – Gyan Mar 30 '19 at 09:58
  • 4
    I found out that I had to use parameters "-c:a alac -c:v copy" so it copied the album art video stream and re-encoded the audio stream! Problem is fixed but maybe I want to keep this here so someone else may find it useful? – Superkoira Mar 30 '19 at 11:20

2 Answers2

29

what I did was

for name in *.flac; do ffmpeg -nostdin -i "$name" -c:a alac -c:v copy "${name%.*}.m4a"; done
Superkoira
  • 595
  • 1
  • 5
  • 12
  • 11
    Thanks for that! But why does that command fix the issue? – Carlos Agarie Sep 06 '20 at 02:33
  • `-c:v copy` seems say "copy over all the video streams" so that the other codec parameters apply only to the audio streams. An alternative is `-vn` to skip video streams altogether. – huyz Jun 05 '23 at 09:42
0
for name in *.flac; do ffmpeg -i "$name" -select_streams a:0 -c:a alac -c:v copy "${name%.*}.m4a"; done

you can use -select_streams a:0 to specifically target the first audio stream.

DopeLabs
  • 109
  • 4
  • 2
    `-select_streams a:0` is an option for `ffprobe`. Using it with `ffmpeg` will result in `Unrecognized option 'select_streams'.`. You probably meant to use the `-map` option. – llogan Apr 02 '19 at 16:44
  • 1
    Also, with -map a:0, do you still need -c:v copy? The command that worked best for me is `find -name "*.flac" -exec bash -c ffmpeg -nostdin -i "{}" -map a:0 -c:a alac "${0/.flac}.m4a"' {} \;` – akjones Dec 17 '20 at 02:21
  • Adding `-vn` also worked for me to skip the video stream and get to the audio steram – huyz Jun 05 '23 at 09:29