DVR-Scan icon indicating copy to clipboard operation
DVR-Scan copied to clipboard

"Time code of first frame" metadata

Open vaskokj opened this issue 1 year ago • 10 comments

Bug/Issue Description: I am unsure on if this is a bug or a translation issue or just me not understanding what the field means.

My original video has: Encoded date : UTC 2022-02-23 15:18:42

My original video is 8m 52s long, which mean the video would have ended at 2022-02-23 15:26:34

However dvr-scan reports that Time code of first frame : 15:57:41:15

How can I get/decode this information?

Required Information:

Provide a full copy of the command line options you are using, and add --verbosity debug, for example:

dvr-scan -i GL0100002_output.mp4 -d GL0100002_output -m ffmpeg -c ./dvr-scan.cfg

dvr-scan.cfg ffmpeg-output-args = -map 0 -map -0:d -c:v libx264 -preset fast -crf 21 -c:a aac -sn

Expected Behavior: This detection event was at the very beginning of the video so it should have been pretty close to 15:18:42 to 15:18:45 or so.

Computing Environment:

  • OS: Ubuntu 20.04
  • Python Version: 3.8.10

vaskokj avatar Oct 06 '22 22:10 vaskokj

Can you post the full output from running the program? You can use the --logfile argument and attach the resulting file.

Timecodes aren't corrected for date, so they should all be relative to the start of the video (e.g. no timecode should be greater than 00:08:52.00).

On Thu, Oct 6, 2022 at 6:30 PM vaskokj @.***> wrote:

Bug/Issue Description: I am unsure on if this is a bug or a translation issue or just me not understanding what the field means.

My original video has: Encoded date : UTC 2022-02-23 15:18:42

The video is 8m 52s long, which mean the video would have ended at 2022-02-23 15:26:34

However dvr-scan reports that Time code of first frame : 15:57:41:15

How can I get/decode this information?

Required Information:

Provide a full copy of the command line options you are using, and add --verbosity debug, for example:

dvr-scan -i GL0100002_output.mp4 -d GL0100002_output -m ffmpeg -c ./dvr-scan.cfg

dvr-scan.cfg ffmpeg-output-args = -map 0 -map -0:d -c:v libx264 -preset fast -crf 21 -c:a aac -sn

Expected Behavior: This detection event was at the very beginning of the video so it should have been pretty close to 15:18:42 to 15:18:45 or so.

Computing Environment:

  • OS: Ubuntu 20.04
  • Python Version: 3.8.10

— Reply to this email directly, view it on GitHub https://github.com/Breakthrough/DVR-Scan/issues/117, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA6TBGD7TQJYNMT22EQ3CTWB5HJTANCNFSM6AAAAAAQ7B7ZZY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Breakthrough avatar Oct 06 '22 23:10 Breakthrough

Thanks. So I'm looking at Event 1 with mediainfo

All of the .mp4 files dvr-scan generated all seem to have 15:57:41:15, even though the table in the logs show a good Start Time.

[DVR-Scan] DVR-Scan v1.5.1
[DVR-Scan] Loading config from file:
  ./dvr-scan.cfg
[DVR-Scan] Initializing scan context...
[DVR-Scan] Opened video GL0100002_output.mp4 (848 x 480 at 23.976 FPS).
[DVR-Scan] Scanning input video for motion events...
[DVR-Scan] Splitting events using ffmpeg, first event:
[DVR-Scan] ffmpeg -y -nostdin -v error -ss 00:00:00.042 -i GL0100002_output.mp4 -t 00:00:25.192 -map 0 -map -0:d -c:v libx264 -preset fast -crf 21 -c:a aac -sn GL0100002_output/GL0100002_output.DSME_0001.mp4
[DVR-Scan] Processed 12768 frames read in 72.3 secs (avg 176.6 FPS).
[DVR-Scan] Detected 16 motion events in input.
[DVR-Scan] List of motion events:
-------------------------------------------------------------
|   Event #    |  Start Time  |   Duration   |   End Time   |
-------------------------------------------------------------
|  Event    1  |  00:00:00.0  |  00:00:25.2  |  00:00:25.2  |
|  Event    2  |  00:00:28.0  |  00:00:50.6  |  00:01:18.5  |
|  Event    3  |  00:01:23.6  |  00:00:21.6  |  00:01:45.3  |
|  Event    4  |  00:01:45.3  |  00:00:22.4  |  00:02:07.7  |
|  Event    5  |  00:02:12.2  |  00:01:14.5  |  00:03:26.7  |
|  Event    6  |  00:03:31.5  |  00:00:04.6  |  00:03:36.1  |
|  Event    7  |  00:03:36.2  |  00:00:13.4  |  00:03:49.6  |
|  Event    8  |  00:04:16.0  |  00:00:19.0  |  00:04:35.1  |
|  Event    9  |  00:04:37.2  |  00:00:18.9  |  00:04:56.1  |
|  Event   10  |  00:06:02.8  |  00:00:23.0  |  00:06:25.8  |
|  Event   11  |  00:06:33.0  |  00:00:08.0  |  00:06:41.0  |
|  Event   12  |  00:06:53.2  |  00:00:07.0  |  00:07:00.1  |
|  Event   13  |  00:07:05.3  |  00:00:05.7  |  00:07:11.0  |
|  Event   14  |  00:07:13.9  |  00:00:22.8  |  00:07:36.7  |
|  Event   15  |  00:08:11.8  |  00:00:36.2  |  00:08:48.0  |
|  Event   16  |  00:08:48.1  |  00:00:04.5  |  00:08:52.5  |
-------------------------------------------------------------
[DVR-Scan] Comma-separated timecode values:
[DVR-Scan] Motion events written to disk.
[DVR-Scan] Comma-separated timecode values:
00:00:00.042,00:00:25.234,00:00:27.986,00:01:18.537,00:01:23.625,00:01:45.272,00:01:45.314,00:02:07.669,00:02:12.215,00:03:26.706,00:03:31.503,00:03:36.133,00:03:36.174,00:03:49.563,00:04:16.047,00:04:35.066,00:04:37.235,00:04:56.129,00:06:02.779,00:06:25.802,00:06:33.018,00:06:40.984,00:06:53.163,00:07:00.128,00:07:05.300,00:07:10.972,00:07:13.933,00:07:36.706,00:08:11.783,00:08:48.027,00:08:48.069,00:08:52.532
[DVR-Scan] Motion events written to disk.
$ mediainfo GL0100002_output/GL0100002_output.DSME_0001.mp4 
General
Complete name                            : GL0100002_output/GL0100002_output.DSME_0001.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 4.54 MiB
Duration                                 : 25 s 234 ms
Overall bit rate                         : 1 510 kb/s
Writing application                      : Lavf58.29.100

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L3
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 25 s 234 ms
Bit rate                                 : 1 376 kb/s
Width                                    : 848 pixels
Height                                   : 480 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 23.976 (24000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.141
Stream size                              : 4.14 MiB (91%)
Title                                    : GoPro AVC  
Writing library                          : x264 core 155 r2917 0a84d98
Encoding settings                        : cabac=1 / ref=2 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=6 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=12 / lookahead_threads=2 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=1 / keyint=250 / keyint_min=23 / scenecut=40 / intra_refresh=0 / rc_lookahead=30 / rc=crf / mbtree=1 / crf=21.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Language                                 : English
Color range                              : Full
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 25 s 214 ms
Duration_LastFrame                       : -3 ms
Bit rate mode                            : Constant
Bit rate                                 : 129 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 398 KiB (9%)
Title                                    : GoPro AAC  
Language                                 : English
Default                                  : Yes
Alternate group                          : 1

Other
ID                                       : 3
Type                                     : Time code
Format                                   : QuickTime TC
Duration                                 : 25 s 234 ms
Frame rate                               : 23.976 (24000/1001) FPS
Time code of first frame                 : 15:57:41:15
Time code, striped                       : Yes
Title                                    : GoPro AVC  
Language                                 : English
Default                                  : No

vaskokj avatar Oct 07 '22 13:10 vaskokj

Can you share the mediainfo output for the original video as well? I'm not very familiar with the metadata side of things, but there's probably some command line options you can tweak with ffmpeg using the config file to try and set it: https://dvr-scan.readthedocs.io/en/latest/guide/config_file/#inputoutput

For this to work correctly there might need to be some extra metadata passed to ffmpeg, but again I don't know much about this side of things. It could also complicate things since I don't know if this metadata is available through OpenCV. I'm definitely open to any suggestions or ideas to address this.

Breakthrough avatar Oct 08 '22 02:10 Breakthrough

From DVR-Scan's perspective it never sets those fields explicitly:

ffmpeg -y -nostdin -v error -ss 00:00:00.042 -i GL0100002_output.mp4 -t 00:00:25.192 -map 0 -map -0:d -c:v libx264 -preset fast -crf 21 -c:a aac -sn GL0100002_output/GL0100002_output.DSME_0001.mp

This is why I'm confused as to where that value comes from just as you are.

Breakthrough avatar Oct 08 '22 02:10 Breakthrough

Here is what mediainfo is saying for one of the output files. Oddly enough the other files that were generated say the same thing.

$ mediainfo GL0100002_output/GL0100002_output.DSME_0001.mp4 
General
Complete name                            : GL0100002_output/GL0100002_output.DSME_0001.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 4.54 MiB
Duration                                 : 25 s 234 ms
Overall bit rate                         : 1 510 kb/s
Writing application                      : Lavf58.29.100

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L3
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 25 s 234 ms
Bit rate                                 : 1 376 kb/s
Width                                    : 848 pixels
Height                                   : 480 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 23.976 (24000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.141
Stream size                              : 4.14 MiB (91%)
Title                                    : GoPro AVC  
Writing library                          : x264 core 155 r2917 0a84d98
Encoding settings                        : cabac=1 / ref=2 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=6 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=12 / lookahead_threads=2 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=1 / keyint=250 / keyint_min=23 / scenecut=40 / intra_refresh=0 / rc_lookahead=30 / rc=crf / mbtree=1 / crf=21.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Language                                 : English
Color range                              : Full
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 25 s 214 ms
Duration_LastFrame                       : -3 ms
Bit rate mode                            : Constant
Bit rate                                 : 129 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 398 KiB (9%)
Title                                    : GoPro AAC  
Language                                 : English
Default                                  : Yes
Alternate group                          : 1

Other
ID                                       : 3
Type                                     : Time code
Format                                   : QuickTime TC
Duration                                 : 25 s 234 ms
Frame rate                               : 23.976 (24000/1001) FPS
Time code of first frame                 : 15:57:41:15
Time code, striped                       : Yes
Title                                    : GoPro AVC  
Language                                 : English
Default                                  : No

vaskokj avatar Oct 10 '22 13:10 vaskokj

Could this 15:57:41:15 be the actual time of when the video started playing and not from the videos perspective of time? e.g. the first frame starts at 00:00:00.

I really only need this

| Event 1 | 00:00:00.0 | 00:00:25.2 | 00:00:25.2 |

which seems to already be produced. Is there any easy way of getting this without parsing the output?

vaskokj avatar Oct 18 '22 14:10 vaskokj

Are there any small samples you can share containing the parameter? If you split the video using ffmpeg the same way DVR-Scan does, what does the start time become then?

Breakthrough avatar Oct 19 '22 02:10 Breakthrough

Unfortunately I can't send a video since its all proprietary information.

I did what you suggested and ran ffmpeg directly on the file and got the same exact results. So it looks like ffmpeg is injecting it and doesn't have anything to do with dvr-scan but I still don't understand what it means. I really just need the time the events happen in the original video after its split and the time of the original video.

ffmpeg -y -nostdin -v error -ss 00:00:00.042 -i GL0100002_output.mp4 -t 00:00:25.192 -map 0 -map -0:d -c:v libx264 -preset fast -crf 21 -c:a aac -sn GL0100002_test_output.DSME_0001.mp4

here is the output of the above command from mediainfo. same `15:57:41:15` value. 

$ mediainfo GL0100002_test.DSME_0001.mp4 
General
Complete name                            : GL0100002_test.DSME_0001.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 4.54 MiB
Duration                                 : 25 s 234 ms
Overall bit rate                         : 1 510 kb/s
Writing application                      : Lavf58.29.100

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L3
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 25 s 234 ms
Bit rate                                 : 1 376 kb/s
Width                                    : 848 pixels
Height                                   : 480 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 23.976 (24000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.141
Stream size                              : 4.14 MiB (91%)
Title                                    : GoPro AVC  
Writing library                          : x264 core 155 r2917 0a84d98
Encoding settings                        : cabac=1 / ref=2 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=6 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=12 / lookahead_threads=2 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=1 / keyint=250 / keyint_min=23 / scenecut=40 / intra_refresh=0 / rc_lookahead=30 / rc=crf / mbtree=1 / crf=21.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Language                                 : English
Color range                              : Full
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 25 s 214 ms
Duration_LastFrame                       : -3 ms
Bit rate mode                            : Constant
Bit rate                                 : 129 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 398 KiB (9%)
Title                                    : GoPro AAC  
Language                                 : English
Default                                  : Yes
Alternate group                          : 1

Other
ID                                       : 3
Type                                     : Time code
Format                                   : QuickTime TC
Duration                                 : 25 s 234 ms
Frame rate                               : 23.976 (24000/1001) FPS
Time code of first frame                 : 15:57:41:15
Time code, striped                       : Yes
Title                                    : GoPro AVC  
Language                                 : English
Default                                  : No

vaskokj avatar Oct 19 '22 13:10 vaskokj

So this is what I found out.

The time code is stored in a separate time code track and is written by the original authoring app viz. GoPro. This field comes from the professional TV/broadcast practice of storing consecutive timecodes on successive pieces of recording, originally on analogue tapes.

Add -write_tmcd false to disable copying it over.

https://stackoverflow.com/questions/74126500/ffmpeg-time-code-of-first-frame-not-making-sense/74130478#74130478

It looks like I can set it with -timecode '00:00:00:00' (hh:mm:ss:ff where ff is the frame number).

ffmpeg -y -nostdin -v error -ss 00:00:00.042 -i GL0100002_output.mp4 -t 00:00:25.192 -map_metadata 0 -map 0 -map -0:d -c:v libx264 -preset fast -crf 21 -c:a aac -sn -timecode '00:00:00.042' GL0100002_test.DSME_0001.mp4

adding -map_metadata 0 keeps the "Encoded date" and "Tagged date" values from the original video.

I assume the the best way to get the -ss values passed to ffmpeg (e.g.

[DVR-Scan] Comma-separated timecode values:
00:00:00.042,00:00:25.234,00:00:27.986,00:01:18.537,00:01:23.625,00:01:45.272,00:01:45.314,00:02:07.669,00:02:12.215,00:03:26.706,00:03:31.503,00:03:36.133,00:03:36.174,00:03:49.563,00:04:16.047,00:04:35.066,00:04:37.235,00:04:56.129,00:06:02.779,00:06:25.802,00:06:33.018,00:06:40.984,00:06:53.163,00:07:00.128,00:07:05.300,00:07:10.972,00:07:13.933,00:07:36.706,00:08:11.783,00:08:48.027,00:08:48.069,00:08:52.532

) is to just parse the output of dvr-scan?

vaskokj avatar Oct 20 '22 16:10 vaskokj

Pretty much, yes. This could possibly be done using some kind of template variables in the future.

Breakthrough avatar Nov 08 '22 01:11 Breakthrough