editing video stream with KLV metadata

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

editing video stream with KLV metadata

Claire Mantel
Hello,

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 tried several command lines, the two most relevant being the two below I believe.
However, in both cases I only get the video stream...

I also tried to retrieve the metadata in a file with
ffmpeg -ss 00:02:15.0 -i video_out_2018_05_01_14_11_53.ts -f ffmetadata testMetadata.txt
But that gives a file containing: ;FFMETADATA1 encoder=Lavf58.13.100
As if it was using data from the video stream and not the data stream.

Thanks for any help!
Claire

ffmpeg -ss 00:02:15.0 -i video_out_2018_05_01_14_11_53.ts -c:v copy -c:d copy EditMetadata.ts

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 @ 00000201640a9f40] PES packet size mismatch
    Last message repeated 1 times
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 '4minShakyLowLightMetadata.ts' already exists. Overwrite ? [y/N] y
Output #0, mpegts, to '4minShakyLowLightMetadata.ts':
  Metadata:
    encoder         : Lavf58.13.100
    Stream #0:0: Video: h264 (Constrained Baseline) (HDMV / 0x564D4448), yuv420p(progressive), 1280x720, q=2-31, 22.17 tbr, 90k tbn, 90k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mpegts @ 00000201640a9f40] PES packet size mismatch5:54.08 bitrate=7835.8kbits/s speed=6.48x
frame= 7966 fps=145 q=-1.0 Lsize=  341290kB time=00:05:59.35 bitrate=7780.3kbits/s speed=6.54x
video:315714kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.101032%


the second is

ffmpeg -ss 00:02:15.0 -i video_out_2018_05_01_14_11_53.ts -codec:video copy -map_metadata:s:d 0:s:d -t 00:04:00.0 EditMetadataTrial2.ts

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 @ 0000020095249fc0] PES packet size mismatch
    Last message repeated 1 times
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)
Output #0, mpegts, to '4minShakyLowLightMetadataTrial2.ts':
  Metadata:
    encoder         : Lavf58.13.100
    Stream #0:0: Video: h264 (Constrained Baseline) (HDMV / 0x564D4448), yuv420p(progressive), 1280x720, q=2-31, 22.17 tbr, 90k tbn, 90k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 5315 fps=131 q=-1.0 Lsize=  252496kB time=00:03:59.95 bitrate=8620.1kbits/s speed=5.89x
video:233637kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.071818%
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: editing video stream with KLV metadata

Moritz Barsnick
Hi Claire,

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.)

> I also tried to retrieve the metadata in a file with
> ffmpeg -ss 00:02:15.0 -i video_out_2018_05_01_14_11_53.ts -f ffmetadata testMetadata.txt
> But that gives a file containing: ;FFMETADATA1 encoder=Lavf58.13.100
> As if it was using data from the video stream and not the data stream.

At this point, I'm not sure whether you mean that stream 0:1 or actual
metadata.

I'm assuming you mean that data stream, as seen in the following
command line:

> ffmpeg -ss 00:02:15.0 -i video_out_2018_05_01_14_11_53.ts -c:v copy -c:d copy EditMetadata.ts
[...]
> 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)
[...]
> Output #0, mpegts, to '4minShakyLowLightMetadata.ts':
>   Metadata:
>     encoder         : Lavf58.13.100
>     Stream #0:0: Video: h264 (Constrained Baseline) (HDMV / 0x564D4448), yuv420p(progressive), 1280x720, q=2-31, 22.17 tbr, 90k tbn, 90k tbc
> Stream mapping:
>   Stream #0:0 -> #0:0 (copy)

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

At that point, it depends on whether ffmpeg is willing to and capable
of muxing that data stream. Which will give:
>   Stream #0:0 -> #0:0 (copy)
>   Stream #0:1 -> #0:1 (copy)

If not (please try and give us the output), ffmpeg offers this
option:

  ‘-copy_unknown’
      Allow input streams with unknown type to be copied instead of failing if copying such streams is attempted.

I don't know whether you would need it though.

Hope this helps,
Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: editing video stream with KLV metadata

Claire Mantel
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!
Claire

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':
  Metadata:
    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
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: editing video stream with KLV metadata

Moritz Barsnick
Hi Claire,

On Mon, May 07, 2018 at 10:41:44 +0000, Claire Mantel wrote:
> 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.

I see.

> I tried the first command and it works, so thanks a lot!

Very nice, thanks for the feedback.

> 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.

That means that the data stream has timestamps as well (which seems
necessary, if you want to correlate changing GPS positions with a
recording).

> 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

Again, as far as ffmpeg is concerned, that KLV stream is a binary data
stream with unknown content. While that content may be "metadata", what
ffmpeg usually considers as metadata is additional data which is
"attached" to a stream, not contained. That's why your ffmpeg metadata
commands are to no avail.

> Would you have any input?

You need to access the binary data of the stream. One method is
outlined here:
https://stackoverflow.com/a/29461404/3974309

So you can dump that data to a file. As far as I know, it will lose its
timestamps though. (I *may* be wrong here.) You would need to read the
KLV specification to understand that data, ffmpeg doesn't.

There was once a suggestion for an "fftextdata" muxer (and demuxer)
which might suit your needs. It would dump each received packet with a
timestamp and the base64-encoded hex data payload. Again, you need to
interpret the data on your own.

The patch was never accepted (and perhaps was never meant to be):
https://ffmpeg.org/pipermail/ffmpeg-devel/2016-May/194445.html
I am attaching a rebased version, in case it's something which could
help you. I assume it doesn't help, as you actually want to have the
KLV data interpreted?

Med vennlig hilsen,
Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

ffmpeg-2017-02-07-textdata.01.patch (13K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: editing video stream with KLV metadata

Carl Eugen Hoyos-2
In reply to this post by Claire Mantel
2018-05-03 16:21 GMT+02:00, Claire Mantel <[hidden email]>:

> I have a videostream with klv metadata that I want to edit
> while keeping the metadata.

Just to add to what Moritz wrote:
FFmpeg can read your input file, it can write a new file (with
different properties), it can - as Moritz kindly explained - copy
klv streams but it is not a tool to "edit" files / transport streams.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".