jmbannon / ytdl-sub

Lightweight tool to automate downloading and metadata generation with yt-dlp
https://ytdl-sub.readthedocs.io
GNU General Public License v3.0
1.84k stars 71 forks source link

SponsorBlock for non-MP4 Videos #438

Closed wjbridge closed 1 year ago

wjbridge commented 1 year ago

So I was doing some research, and I saw this issue https://github.com/jmbannon/ytdl-sub/issues/272 in the list. I am trying to remove Sponsorblock categories in the videos but if the video is not MP4 the conversion fails using yt-dlp. The FFMPEG post-processing does not work because this happens after the video is downloaded by yt-dlp.

After some research, I found this related issue, https://github.com/yt-dlp/yt-dlp/issues/871. Seems that the FFMPEG version matters when converting non-MP4 videos. The FFMPEG version needs to be at least 5.1 rather than 5.0.

I did some testing modifying the docker file to see if this fixes the issue and I was able to get the Sponsorblock remove categories working! I am not an expert on this related stuff but I thought I share my findings so maybe the proper modifications could make it into a release. Please forgive any Dockerfile proper format rules...I was just testing it out. I had to upgrade the baseimage-alpine and install a release candidate FFMPEG version 5.1.2-r7.

config.yaml

ytdl_options:
   format: "((bv*[fps>30]/bv*)[height<=2160]/(wv*[fps>30]/wv*)) + ba / (b[fps>30]/b)[height<=2160]/(w[fps>30]/w)"

sponsorblock:
  # If you download using cron, it is wise to add a delay before downloading ad-filled content to
  # give folks time to submit sponsor segments. Uncomment to wait 2 days before download a video.
  # date_range:
  #  before: "today-2days"

  chapters:
    # Embedded Chapter Fields
    embed_chapters: True
    # Remove all of these sponsorblock categories
    sponsorblock_categories:
      - "outro"
      - "selfpromo"
      - "preview"
      - "interaction"
      - "sponsor"
      - "music_offtopic"
      - "intro"
    remove_sponsorblock_categories:
      - "sponsor"
      - "selfpromo"
      - "outro"
    force_key_frames: False

Dockerfile

FROM ghcr.io/linuxserver/baseimage-alpine:3.17

###############################################################################
# YTDL-SUB INSTALL

COPY root/ /
RUN apk update --no-cache && apk upgrade --no-cache
RUN apk add --repository=http://dl-3.alpinelinux.org/alpine/edge/main/ \
      vim \
      g++ \
      nano \
      git \
      make \
      python3=~3.10 \
      py3-pip \
      py3-setuptools
RUN apk add --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community \
      ffmpeg=5.1.2-r7
RUN mkdir -p /config && \
    # Ensure ffmpeg is installed property
    ffmpeg -version
    # Install ytdl-sub, ensure it is installed propertly
RUN pip install --no-cache-dir git+https://github.com/jmbannon/ytdl-sub.git && \
    ytdl-sub -h && \
    # Delete unneeded packages after install
    apk del \
      g++ \
      make \
      py3-setuptools

###############################################################################
# CONTAINER CONFIGS

ENV EDITOR="nano" \
HOME="/config"

VOLUME /config

Log Output:

[ytdl-sub:yt-dlp] [Merger] Merging formats into "/tmp/ytdl-sub-downloads/jayz_two_cents/zc1NYwMCpTo.webm"
[ytdl-sub:yt-dlp] Deleting original file /tmp/ytdl-sub-downloads/jayz_two_cents/zc1NYwMCpTo.f313.webm (pass -k to keep)
[ytdl-sub:yt-dlp] Deleting original file /tmp/ytdl-sub-downloads/jayz_two_cents/zc1NYwMCpTo.f251.webm (pass -k to keep)
[ytdl-sub:yt-dlp] [VideoRemuxer] Remuxing video from webm to mkv; Destination: /tmp/ytdl-sub-downloads/jayz_two_cents/zc1NYwMCpTo.mkv
[ytdl-sub:yt-dlp] Deleting original file /tmp/ytdl-sub-downloads/jayz_two_cents/zc1NYwMCpTo.webm (pass -k to keep)
[ytdl-sub:yt-dlp] [EmbedSubtitle] There aren't any subtitles to embed
[ytdl-sub:yt-dlp] [Metadata] Adding metadata to "/tmp/ytdl-sub-downloads/jayz_two_cents/zc1NYwMCpTo.mkv"
[ytdl-sub:yt-dlp] [ModifyChapters] Removing chapters from /tmp/ytdl-sub-downloads/jayz_two_cents/zc1NYwMCpTo.mkv
[ytdl-sub:yt-dlp] Deleting original file /tmp/ytdl-sub-downloads/jayz_two_cents/zc1NYwMCpTo.uncut.mkv (pass -k to keep)
[ytdl-sub:yt-dlp] [Metadata] Adding metadata to "/tmp/ytdl-sub-downloads/jayz_two_cents/zc1NYwMCpTo.mkv"
[ytdl-sub:subtitles] subtitles not found for Intel just hit NVIDIA where it hurts
jmbannon commented 1 year ago

This is great stuff @wjbridge ! I will definitely add this. Last time a messed with upgrading ffmpeg, 5.1 wasn't available on Alpine. Glad to see that has changed :)

wjbridge commented 1 year ago

Also, yt-dlp might need phantomjs. This segment will install this in the container if you want to include it

RUN apk add --no-cache fontconfig && \
   mkdir -p /usr/share && \
   cd /usr/share \
   && curl -L https://github.com/Overbryd/docker-phantomjs-alpine/releases/download/2.11/phantomjs-alpine-x86_64.tar.bz2 | tar xj \
    && ln -s /usr/share/phantomjs/phantomjs /usr/bin/phantomjs \
   && phantomjs --version
jmbannon commented 1 year ago

Haven't forgot about this, will be the next thing I add. Hopefully this weekend

Shabbypenguin commented 1 year ago

Is there any guide information on how to use sponsorblock?

jmbannon commented 1 year ago

@Shabbypenguin https://ytdl-sub.readthedocs.io/en/latest/config.html#chapters