1

I recorded a voice memo that shows a length of 10:22 in iTunes. I convert it to PCM with

ffmpeg -i input.m4a -c:a pcm_s16le -f s16le temp.pcm

and then back to m4a with

ffmpeg -f s16le -i temp.pcm -c:a aac -b:a 96k -ac 2 output.m4a

and the file now shows a length of 11:18!

I confirm that both input and output files have the same beginning and ending. I tried the same conversion with another voice memo and the duration is the same.

My version is:

ffmpeg version 3.1.1 Copyright (c) 2000-2016 the FFmpeg developers
  built with Apple LLVM version 7.3.0 (clang-703.0.31)

What is going on?

Update: I paste below the full log of both commands. Notice how the first gives Duration: 00:10:22.49 and the second Duration: 00:11:17.56.

First command:

> ffmpeg -i 'input.m4a' -c:a pcm_s16le -f s16le temp.pcm
ffmpeg version 3.1.1 Copyright (c) 2000-2016 the FFmpeg developers
  built with Apple LLVM version 7.3.0 (clang-703.0.31)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.1.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --disable-lzma --enable-vda
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 41.100 / 57. 41.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 47.100 /  6. 47.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.m4a':
  Metadata:
    major_brand     : M4A 
    minor_version   : 0
    compatible_brands: M4A mp42isom
    creation_time   : 2018-09-25 17:09:46
    iTunSMPB        :  00000000 00000840 000003D0 0000000001C7EBF0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    encoder         : com.apple.VoiceMemos (iOS 11.4.1)
    artist          : Louise Le Gat
    title           : input
    grouping        : Short
  Duration: 00:10:22.49, start: 0.044000, bitrate: 66 kb/s
    Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 65 kb/s (default)
    Metadata:
      creation_time   : 2018-09-25 17:09:46
      handler_name    : Core Media Audio
[s16le @ 0x7fb901822c00] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, s16le, to '/Users/miguel/Downloads/temp.pcm':
  Metadata:
    major_brand     : M4A 
    minor_version   : 0
    compatible_brands: M4A mp42isom
    grouping        : Short
    iTunSMPB        :  00000000 00000840 000003D0 0000000001C7EBF0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    title           : input
    artist          : Louise Le Gat
    encoder         : Lavf57.41.100
    Stream #0:0(und): Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s (default)
    Metadata:
      creation_time   : 2018-09-25 17:09:46
      handler_name    : Core Media Audio
      encoder         : Lavc57.48.101 pcm_s16le
Stream mapping:
  Stream #0:0 -> #0:0 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
size=   58360kB time=00:10:22.50 bitrate= 768.0kbits/s speed= 794x    
video:0kB audio:58360kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%

Second command:

> ffmpeg -f s16le -i temp.pcm -c:a aac -b:a 96k -ac 2 output.m4a
ffmpeg version 3.1.1 Copyright (c) 2000-2016 the FFmpeg developers
  built with Apple LLVM version 7.3.0 (clang-703.0.31)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.1.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --disable-lzma --enable-vda
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 41.100 / 57. 41.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 47.100 /  6. 47.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
[s16le @ 0x7fb932000000] Estimating duration from bitrate, this may be inaccurate
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, s16le, from 'temp.pcm':
  Duration: 00:11:17.56, bitrate: 705 kb/s
    Stream #0:0: Audio: pcm_s16le, 44100 Hz, 1 channels, s16, 705 kb/s
[ipod @ 0x7fb931001400] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, ipod, to 'output.m4a':
  Metadata:
    encoder         : Lavf57.41.100
    Stream #0:0: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 96 kb/s
    Metadata:
      encoder         : Lavc57.48.101 aac
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
size=    8050kB time=00:11:17.55 bitrate=  97.3kbits/s speed=39.7x    
video:0kB audio:7935kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.447161%
[aac @ 0x7fb931001a00] Qavg: 938.144
1
  • Share full log of both commands.
    – Gyan
    Commented Oct 24, 2018 at 7:46

1 Answer 1

4

Raw PCM does not store stream properties, so when you ingest a raw PCM stream, ffmpeg assumes a sampling rate of 44100 Hz whereas your source is 48000 Hz. So new duration = old duration x (48000/44100).

Export to WAV or AIFF using -c:a pcm_s16le. Alternatively, save as now and ingest using -f s16le -sample_rate 48000 -i temp.pcm. First method is recommended.

2
  • On WAV or AIFF, you mention "Export to WAV or AIFF using -c:a pcm_s16le", but this is the same as I have in my commands. Can you confirm that is your intention?
    – emonigma
    Commented Oct 24, 2018 at 18:51
  • 1
    Yes, but the container is different.
    – Gyan
    Commented Oct 24, 2018 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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