lay295 / TwitchDownloader

Twitch VOD/Clip Downloader - Chat Download/Render/Replay
MIT License
2.52k stars 260 forks source link

Chapters not adjusted to output when Trim is applied #1003

Closed superbonaci closed 3 months ago

superbonaci commented 3 months ago

Checklist

Edition

Unsure

Describe your issue here

This is metadata.txt for the entire ID:

;FFMETADATA1
title=🐳 Finishing Bread & Fred with @limealicious | !newvid !supps (2065608792)
artist=bao
date=2024
comment=Originally aired: 2024-02-17 18:05:48Z\
Video id: 2065608792\
Views: 48996
[CHAPTER]
TIMEBASE=1/1000
START=0
END=2333000
title=Just Chatting
[CHAPTER]
TIMEBASE=1/1000
START=2333000
END=8125000
title=Bread & Fred
[CHAPTER]
TIMEBASE=1/1000
START=8125000
END=9114000
title=Just Chatting
[CHAPTER]
TIMEBASE=1/1000
START=9114000
END=24980000
title=Palworld

This is how it looks like by current commit 79eab7f when downloading part of the ID:

TwitchDownloaderCLI videodownload -q 480p -o clip.mp4 -u 2065608792 -b 8025 -e 9114
;FFMETADATA1
title=🐳 Finishing Bread & Fred with @limealicious | !newvid !supps (2065608792)
artist=bao
date=2024
comment=Originally aired: 2024-02-17 18:05:48Z\
Video id: 2065608792\
Views: 49011
[CHAPTER]
TIMEBASE=1/1000
START=-8025000
END=16955000
title=Just Chatting

This is how the trimmed metadata should look like:

;FFMETADATA1
title=🐳 Finishing Bread & Fred with @limealicious | !newvid !supps (2065608792)
artist=bao
date=2024
comment=Originally aired: 2024-02-17 18:05:48Z\
Video id: 2065608792\
Views: 48996
[CHAPTER]
TIMEBASE=1/1000
START=0
END=100000
title=Bread & Fred
[CHAPTER]
TIMEBASE=1/1000
START=100000
END=1089000
title=Just Chatting

All chapters that fall within the output timestamp must be included and their START and END shifted and trimmed accordingly.

Add any related files or extra information here

No response

ScrubN commented 3 months ago

Chapters are working perfectly fine image

superbonaci commented 3 months ago

You have to add upper clamp to chapters offset as well:

This is what looks like 8de54ef:

$ ffprobe -hide_banner -i clip.mp4 
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'clip.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           :  Finishing Bread & Fred with @limealicious | !newvid !supps (2065608792)
    artist          : bao
    date            : 2024
    encoder         : Lavf60.16.100
    comment         : Originally aired: 2024-02-17 18:05:48Z
                    : Video id: 2065608792
                    : Views: 49014
  Duration: 00:18:09.00, start: 0.000000, bitrate: 1258 kb/s
  Chapters:
    Chapter #0:0: start 0.000000, end 100.000000
      Metadata:
        title           : Bread & Fred
    Chapter #0:1: start 100.000000, end 1089.000000
      Metadata:
        title           : Just Chatting
    Chapter #0:2: start 1089.000000, end 1089.000333
      Metadata:
        title           : Palworld
  Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 852x480 [SAR 1:1 DAR 71:40], 1197 kb/s, 30 fps, 30 tbr, 90k tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 53 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
  Stream #0:2[0x3](eng): Data: bin_data (text / 0x74786574)
    Metadata:
      handler_name    : SubtitleHandler
Unsupported codec with id 98314 for input stream 2

This is what it should look like:

$ ffprobe -hide_banner -i clip.mp4 
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'clip.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           :  Finishing Bread & Fred with @limealicious | !newvid !supps (2065608792)
    artist          : bao
    date            : 2024
    encoder         : Lavf60.16.100
    comment         : Originally aired: 2024-02-17 18:05:48Z
                    : Video id: 2065608792
                    : Views: 49014
  Duration: 00:18:09.00, start: 0.000000, bitrate: 1258 kb/s
  Chapters:
    Chapter #0:0: start 0.000000, end 100.000000
      Metadata:
        title           : Bread & Fred
    Chapter #0:1: start 100.000000, end 1089.000000
      Metadata:
        title           : Just Chatting
  Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 852x480 [SAR 1:1 DAR 71:40], 1197 kb/s, 30 fps, 30 tbr, 90k tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 53 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
  Stream #0:2[0x3](eng): Data: bin_data (text / 0x74786574)
    Metadata:
      handler_name    : SubtitleHandler
Unsupported codec with id 98314 for input stream 2
ScrubN commented 3 months ago

I would argue this is technically not our problem, but its fixed anyways.

superbonaci commented 3 months ago

It's not properly fixed because adds chapters with negative time.

ScrubN commented 3 months ago

FFmpeg discards the negative chapters.

superbonaci commented 3 months ago

But not the positive, at least the last time I tried.