Log in

View Full Version : How to add a time code to H264


KSSW
22nd February 2024, 01:13
How to add a time code to H264
Time code of first frame: 01:00:00:00


General
Complete name : C:\Users\Use\Desktop\00000.264
Format : AVC
Format/Info : Advanced Video Codec
File size : 85.9 MiB
Overall bit rate mode : Constant
Frame rate : 23.976 FPS

Video
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4.1
Format settings : CABAC / 4 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference frames : 4 frames
Format settings, Slice count : 4 slices per frame
Bit rate mode : Constant
Bit rate : 18.0 Mb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
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.362
Time code of first frame : 01:00:00:00


I don't know how to add a time code?

Selur
22nd February 2024, 12:08
https://stackoverflow.com/questions/65027118/ffmpeg-change-timecode-metadata-inside-video-file might help

KSSW
23rd February 2024, 02:12
If you follow this method, there will be no Time code of first frame: 01:00:00:00
Instead, there will be the following:

https://pic.imgdb.cn/item/65d7f0b69f345e8d03da1de8.jpg

https://pic.imgdb.cn/item/65d7f0d49f345e8d03da5e54.jpg

Selur
23rd February 2024, 15:15
Ah okay, so set simply changes the first time code not set this info.
What do you get if you call:
ffmpeg -i "path to inpu" -f ffmetadata in.txt
in the ffmetadata.txt if you call it on one of the files with this info?
If it includes the info you can probably use '-metadata' option in ffmpeg to set the info.

Time code of first frame : 01:00:00:00
I only have this info on Quicktime Time code streams not on the raw video,...
Other
ID : 3
Type : Time code
Format : QuickTime TC
Duration : 160 ms
Frame rate : 25.000 FPS
Time code of first frame : 01:00:00:00
Time code of last frame : 01:00:00:03
Time code, stripped : Yes
Language : English
Encoded date : 2016-01-18 21:44:55 UTC
Tagged date : 2016-01-18 21:44:55 UTC


Cu Selur

Selur
23rd February 2024, 15:30
I tried:
ffmpeg -y -i "g:\TestClips&Co\files\5000frames.mp4" -timecode 01:02:03.04 -c copy g:\Output\test.mkv
and got:
General
Unique ID : 53443209611799196111184538750715928172 (0x2834C9AB657FEA584932404B99939E6C)
Complete name : g:\Output\test.mkv
Format : Matroska
Format version : Version 4
File size : 799 KiB
Duration : 3 min 20 s
Overall bit rate : 32.7 kb/s
Frame rate : 25.000 FPS
Writing application : Lavf60.20.100
Writing library : Lavf60.20.100
ErrorDetectionType : Per level 1
Time code of first frame : 01:02:03.04
Time code source : Matroska tags

Video
ID : 1
Format : HEVC
Format/Info : High Efficiency Video Coding
Format profile : Main 10@L4.1@Main
Codec ID : V_MPEGH/ISO/HEVC
Duration : 3 min 20 s
Bit rate : 32.1 kb/s
Width : 640 pixels
Height : 480 pixels
Display aspect ratio : 4:3
Frame rate mode : Constant
Frame rate : 25.000 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 10 bits
Bits/(Pixel*Frame) : 0.004
Stream size : 784 KiB (98%)
Writing library : x265 2.6+22-ff02513b92c0:[Windows][GCC 7.2.0][64 bit] 10bit
Encoding settings : cpuid=1173503 / frame-threads=4 / numa-pools=16 / wpp / no-pmode / no-pme / no-psnr / no-ssim / log-level=2 / input-csp=1 / input-res=640x480 / interlace=0 / total-frames=0 / level-idc=41 / high-tier=0 / uhd-bd=0 / ref=3 / no-allow-non-conformance / no-repeat-headers / annexb / no-aud / no-hrd / info / hash=0 / no-temporal-layers / no-open-gop / min-keyint=25 / keyint=250 / gop-lookahead=0 / bframes=4 / b-adapt=2 / b-pyramid / bframe-bias=0 / rc-lookahead=20 / lookahead-slices=0 / scenecut=40 / radl=0 / no-intra-refresh / ctu=64 / min-cu-size=8 / no-rect / no-amp / max-tu-size=32 / tu-inter-depth=1 / tu-intra-depth=1 / limit-tu=0 / rdoq-level=2 / dynamic-rd=0.00 / no-ssim-rd / signhide / no-tskip / nr-intra=0 / nr-inter=0 / no-constrained-intra / strong-intra-smoothing / max-merge=2 / limit-refs=3 / limit-modes / me=1 / subme=2 / merange=57 / temporal-mvp / weightp / no-weightb / no-analyze-src-pics / deblock=-1:-1 / sao / no-sao-non-deblock / rd=3 / no-early-skip / rskip / no-fast-intra / no-tskip-fast / no-cu-lossless / no-b-intra / no-splitrd-skip / rdpenalty=0 / psy-rd=2.50 / psy-rdoq=10.00 / no-rd-refine / no-lossless / cbqpoffs=-2 / crqpoffs=-2 / rc=crf / crf=18.0 / qcomp=0.60 / qpstep=4 / stats-write=0 / stats-read=0 / vbv-maxrate=20000 / vbv-bufsize=20000 / vbv-init=0.9 / crf-max=0.0 / crf-min=0.0 / ipratio=1.40 / pbratio=1.30 / aq-mode=1 / aq-strength=0.00 / cutree / zone-count=0 / no-strict-cbr / qg-size=8 / no-rc-grain / qpmax=69 / qpmin=0 / no-const-vbv / sar=0 / overscan=0 / videoformat=5 / range=0 / colorprim=2 / transfer=2 / colormatrix=5 / chromaloc=0 / display-window=0 / max-cll=0,0 / min-luma=0 / max-luma=1023 / log2-max-poc-lsb=8 / vui-timing-info / vui-hrd-info / slices=1 / no-opt-qp-pps / no-opt-ref-list-length-pps / no-multi-pass-opt-rps / scenecut-bias=0.05 / no-opt-cu-delta-qp / no-aq-motion / no-hdr / no-hdr-opt / no-dhdr10-opt / analysis-save=(null) / analysis-load=(null) / analysis-reuse-level=5 / scale-factor=0 / refine-intra=0 / refine-inter=0 / refine-mv=0 / limit-sao / ctu-info=0 / no-lowpass-dct / refine-mv-type=0 / copy-pic=1
Default : Yes
Forced : No
Color range : Limited
Matrix coefficients : BT.470 System B/G
VENDOR_ID : [0][0][0][0]


video stream didn't chante to vfr, this might not be caused by the '-timecode ....' settings, but by something else.

KSSW
24th February 2024, 07:43
Ah okay, so set simply changes the first time code not set this info.
What do you get if you call:

in the ffmetadata.txt if you call it on one of the files with this info?
If it includes the info you can probably use '-metadata' option in ffmpeg to set the info.


I only have this info on Quicktime Time code streams not on the raw video,...
Other
ID : 3
Type : Time code
Format : QuickTime TC
Duration : 160 ms
Frame rate : 25.000 FPS
Time code of first frame : 01:00:00:00
Time code of last frame : 01:00:00:03
Time code, stripped : Yes
Language : English
Encoded date : 2016-01-18 21:44:55 UTC
Tagged date : 2016-01-18 21:44:55 UTC


Cu Selur

Hello Selur

Thank you for your the previous answer

So how does below H264 RAW file generate the time code (Time code of first frame : 01:00:00:00) parameter?

This is the H264 RAW file
https://drive.google.com/file/d/1DH_EoUl5aVXKE-8CL7TsLDus8-8oNYS5/view?usp=drive_link

If want to solve the problem

Container encapsulated time code parameters It is not advisable

But rather, the time code parameters need to be included in the RAW video file This is the main problem

Or perhaps the H264 RAW file of FFmpeg does not support the time code parameter at all (Time code of first frame: 01:00:00:00)

rwill
24th February 2024, 08:44
Disclaimer: I have not looked at the example raw h.264 stream.

There can be a time code in the picture timing SEI message in H.264. It can contain hours:minutes:seconds:frames. How you get x264 to write such a timecode to the picture timing SEI I do not know.

KSSW
24th February 2024, 08:57
Disclaimer: I have not looked at the example raw h.264 stream.

There can be a time code in the picture timing SEI message in H.264. It can contain hours:minutes:seconds:frames. How you get x264 to write such a timecode to the picture timing SEI I do not know.

It was deleted just now and now it has been reissued

This is the H264 RAW file
https://drive.google.com/file/d/1DH_EoUl5aVXKE-8CL7TsLDus8-8oNYS5/view?usp=drive_link

KSSW
24th February 2024, 10:31
Videos downloaded randomly from websites

ivanb
24th February 2024, 17:34
Timecode is indeed contained within the pic_struct. Unfortunately, I haven't found a way to write it using x264.
https://i.ibb.co/dtVs3vC/Screenshot-2024-02-24-at-23-18-00-2.png (https://ibb.co/dtVs3vC)

ivanb
24th February 2024, 17:46
Here is what x264 source says about it:

// These clock timestamps are not standardised so we don't set them
// They could be time of origin, capture or alternative ideal display
for( int i = 0; i < num_clock_ts[h->fenc->i_pic_struct]; i++ )
bs_write1( &q, 0 ); // clock_timestamp_flag