title: M4a (mp4) audio file encoded with pydub+ffmpeg doesn't play on Android
body: <p>I have a python script to split up some <code>wav</code> files and export to <code>m4a</code> using <a href="https://github.com/jiaaro/pydub" rel="nofollow noreferrer">pydub</a>.  I'm able to get these files to play on several devices, but not on an Android device (using Google Pixel 3).  When I try encoding with straight <code>ffmpeg</code> in terminal, that works fine on the Android device.</p>
  <p>What is the difference in these two files, and since <code>pydub</code> is using <code>ffmpeg</code>, what do I need to change to make it do exactly the same as the <code>ffmpeg</code> command?</p>
  <p><strong>Not working</strong></p>
  <pre><code>from pydub import AudioSegment
  &gt;&gt;&gt; audio = AudioSegment.from_wav(&quot;input.wav&quot;)
  &gt;&gt;&gt; slice = audio[1000:3000]
  &gt;&gt;&gt; slice.export(&quot;pydub_export.m4a&quot;, format=&quot;mp4&quot;, parameters=[&quot;-ac&quot;, &quot;1&quot;, &quot;-c:a&quot;, &quot;libfdk_aac&quot;, &quot;-profile:a&quot;, &quot;aac_he&quot;, &quot;-vbr&quot;, &quot;2&quot;])
  </code></pre>
  <p><code>mediainfo</code> output:</p>
  <pre><code>General
  Complete name                            : pydub_export.m4a
  Format                                   : MPEG-4
  Format profile                           : Base Media
  Codec ID                                 : isom (isom/iso2/mp41)
  File size                                : 11.7 KiB
  Duration                                 : 2 s 115 ms
  Overall bit rate mode                    : Constant
  Overall bit rate                         : 45.1 kb/s
  Writing application                      : Lavf58.29.100
  
  Audio
  ID                                       : 1
  Format                                   : AAC LC SBR
  Format/Info                              : Advanced Audio Codec Low Complexity with Spectral Band Replication
  Commercial name                          : HE-AAC
  Format settings                          : NBC
  Codec ID                                 : mp4a-40-5
  Duration                                 : 2 s 115 ms
  Duration_LastFrame                       : -22 ms
  Bit rate mode                            : Constant
  Bit rate                                 : 41.4 kb/s
  Channel(s)                               : 1 channel
  Channel layout                           : C
  Sampling rate                            : 44.1 kHz
  Frame rate                               : 21.533 FPS (2048 SPF)
  Compression mode                         : Lossy
  Stream size                              : 10.7 KiB (92%)
  Default                                  : Yes
  Alternate group                          : 1
  </code></pre>
  <p><strong>Working</strong></p>
  <pre><code>$ffmpeg -i input.wav -acodec copy -ss 1 -to 3 input_slice.wav
  $ffmpeg -i input_slice.wav -ac 1 -c:a libfdk_aac -profile:a aac_he -vbr 2 ffmpeg_export.m4a
  </code></pre>
  <p><code>mediainfo</code> output:</p>
  <pre><code>General
  Complete name                            : ffmpeg_export.m4a
  Format                                   : MPEG-4
  Format profile                           : Apple audio with iTunes info
  Codec ID                                 : M4A  (isom/iso2)
  File size                                : 11.2 KiB
  Duration                                 : 2 s 112 ms
  Overall bit rate mode                    : Constant
  Overall bit rate                         : 43.6 kb/s
  Writing application                      : Lavf58.29.100
  
  Audio
  ID                                       : 1
  Format                                   : AAC LC SBR
  Format/Info                              : Advanced Audio Codec Low Complexity with Spectral Band Replication
  Commercial name                          : HE-AAC
  Format settings                          : NBC
  Codec ID                                 : mp4a-40-5
  Duration                                 : 2 s 112 ms
  Duration_LastFrame                       : -25 ms
  Bit rate mode                            : Constant
  Bit rate                                 : 39.9 kb/s
  Channel(s)                               : 1 channel
  Channel layout                           : C
  Sampling rate                            : 44.1 kHz
  Frame rate                               : 21.533 FPS (2048 SPF)
  Compression mode                         : Lossy
  Stream size                              : 10.3 KiB (91%)
  Default                                  : Yes
  Alternate group                          : 1
  </code></pre>
  <p>I already tried <a href="https://stackoverflow.com/a/14172629/129486">moving metadata to the front</a> with <code>-movflags faststart</code> on the broken file and it didn't make a difference.</p>