Opened 21 months ago

Last modified 21 months ago

#9852 new defect

Single TS transcoding produces incorrect results using H265 HLS

Reported by: kirill_p Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description (last modified by kirill_p)

Summary of the bug:
Given MP4 file (recorded by IPhone 13 mini) with H265 codec. Splitting it to an HLS without transcoding (codec copy), and then doing a full transcode of a single segment - TS, let's say the second segment. Then generating a new m3u8 index file, with all the original information, except that the second segment now points to a new transcoded file. The new m3u8 playback will contain errors:
FFPlay reports [mpegts @ 00000286995b9180] Packet corrupt (stream = 0, dts = 402000).
VLC stucks, shows black frame for a moment, at the beginning and the end of the second segment.

Expected: The HLS will play without interruptions. The same flow works perfectly with H264 codec.

How to reproduce:
Generating HLS:

% ffmpeg -i original.mp4 -c:v copy -an -bsf:v hevc_mp4toannexb -crf 18 -g 30 -sc_threshold 0 -f hls -start_number 0 -hls_time 3 -hls_list_size 0 o.m3u8
ffmpeg version n5.1-1-g6d83c5f876-20220730 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 --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=20220730
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'original.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomdby1iso2mp41
    encoder         : Lavf59.8.100
  Duration: 00:00:25.57, start: 0.000000, bitrate: 8740 kb/s
  Stream #0:0[0x1](und): Video: hevc (Main 10) (hvc1 / 0x31637668), yuv420p10le(tv, bt2020nc/bt2020/arib-std-b67), 1920x1080, 8565 kb/s, SAR 1:1 DAR 16:9, 30 fps, 30 tbr, 19200 tbn (default)
    Metadata:
      handler_name    : Core Media Video
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 166 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
      vendor_id       : [0][0][0][0]
Output #0, hls, to 'o.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomdby1iso2mp41
    encoder         : Lavf59.27.100
  Stream #0:0(und): Video: hevc (Main 10) (hvc1 / 0x31637668), yuv420p10le(tv, bt2020nc/bt2020/arib-std-b67), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 8565 kb/s, 30 fps, 30 tbr, 90k tbn (default)
    Metadata:
      handler_name    : Core Media Video
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[hls @ 00000264499e2740] Opening 'o0.ts' for writing6 bitrate=N/A speed=N/A
[hls @ 00000264499e2740] Opening 'o.m3u8.tmp' for writing
[hls @ 00000264499e2740] Opening 'o1.ts' for writing
[hls @ 00000264499e2740] Opening 'o.m3u8.tmp' for writing
[hls @ 00000264499e2740] Opening 'o2.ts' for writing
[hls @ 00000264499e2740] Opening 'o.m3u8.tmp' for writing
[hls @ 00000264499e2740] Opening 'o3.ts' for writing
[hls @ 00000264499e2740] Opening 'o.m3u8.tmp' for writing
[hls @ 00000264499e2740] Opening 'o4.ts' for writing
[hls @ 00000264499e2740] Opening 'o.m3u8.tmp' for writing
[hls @ 00000264499e2740] Opening 'o5.ts' for writing
[hls @ 00000264499e2740] Opening 'o.m3u8.tmp' for writing
[hls @ 00000264499e2740] Opening 'o6.ts' for writing
[hls @ 00000264499e2740] Opening 'o.m3u8.tmp' for writing
[hls @ 00000264499e2740] Opening 'o7.ts' for writing
[hls @ 00000264499e2740] Opening 'o.m3u8.tmp' for writing
[hls @ 00000264499e2740] Opening 'o8.ts' for writing
[hls @ 00000264499e2740] Opening 'o.m3u8.tmp' for writing
frame=  767 fps=0.0 q=-1.0 Lsize=N/A time=00:00:25.46 bitrate=N/A speed= 158x
video:26735kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Single TS transcode:

% ffmpeg -i o1.ts -c:v libx265 -x265-params no-open-gop=1:no-scenecut=1 -crf 18 -g 30 -preset fast -copyts -copytb 1 -muxdelay 0 o1edited.ts
ffmpeg version n5.1-1-g6d83c5f876-20220730 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 --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=20220730
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.100
Input #0, mpegts, from 'o1.ts':
  Duration: 00:00:03.10, start: 4.666667, bitrate: 9172 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
  Stream #0:0[0x100]: Video: hevc (Main 10) (HEVC / 0x43564548), yuv420p10le(tv, bt2020nc/bt2020/arib-std-b67), 1920x1080, 30 fps, 30 tbr, 90k tbn
Stream mapping:
  Stream #0:0 -> #0:0 (hevc (native) -> hevc (libx265))
Press [q] to stop, [?] for help
[hevc @ 000002ca49c93a80] Multiple Dolby Vision RPUs found in one AU. Skipping previous.
[hevc @ 000002ca49920e80] Multiple Dolby Vision RPUs found in one AU. Skipping previous.
[hevc @ 000002ca49921280] Multiple Dolby Vision RPUs found in one AU. Skipping previous.
x265 [info]: HEVC encoder version 3.5+38-20255e6f0
x265 [info]: build info [Windows][GCC 12.1.0][64 bit] 10bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main 10 profile, Level-4 (Main tier)
x265 [info]: Thread pool created using 4 threads
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 2 / wpp(17 rows)
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge         : hex / 57 / 2 / 2
x265 [info]: Lookahead / bframes / badapt        : 15 / 4 / 0
x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 0
x265 [info]: References / ref-limit  cu / depth  : 3 / on / on
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 2 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress            : CRF-18.0 / 0.60
x265 [info]: tools: rd=2 psy-rd=2.00 rskip mode=1 signhide tmvp fast-intra
x265 [info]: tools: strong-intra-smoothing lslices=6 deblock sao
Output #0, mpegts, to 'o1edited.ts':
  Metadata:
    encoder         : Lavf59.27.100
  Stream #0:0: Video: hevc, yuv420p10le(tv, bt2020nc/bt2020/arib-std-b67, progressive), 1920x1080, q=2-31, 30 fps, 90k tbn
    Metadata:
      encoder         : Lavc59.37.100 libx265
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
frame=   93 fps=7.1 q=23.8 Lsize=    3835kB time=00:00:03.03 bitrate=10358.3kbits/s speed=0.233x
video:3731kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.809286%
x265 [info]: frame I:      4, Avg QP:18.85  kb/s: 25288.08
x265 [info]: frame P:     19, Avg QP:20.14  kb/s: 21011.96
x265 [info]: frame B:     70, Avg QP:23.99  kb/s: 5915.63
x265 [info]: Weighted P-Frames: Y:31.6% UV:31.6%
x265 [info]: consecutive B-frames: 17.4% 4.3% 0.0% 13.0% 65.2%

encoded 93 frames in 12.92s (7.20 fps), 9833.05 kb/s, Avg QP:22.98

The latest FFMPEG that was used was downloaded today from https://github.com/BtbN/FFmpeg-Builds/releases (Latest Auto-Build (2022-07-30 12:38), ffmpeg-n5.1-latest-win64-gpl-5.1.zip)

As attachments limited to 2.5 MB, movie original.mp4 (27MB) could be downloaded from here: https://ufile.io/qp8p7bcy

Attachments (1)

oedited.m3u8 (310 bytes ) - added by kirill_p 21 months ago.
Modified index file (m3u8)

Download all attachments as: .zip

Change History (4)

by kirill_p, 21 months ago

Attachment: oedited.m3u8 added

Modified index file (m3u8)

comment:1 by kirill_p, 21 months ago

Description: modified (diff)

comment:2 by Balling, 21 months ago

Why -copyts?

comment:3 by kirill_p, 21 months ago

Without -copyts the start time of transcoded second chunk is not equal to the original. The original has pts_time=4.666667. And without copyts the new have 0.066667

Tried with copyts and without, same for copytb. Couldn't produce the expected result.

Note: See TracTickets for help on using tickets.