Opened 6 months ago

Last modified 6 months ago

#9876 new defect

timestamp is not correct when mux a clip into mkv

Reported by: lincutt Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: nvenc hevc mkv
Cc: lincutt Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
after transcode a short clip(2:00) with hevc_nvenc, and mux it into mkv, the output clip time is changed to 1193:04:43.45.
but if mux with mp4 instead of mkv, the output is correctly 2:00.
I can upload the clip if needed.

How to reproduce:
PS D:\rigaya hwenc> .\ffmpeg.exe -y -v verbose -strict 2 -hwaccel vulkan -i .\tmp2.mkv -filter_complex "[0:v][0:s]overlay[v]" -map "[v]" -map 0:a -b:v 0 -maxrate:v 16777216 -bufsize:v 67108864 -bf 5 -qmin 1 -qmax 51 -qdiff 5 -g 240 -c:v hevc_nvenc -preset p7 -profile:v main10 -tier high -rc:v vbr -cq 26 -rc-lookahead 32 -b_ref_mode each -multipass fullres -2pass true -spatial-aq true -temporal-aq true -nonref_p true -tune hq -init_qpI 26 -init_qpP 26 -init_qpB 26 -b_adapt true -c:a libopus -b:a 128k -ac 2 -pix_fmt p010le -color_primaries bt709 -color_trc bt709 -colorspace bt709 -color_range tv -tag:v? hvc1 -movflags +faststart -sn -map_metadata -1 -map_chapters -1 -metadata:s:v:0 language=chi -metadata:s:a:0 language=jpn -report test2.mkv
ffmpeg started on 2022-08-14 at 20:45:33
Report written to "ffmpeg-20220814-204533.log"
Log level: 48
ffmpeg version N-107780-g6ded80af92-20220813 Copyright (c) 2000-2022 the FFmpeg developers

built with gcc 12.1.0 (crosstool-NG 1.25.0.55_3defb7b)
configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-shared --disable-static --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --disable-libpulse --enable-libvmaf --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libass --enable-libbluray --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librist --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --disable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20220813
libavutil 57. 33.100 / 57. 33.100
libavcodec 59. 42.101 / 59. 42.101
libavformat 59. 30.100 / 59. 30.100
libavdevice 59. 8.101 / 59. 8.101
libavfilter 8. 46.101 / 8. 46.101
libswscale 6. 8.102 / 6. 8.102
libswresample 4. 8.100 / 4. 8.100
libpostproc 56. 7.100 / 56. 7.100

Routing option strict to both codec and muxer layer
[matroska,webm @ 0000021ce8ebc080] max_analyze_duration 5000000 reached at 5005000 microseconds st:0
[matroska,webm @ 0000021ce8ebc080] Could not find codec parameters for stream 2 (Subtitle: hdmv_pgs_subtitle (pgssub)): unspecified size
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, matroska,webm, from '.\tmp2.mkv':

Metadata:

ENCODER : Lavf59.27.100

Duration: 00:02:00.16, start: 0.000000, bitrate: 18004 kb/s
Stream #0:0: Video: hevc (Main 10), 1 reference frame, yuv420p10le(tv, bt709, left), 1920x1080, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn (default)

Metadata:

DURATION : 00:02:00.161000000

Stream #0:1: Audio: flac, 48000 Hz, 7.1, s32 (24 bit) (default)

Metadata:

DURATION : 00:02:00.063000000

Stream #0:2: Subtitle: hdmv_pgs_subtitle

Metadata:

DURATION : 00:01:56.366000000

Codec AVOption b_adapt (When lookahead is enabled, set this to 0 to disable adaptive B-frame decision) specified for output file #0 (test2.mkv) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
[AVHWDeviceContext @ 0000021ceac9d280] Supported validation layers:
[AVHWDeviceContext @ 0000021ceac9d280] VK_LAYER_NV_optimus
[AVHWDeviceContext @ 0000021ceac9d280] VK_LAYER_AMD_switchable_graphics
[AVHWDeviceContext @ 0000021ceac9d280] VK_LAYER_OBS_HOOK
[AVHWDeviceContext @ 0000021ceac9d280] VK_LAYER_VALVE_steam_overlay
[AVHWDeviceContext @ 0000021ceac9d280] VK_LAYER_VALVE_steam_fossilize
[AVHWDeviceContext @ 0000021ceac9d280] GPU listing:
[AVHWDeviceContext @ 0000021ceac9d280] 0: AMD Radeon(TM) Graphics (integrated) (0x1638)
[AVHWDeviceContext @ 0000021ceac9d280] 1: NVIDIA GeForce RTX 3050 Ti Laptop GPU (discrete) (0x25a0)
[AVHWDeviceContext @ 0000021ceac9d280] Device 0 selected: AMD Radeon(TM) Graphics (integrated) (0x1638)
[AVHWDeviceContext @ 0000021ceac9d280] Queue families:
[AVHWDeviceContext @ 0000021ceac9d280] 0: graphics compute transfer sparse (queues: 1)
[AVHWDeviceContext @ 0000021ceac9d280] 1: compute transfer sparse (queues: 2)
[AVHWDeviceContext @ 0000021ceac9d280] 2: transfer sparse (queues: 1)
[AVHWDeviceContext @ 0000021ceac9d280] Using device extension VK_KHR_sampler_ycbcr_conversion
[AVHWDeviceContext @ 0000021ceac9d280] Using device extension VK_KHR_synchronization2
[AVHWDeviceContext @ 0000021ceac9d280] Using device extension VK_EXT_external_memory_host
[AVHWDeviceContext @ 0000021ceac9d280] Using device extension VK_KHR_external_memory_win32
[AVHWDeviceContext @ 0000021ceac9d280] Using device extension VK_KHR_external_semaphore_win32
[AVHWDeviceContext @ 0000021ceac9d280] Using device: AMD Radeon(TM) Graphics
[AVHWDeviceContext @ 0000021ceac9d280] Alignments:
[AVHWDeviceContext @ 0000021ceac9d280] optimalBufferCopyRowPitchAlignment: 1
[AVHWDeviceContext @ 0000021ceac9d280] minMemoryMapAlignment: 64
[AVHWDeviceContext @ 0000021ceac9d280] minImportedHostPointerAlignment: 4096
[AVHWDeviceContext @ 0000021ceac9d280] Using queue family 0 (queues: 1) for graphics
[AVHWDeviceContext @ 0000021ceac9d280] Using queue family 2 (queues: 1) for transfers
[AVHWDeviceContext @ 0000021ceac9d280] Using queue family 1 (queues: 2) for compute
Stream mapping:

Stream #0:0 (hevc) -> overlay (graph 0)
Stream #0:2 (pgssub) -> overlay (graph 0)
overlay:default (graph 0) -> Stream #0:0 (hevc_nvenc)
Stream #0:1 -> #0:1 (flac (native) -> opus (libopus))

Press [q] to stop, ? for help
[graph 0 input from stream 0:0 @ 0000021cf64d8500] w:1920 h:1080 pixfmt:yuv420p10le tb:1/1000 fr:24000/1001 sar:1/1
[matroska,webm @ 0000021ce8ebc080] sub2video: using 1920x1080 canvas
[graph 0 input from stream 0:2 @ 0000021cf64d6f00] w:1920 h:1080 pixfmt:bgra tb:1/1000 fr:0/1 sar:0/1
[auto_scale_0 @ 0000021cf64d8900] w:iw h:ih flags: interl:0
[Parsed_overlay_0 @ 0000021cf64d6e00] auto-inserting filter 'auto_scale_0' between the filter 'graph 0 input from stream 0:0' and the filter 'Parsed_overlay_0'
[auto_scale_1 @ 0000021cf64d7700] w:iw h:ih flags:
interl:0
[Parsed_overlay_0 @ 0000021cf64d6e00] auto-inserting filter 'auto_scale_1' between the filter 'graph 0 input from stream 0:2' and the filter 'Parsed_overlay_0'
[auto_scale_2 @ 0000021cf64d7100] w:iw h:ih flags: interl:0
[format @ 0000021cf64d8700] auto-inserting filter 'auto_scale_2' between the filter 'Parsed_overlay_0' and the filter 'format'
[auto_scale_0 @ 0000021cf64d8900] w:1920 h:1080 fmt:yuv420p10le sar:1/1 -> w:1920 h:1080 fmt:yuva420p sar:1/1 flags:0x0
[auto_scale_1 @ 0000021cf64d7700] w:1920 h:1080 fmt:bgra sar:0/1 -> w:1920 h:1080 fmt:yuva420p sar:0/1 flags:0x0
[Parsed_overlay_0 @ 0000021cf64d6e00] main w:1920 h:1080 fmt:yuva420p overlay w:1920 h:1080 fmt:yuva420p
[Parsed_overlay_0 @ 0000021cf64d6e00] [framesync @ 0000021cfcc26028] Selected 1/1000 time base
[Parsed_overlay_0 @ 0000021cf64d6e00] [framesync @ 0000021cfcc26028] Sync level 2
[auto_scale_2 @ 0000021cf64d7100] w:1920 h:1080 fmt:yuva420p sar:1/1 -> w:1920 h:1080 fmt:p010le sar:1/1 flags:0x0
[auto_scale_0 @ 0000021cf64d8900] w:1920 h:1080 fmt:yuv420p10le sar:1/1 -> w:1920 h:1080 fmt:yuva420p sar:1/1 flags:0x0

Last message repeated 2 times

[auto_scale_2 @ 0000021cf64d7100] w:1920 h:1080 fmt:yuva420p sar:1/1 -> w:1920 h:1080 fmt:p010le sar:1/1 flags:0x0

Last message repeated 2 times

[hevc_nvenc @ 0000021cea9ff3c0] Loaded Nvenc version 11.1
[hevc_nvenc @ 0000021cea9ff3c0] Nvenc initialized successfully
[hevc_nvenc @ 0000021cea9ff3c0] 1 CUDA capable devices found
[hevc_nvenc @ 0000021cea9ff3c0] [ GPU #0 - < NVIDIA GeForce RTX 3050 Ti Laptop GPU > has Compute SM 8.6 ]
[hevc_nvenc @ 0000021cea9ff3c0] supports NVENC
[hevc_nvenc @ 0000021cea9ff3c0] AQ enabled.
[hevc_nvenc @ 0000021cea9ff3c0] Temporal AQ enabled.
[hevc_nvenc @ 0000021cea9ff3c0] Lookahead enabled: depth 32, scenecut enabled, B-adapt disabled.
[hevc_nvenc @ 0000021cea9ff3c0] CQ(6656) mode enabled.
[graph_1_in_0_1 @ 0000021cfcf80e80] tb:1/48000 samplefmt:s32 samplerate:48000 chlayout:7.1
[format_out_0_1 @ 0000021cfcf83880] auto-inserting filter 'auto_aresample_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_1'
[auto_aresample_0 @ 0000021cfcf82f80] ch:8 chl:7.1 fmt:s32 r:48000Hz -> ch:2 chl:stereo fmt:flt r:48000Hz
Output #0, matroska, to 'test2.mkv':

Metadata:

encoder : Lavf59.30.100

Stream #0:0(chi): Video: hevc (Main 10), 1 reference frame (hvc1 / 0x31637668), p010le(tv, bt709, progressive, left), 1920x1080 (0x0) [SAR 1:1 DAR 16:9], q=2-31, 23.98 fps, 1k tbn

Metadata:

encoder : Lavc59.42.101 hevc_nvenc

Side data:

cpb: bitrate max/min/avg: 16777216/0/0 buffer size: 67108864 vbv_delay: N/A

Stream #0:1(jpn): Audio: opus ([255][255][255][255] / 0xFFFFFFFF), 48000 Hz, stereo, flt, delay 312, 128 kb/s (default)

Metadata:

encoder : Lavc59.42.101 libopus

[Parsed_overlay_0 @ 0000021cf64d6e00] [framesync @ 0000021cfcc26028] Sync level 1 speed=5.32x
[Parsed_overlay_0 @ 0000021cf64d6e00] [framesync @ 0000021cfcc26028] Sync level 0
No more output streams to write to, finishing.
[matroska @ 0000021cea9f4b80] Starting new cluster due to timestamp
[matroska @ 0000021cea9f4b80] Invalid DTS: 4295083459 PTS: 120120 in output stream 0:0, replacing by guess
[matroska @ 0000021cea9f4b80] Starting new cluster due to timestamp
All streams finished for output file #0
Terminating muxer thread 0
[AVIOContext @ 0000021ce8eb7840] Statistics: 47962442 bytes written, 2 seeks, 184 writeouts
frame= 2881 fps=126 q=21.0 Lsize= 46838kB time=1193:04:43.45 bitrate= 0.1kbits/s speed=1.88e+05x
video:44701kB audio:2073kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.135937%
Input file #0 (.\tmp2.mkv):

Input stream #0:0 (video): 2880 packets read (224052238 bytes); 2880 frames decoded;
Input stream #0:1 (audio): 1407 packets read (46076940 bytes); 1407 frames decoded (5763072 samples);
Input stream #0:2 (subtitle): 21 packets read (255647 bytes); 11 frames decoded;
Total: 4308 packets (270384825 bytes) demuxed

Output file #0 (test2.mkv):

Output stream #0:0 (video): 2881 frames encoded; 2881 packets muxed (45773980 bytes);
Output stream #0:1 (audio): 6004 frames encoded (5763072 samples); 6004 packets muxed (2122519 bytes);
Total: 8885 packets (47896499 bytes) muxed

[hevc_nvenc @ 0000021cea9ff3c0] Nvenc unloaded
[AVIOContext @ 0000021cea9f5040] Statistics: 270423630 bytes read, 0 seeks

Change History (2)

comment:1 by mkver, 6 months ago

Your duration is basically UINT32_MAX when using a 1ms timebase (as the Matroska muxer does). The subtitle duration field is a 32 bit integer and UINT32_MAX actually means "unknown"; PGS subtitles typically have an unknown duration (they are cancelled/overwritten by a later packet). So it seems that some part of the code does not treat this special value correctly.

Maybe using the -fix_sub_duration (as an input option) would help; I am not sure.

Last edited 6 months ago by mkver (previous) (diff)

in reply to:  1 comment:2 by lincutt, 6 months ago

Replying to mkver:

Your duration is basically UINT32_MAX when using a 1ms timebase (as the Matroska muxer does). The subtitle duration field is a 32 bit integer and UINT32_MAX actually means "unknown"; PGS subtitles typically have an unknown duration (they are cancelled/overwritten by a later packet). So it seems that some part of the code does not treat this special value correctly.

Maybe using the -fix_sub_duration (as an input option) would help; I am not sure.

Thanks for your suggestion, it's worked!

Note: See TracTickets for help on using tickets.