InfinityLoop1308 / PipePipe

A FLOSS Android app to let you browse YouTube, NicoNico and BiliBili freely.
GNU General Public License v3.0
1.9k stars 40 forks source link

[BUG] Long YouTube videos don't finalize properly when using WebM #315

Open ghost opened 2 months ago

ghost commented 2 months ago

I downloaded a video at 720p/60fps that was 5 hours long (from YouTube), finished post-processing without errors, but when I tried watching it in VLC it just starts playing around the 2 hour mark but and doesn't play correctly before that time. (I also used Next Player and it doesn't even play at all.)

I used ffmpeg to remux the audio and video in a new container (no re-encoding) and that fixed it.

This doesn't happen when using MPEG-4 as the video format.

InfinityLoop1308 commented 2 months ago

I think most videos should be MPEG-4? Which video are you downloading?

ghost commented 2 months ago

I think most videos should be MPEG-4? Which video are you downloading?

The first video on DankPods - The Complete Series (video compilation). This issue doesn't seem to exist in NewPipe iirc as it downloads the same video fine (although I haven't used NewPipe in a while since it doesn't load baners/icons) and yt-dlp says WebM does exist in the resolution I chose.

I prefer WebM to MPEG-4 because it is a smaller size (faster downloads w/ decent quality) and my player supports it.

InfinityLoop1308 commented 1 month ago

I think the problem is actually caused by the YouTube's new block, like many other issues such as #316. The new version will soon be released and you can check if the issue persists.

ghost commented 1 month ago

I apologize, but I re-downloaded the same video under the new version, and the issue still exists. I will use ffmpeg and a hex editor to analyze it.

edit: here's what I discerned from ffmpeg and ffprobe:

.../0/Documents $ ffprobe -v error -show_format -show_streams corrupted.webm
[matroska,webm @ 0xb4000079b39bd280] Element at 0xe9e4 ending at 0xe9fb exceeds containing master element ending at 0xe9f0
[matroska,webm @ 0xb4000079b39bd280] Duplicate element
[matroska,webm @ 0xb4000079b39bd280] Element at 0x13ed ending at 0x1402 exceeds containing master element ending at 0x13f4
[matroska,webm @ 0xb4000079b39bd280] Duplicate element
[matroska,webm @ 0xb4000079b39bd280] Element at 0x56 ending at 0x16a6 exceeds containing master element ending at 0x1402
[matroska,webm @ 0xb4000079b39bd280] 0x00 at pos 101 (0x65) invalid as first byte of an EBML number
[matroska,webm @ 0xb4000079b39bd280] Length 8 indicated by an EBML number's first byte 0x01 at pos 59888 (0xe9f0) exceeds max length 4.
[STREAM]
index=0
codec_name=vp9
codec_long_name=Google VP9
profile=Profile 0
codec_type=video
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=1280
height=720
coded_width=1280
coded_height=720
closed_captions=0
film_grain=0
has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=-99
color_range=tv
color_space=bt709
color_transfer=bt709
color_primaries=bt709
chroma_location=unspecified
field_order=unknown
refs=1
id=N/A
r_frame_rate=60/1
avg_frame_rate=60/1
time_base=1/1000
start_pts=3383
start_time=3.383000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
DISPOSITION:non_diegetic=0
DISPOSITION:captions=0
DISPOSITION:descriptions=0
DISPOSITION:metadata=0
DISPOSITION:dependent=0
DISPOSITION:still_image=0
[/STREAM]
[STREAM]
index=1
codec_name=opus
codec_long_name=Opus (Opus Interactive Audio Codec)
profile=unknown
codec_type=audio
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=fltp
sample_rate=48000
channels=2
channel_layout=stereo
bits_per_sample=0
initial_padding=312
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=3474
start_time=3.474000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
extradata_size=19
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
DISPOSITION:non_diegetic=0
DISPOSITION:captions=0
DISPOSITION:descriptions=0
DISPOSITION:metadata=0
DISPOSITION:dependent=0
DISPOSITION:still_image=0
[/STREAM]
[FORMAT]
filename=corrupted.webm
nb_streams=2
nb_programs=0
format_name=matroska,webm
format_long_name=Matroska / WebM
start_time=3.383000
duration=N/A
size=4289294222
bit_rate=N/A
probe_score=100
[/FORMAT]

I remuxed it into a new container:

.../0/Documents $ ffmpeg -i corrupted.webm -c copy output.webm
ffmpeg version 6.1.1 Copyright (c) 2000-2023 the FFmpeg developers
  built with Android (10552028, +pgo, +bolt, +lto, -mlgo, based on r487747d) clang version 17.0.2 (https://android.googlesource.com/toolchain/llvm-project d9f89f4d16663d5012e5c09495f3b30ece3d2362)
  configuration: --arch=aarch64 --as=aarch64-linux-android-clang --cc=aarch64-linux-android-clang --cxx=aarch64-linux-android-clang++ --nm=llvm-nm --pkg-config=/home/builder/.termux-build/_cache/android-r26b-api-24-v3/bin/pkg-config --strip=llvm-strip --cross-prefix=aarch64-linux-android- --disable-indevs --disable-outdevs --enable-indev=lavfi --disable-static --disable-symver --enable-cross-compile --enable-gnutls --enable-gpl --enable-version3 --enable-jni --enable-lcms2 --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libharfbuzz --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenmpt --enable-libopus --enable-librav1e --enable-libsoxr --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-mediacodec --enable-opencl --enable-shared --prefix=/data/data/com.termux/files/usr --target-os=android --extra-libs=-landroid-glob --disable-vulkan --enable-neon --disable-libfdk-aac
  libavutil      58. 29.100 / 58. 29.100
  libavcodec     60. 31.102 / 60. 31.102
  libavformat    60. 16.100 / 60. 16.100
  libavdevice    60.  3.100 / 60.  3.100
  libavfilter     9. 12.100 /  9. 12.100
  libswscale      7.  5.100 /  7.  5.100
  libswresample   4. 12.100 /  4. 12.100
  libpostproc    57.  3.100 / 57.  3.100
[matroska,webm @ 0xb40000793ad83280] Element at 0xe9e4 ending at 0xe9fb exceeds containing master element ending at 0xe9f0
[matroska,webm @ 0xb40000793ad83280] Duplicate element
[matroska,webm @ 0xb40000793ad83280] Element at 0x13ed ending at 0x1402 exceeds containing master element ending at 0x13f4
[matroska,webm @ 0xb40000793ad83280] Duplicate element
[matroska,webm @ 0xb40000793ad83280] Element at 0x56 ending at 0x16a6 exceeds containing master element ending at 0x1402
[matroska,webm @ 0xb40000793ad83280] 0x00 at pos 101 (0x65) invalid as first byte of an EBML number
[matroska,webm @ 0xb40000793ad83280] Length 8 indicated by an EBML number's first byte 0x01 at pos 59888 (0xe9f0) exceeds max length 4.
Input #0, matroska,webm, from 'corrupted.webm':
  Duration: N/A, start: 3.383000, bitrate: N/A
  Stream #0:0: Video: vp9 (Profile 0), yuv420p(tv, bt709), 1280x720, SAR 1:1 DAR 16:9, 60 fps, 60 tbr, 1k tbn (default)
  Stream #0:1: Audio: opus, 48000 Hz, stereo, fltp (default)
Output #0, webm, to 'output.webm':
  Metadata:
    encoder         : Lavf60.16.100
  Stream #0:0: Video: vp9 (Profile 0), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 60 fps, 60 tbr, 1k tbn (default)
  Stream #0:1: Audio: opus, 48000 Hz, stereo, fltp (default)
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[out#0/webm @ 0xb40000793acfde40] video:3868924kB audio:303522kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.382225%
size= 4188394kB time=05:44:54.25 bitrate=1658.0kbits/s speed= 344x

then probed that one:

.../0/Documents $ ffprobe -v error -show_format -show_streams output.webm
[STREAM]
index=0
codec_name=vp9
codec_long_name=Google VP9
profile=Profile 0
codec_type=video
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=1280
height=720
coded_width=1280
coded_height=720
closed_captions=0
film_grain=0
has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=-99
color_range=tv
color_space=bt709
color_transfer=bt709
color_primaries=bt709
chroma_location=unspecified
field_order=unknown
refs=1
id=N/A
r_frame_rate=60/1
avg_frame_rate=60/1
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
DISPOSITION:non_diegetic=0
DISPOSITION:captions=0
DISPOSITION:descriptions=0
DISPOSITION:metadata=0
DISPOSITION:dependent=0
DISPOSITION:still_image=0
TAG:DURATION=05:44:54.250000000
[/STREAM]
[STREAM]
index=1
codec_name=opus
codec_long_name=Opus (Opus Interactive Audio Codec)
profile=unknown
codec_type=audio
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=fltp
sample_rate=48000
channels=2
channel_layout=stereo
bits_per_sample=0
initial_padding=312
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=91
start_time=0.091000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
extradata_size=19
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
DISPOSITION:non_diegetic=0
DISPOSITION:captions=0
DISPOSITION:descriptions=0
DISPOSITION:metadata=0
DISPOSITION:dependent=0
DISPOSITION:still_image=0
TAG:DURATION=05:44:54.278000000
[/STREAM]
[FORMAT]
filename=output.webm
nb_streams=2
nb_programs=0
format_name=matroska,webm
format_long_name=Matroska / WebM
start_time=0.000000
duration=20694.278000
size=4288915496
bit_rate=1658010
probe_score=100
TAG:ENCODER=Lavf60.16.100
[/FORMAT]

The remuxed one plays fine. I don't know what causes this to happen, but maybe this provides some insight.

InfinityLoop1308 commented 1 month ago

I don't know either... NewPipe's dev write long codes to mux them manually, and these codes are like a black box to me. But as we have FFMPEG already bundled maybe we can just do a remux during post-processing.