[FFmpeg-user] editing video stream with KLV metadata

Claire Mantel clma at fotonik.dtu.dk
Mon May 7 13:41:44 EEST 2018

Hi Moritz,

Thanks a lot for your answer!
I'm only replying now as I only had access to a software able to read files with KLV this morning.

On Thu, May 03, 2018 at 14:21:29 +0000, Claire Mantel wrote:
>> I have a videostream with klv metadata that I want to edit while keeping the metadata.
>> I'm wondering if it's possible with ffmpeg?

>I assume you mean that which ffmpeg identifies as a KLV data stream? (I have no knowledge of KLV, by the way.)
Yes, KLV is a standard for encoding data (https://en.wikipedia.org/wiki/KLV)
I believe it's quite commonly used in commercial UAVs (drones) to tag the video with info like timestamp, GPS coordinates and pitch, roll and yaw of the camera.

>ffmpeg isn't even considering copying the data stream. By implementation, ffmpeg by default extracts/maps exactly one of each type of stream (video, audio, subtitles, data). >For data, I see the restriction "Data only if codec id match" in the code, which I don't quite understand.

>Anyway, you can either explicitly map both streams:
 > -map 0:v -map 0:d
>or just ask ffmpeg to map all streams:
>  -map 0

I tried the first command and it works, so thanks a lot!
(command ffmpeg -ss 00:02:15.0 -i video_out_2018_05_01_14_11_53.ts -c:v copy -c:d copy -map 0:v -map 0:d testCopy.ts)

So I guess it means ffmpeg is able to tell which KLV data is associated with which frame as the editing also edited the KLV stream properly.

I'm also trying to output the KLV data in some text file, I tried 
ffmpeg -i video_out_2018_05_01_14_11_53.ts -f ffmetadata testMetadata.txt
ffmpeg -i video_out_2018_05_01_14_11_53.ts -map 0:d -f ffmetadata testMetadata.txt
ffmpeg -i video_out_2018_05_01_14_11_53.ts -c:d copy  -map 0:d -f ffmetadata testMetadata.txt

but I only get " ;FFMETADATA1 encoder=Lavf58.13.100 [STREAM]"  in my testMetadata.txt file

Even though in the console output there is " Stream mapping:   Stream #0:1 -> #0:0 (copy)"
(complete console output below)

Would you have any input?
Thanks in advance!

Complete console of ffmpeg -i video_out_2018_05_01_14_11_53.ts -c:d copy  -map 0:d -f ffmetadata testMetadata.txt 
ffmpeg version N-90926-gbad42e9b40 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.100 / 58. 13.100
  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
[mpegts @ 00000224e8eb9f00] PES packet size mismatch
Input #0, mpegts, from 'video_out_2018_05_01_14_11_53.ts':
  Duration: 00:08:14.40, start: 3600.000000, bitrate: 6676 kb/s
  Program 1
    Stream #0:0[0x41]: Video: h264 (Constrained Baseline) (HDMV / 0x564D4448), yuv420p(progressive), 1280x720, 22.17 tbr, 90k tbn, 180k tbc
    Stream #0:1[0x42]: Data: klv (KLVA / 0x41564C4B)
File 'testMetadata.txt' already exists. Overwrite ? [y/N] y
Output #0, ffmetadata, to 'testMetadata.txt':
    encoder         : Lavf58.13.100
    Stream #0:0: Data: klv (KLVA / 0x41564C4B)
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
Press [q] to stop, [?] for help
size=       0kB time=00:08:14.34 bitrate=   0.0kbits/s speed=13.8x
video:0kB audio:0kB subtitle:0kB other streams:1727kB global headers:0kB muxing overhead: unknown

More information about the ffmpeg-user mailing list