0

I want to concatenate two GoPro videos losslessly with that FFmpeg command:

ffmpeg -safe 0 -f concat -i "list_videos.txt" -map 0:v -map 0:a -map 0:3 -copy_unknown -tag:2 gpmd -c copy "ab.mp4"

with list_videos.txt containing:

file 'a.MP4'
file 'b.MP4'

That works fine. The extra attributes -map 0:v -map 0:a -map 0:3 -copy_unknown -tag:2 gpmd keeps the telemetry information.

Since a.MP4 is a bit too long and I just want to keep the first 10 seconds of it, I run the following FFmpeg command to keep the first 10 seconds of it, as suggested by Gyan:

ffmpeg -sseof -10 -i a.MP4 -map 0:v -map 0:a -map 0:3 -map 0:3 -copy_unknown -tag:2 gpmd -tag:3 gpmd -c copy a_only_the_first_10secs.MP4

That works fine. However, when I try to concatenate a_only_the_first_10secs.MP4 with b.MP4 using the aforementioned command (ffmpeg -safe 0 -f concat [...]), it fails with that error:

[mp4 @ 000001da1b77e900] Application provided duration: -9223372036854775808 / timestamp: -9223372036854775808 is out of range for mov/mp4 format
[mp4 @ 000001da1b77e900] pts has no value

What's the issue?


Full log:

C:\vids\test>ffmpeg -safe 0 -f concat -i "list_videos.txt" -map 0:v -map 0:a -map 0:3 -copy_unknown -tag:2 gpmd -c copy "ab.mp4"
ffmpeg version 5.0.1-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 11.2.0 (Rev7, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      57. 17.100 / 57. 17.100
  libavcodec     59. 18.100 / 59. 18.100
  libavformat    59. 16.100 / 59. 16.100
  libavdevice    59.  4.100 / 59.  4.100
  libavfilter     8. 24.100 /  8. 24.100
  libswscale      6.  4.100 /  6.  4.100
  libswresample   4.  3.100 /  4.  3.100
  libpostproc    56.  3.100 / 56.  3.100
[concat @ 000001da1b736440] Could not find codec parameters for stream 4 (Unknown: none): unknown codec
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, concat, from 'list_videos.txt':
  Duration: N/A, start: -0.026667, bitrate: 59959 kb/s
  Stream #0:0(eng): Video: hevc (Main) (hvc1 / 0x31637668), yuvj420p(pc, bt709), 3840x2160 [SAR 1:1 DAR 16:9], 59651 kb/s, 59.94 fps, 59.94 tbr, 60k tbn
    Metadata:
      handler_name    : GoPro H.265
      vendor_id       : [0][0][0][0]
      timecode        : 00:05:41:11
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s
    Metadata:
      handler_name    : GoPro AAC
      vendor_id       : [0][0][0][0]
  Stream #0:2(eng): Data: bin_data (gpmd / 0x646D7067), 59 kb/s
    Metadata:
      handler_name    : GoPro MET
  Stream #0:3(eng): Data: bin_data (gpmd / 0x646D7067), 59 kb/s
    Metadata:
      handler_name    : GoPro MET
  Stream #0:4: Unknown: none
[mp4 @ 000001da1b77e900] Application provided duration: -9223372036854775808 / timestamp: -9223372036854775808 is out of range for mov/mp4 format
[mp4 @ 000001da1b77e900] pts has no value
Output #0, mp4, to 'ab.mp4':
  Metadata:
    encoder         : Lavf59.16.100
  Stream #0:0(eng): Video: hevc (Main) (hvc1 / 0x31637668), yuvj420p(pc, bt709), 3840x2160 [SAR 1:1 DAR 16:9], q=2-31, 59651 kb/s, 59.94 fps, 59.94 tbr, 60k tbn
    Metadata:
      handler_name    : GoPro H.265
      vendor_id       : [0][0][0][0]
      timecode        : 00:05:41:11
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s
    Metadata:
      handler_name    : GoPro AAC
      vendor_id       : [0][0][0][0]
  Stream #0:2(eng): Data: bin_data (gpmd / 0x646D7067), 59 kb/s
    Metadata:
      handler_name    : GoPro MET
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #0:3 -> #0:2 (copy)
Press [q] to stop, [?] for help
frame=19394 fps=3787 q=-1.0 Lsize= 2368221kB time=00:05:23.56 bitrate=59958.9kbits/s speed=63.2x
video:2358037kB audio:7480kB subtitle:0kB other streams:2347kB global headers:0kB muxing overhead: 0.015097%

Franck Dernoncourt
  • 24,246
  • 64
  • 231
  • 400

1 Answers1

1

The unknown stream is causing ffmpeg to look for a presentation timestamp that it doesn't have. You can extract the metadata, run the concatenation, then add the metadata back to the file.

Extract each stream separately:

ffmpeg -i a.MP4 -map 0:2 -f ffmetadata a_gpmd1.txt
ffmpeg -i a.MP4 -map 0:3 -f ffmetadata a_gpmd2.txt

Concatenate the metadata: type a_gpmd1.txt a_gpmd2.txt > a_metadata.txt Repeat for b.MP4.

Merge those two for the final metadata file:

type a_metadata.txt b_metadata.txt > final_metadata.txt

Since you've already dumped the metadata you can get the first 10 seconds with:

ffmpeg -i a.MP4 -to 00:00:10 -map 0:v -map 0:a -c copy a_first_10secs.MP4

Perform the concatenation:

ffmpeg -safe 0 -f concat -i "list_videos.txt" -map 0:v -map 0:a -c copy "concatenated.mp4"

Then, add the metadata back to the file:

ffmpeg -i "concatenated.mp4" -i final_metadata.txt -map_metadata 1 -c copy "final_output.mp4"