Updating mp4 chapter times and names with ffmpeg?

I'm trying to add custom chapters with ffmpeg to an mp4 file by extracting the metadata file and following this guide.

However, when I edit the metadata file to change any of the chapter names, the second command to re-add the metadata ignores changes to the chapters and leaves them as they are. It definitely reads in the metadata file correctly, as when ffmpeg prints out the data of the two input files, it prints the streams of the mp4 and all the metadata of the metadata file, with all the chapters correctly formatted and parsed.

As soon as it creates the output file though, it has the old chapter names again. If I change other metadata that works (such as the title key or artist keys), but the chapters don't.

Full log of the start of the command:

PS D:\ffmpeg> ./bin/ffmpeg.exe -i .\new_file.mp4 -i FFMETADATAFILE -map_metadata 1 -codec copy .\output.mp4
ffmpeg version N-90979-g08032331ac Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
  libavutil      56. 18.100 / 56. 18.100
  libavcodec     58. 19.100 / 58. 19.100
  libavformat    58. 13.101 / 58. 13.101
  libavdevice    58.  4.100 / 58.  4.100
  libavfilter     7. 21.100 /  7. 21.100
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '.\new_file.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : new_file
    encoder         : Lavf57.46.100
  Duration: 02:01:34.85, start: 0.000000, bitrate: 2940 kb/s
    Chapter #0:0: start 0.000000, end 628.962000
    Metadata:
      title           : Chapter 1
    Chapter #0:1: start 628.962000, end 1042.083000
    Metadata:
      title           : Chapter 2
    Chapter #0:2: start 1042.083000, end 1882.172000
    Metadata:
      title           : Chapter 3
    Chapter #0:3: start 1882.172000, end 2479.102000
    Metadata:
      title           : Chapter 4
    Chapter #0:4: start 2479.102000, end 3095.718000
    Metadata:
      title           : Chapter 5
    Chapter #0:5: start 3095.718000, end 3681.511000
    Metadata:
      title           : Chapter 6
    Chapter #0:6: start 3681.511000, end 4145.600000
    Metadata:
      title           : Chapter 7
    Chapter #0:7: start 4145.600000, end 5149.019000
    Metadata:
      title           : Chapter 8
    Chapter #0:8: start 5149.019000, end 5704.908000
    Metadata:
      title           : Chapter 9
    Chapter #0:9: start 5704.908000, end 5980.850000
    Metadata:
      title           : Chapter 10
    Chapter #0:10: start 5980.850000, end 6826.403000
    Metadata:
      title           : Chapter 11
    Chapter #0:11: start 6826.403000, end 7294.746000
    Metadata:
      title           : Chapter 12
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x816 [SAR 1:1 DAR 40:17], 2678 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:2(eng): Data: bin_data (text / 0x74786574)
    Metadata:
      handler_name    : SubtitleHandler
Input #1, ffmetadata, from 'FFMETADATAFILE':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : Title
    encoder         : Lavf58.13.101
  Duration: 02:01:34.75, start: 0.000000, bitrate: 0 kb/s
    Chapter #1:0: start 0.000000, end 628.962000
    Metadata:
      title           : Edited Name
    Chapter #1:1: start 628.962000, end 1042.083000
    Metadata:
      title           : Chapter 2
    Chapter #1:2: start 1042.083000, end 1882.172000
    Metadata:
      title           : Chapter 3
    Chapter #1:3: start 1882.172000, end 2479.102000
    Metadata:
      title           : Chapter 4
    Chapter #1:4: start 2479.102000, end 3095.718000
    Metadata:
      title           : Chapter 5
    Chapter #1:5: start 3095.718000, end 3681.511000
    Metadata:
      title           : Chapter 6
    Chapter #1:6: start 3681.511000, end 4145.600000
    Metadata:
      title           : Chapter 7
    Chapter #1:7: start 4145.600000, end 5149.019000
    Metadata:
      title           : Chapter 8
    Chapter #1:8: start 5149.019000, end 5704.908000
    Metadata:
      title           : Chapter 9
    Chapter #1:9: start 5704.908000, end 5980.850000
    Metadata:
      title           : Chapter 10
    Chapter #1:10: start 5980.850000, end 6826.403000
    Metadata:
      title           : Chapter 11
    Chapter #1:11: start 6826.403000, end 7294.746000
    Metadata:
      title           : Chapter 12
File '.\output.mp4' already exists. Overwrite ? [y/N] y
Output #0, mp4, to '.\output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : Title
    encoder         : Lavf58.13.101
    Chapter #0:0: start 0.000000, end 628.962000
    Metadata:
      title           : Chapter 1
    Chapter #0:1: start 628.962000, end 1042.083000
    Metadata:
      title           : Chapter 2
    Chapter #0:2: start 1042.083000, end 1882.172000
    Metadata:
      title           : Chapter 3
    Chapter #0:3: start 1882.172000, end 2479.102000
    Metadata:
      title           : Chapter 4
    Chapter #0:4: start 2479.102000, end 3095.718000
    Metadata:
      title           : Chapter 5
    Chapter #0:5: start 3095.718000, end 3681.511000
    Metadata:
      title           : Chapter 6
    Chapter #0:6: start 3681.511000, end 4145.600000
    Metadata:
      title           : Chapter 7
    Chapter #0:7: start 4145.600000, end 5149.019000
    Metadata:
      title           : Chapter 8
    Chapter #0:8: start 5149.019000, end 5704.908000
    Metadata:
      title           : Chapter 9
    Chapter #0:9: start 5704.908000, end 5980.850000
    Metadata:
      title           : Chapter 10
    Chapter #0:10: start 5980.850000, end 6826.403000
    Metadata:
      title           : Chapter 11
    Chapter #0:11: start 6826.403000, end 7294.746000
    Metadata:
      title           : Chapter 12
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x816 [SAR 1:1 DAR 40:17], q=2-31, 2678 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 90k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)

You can see I've edited the title key and the name of the first chapter in Input #1, the metadata file, but then only the title is different in the output.

Any help appreciated.


Solved - looks like -map_metadata only does the top keys before the chapters, you need -map_chapters to get the chapters as well.

ffmpeg -i INPUT -i FFMETADATAFILE -map_metadata 1 -map_chapters 1 -codec copy OUTPUT