Zibbp / ganymede

Twitch VOD and Live Stream archiving platform. Includes a rendered and real-time chat for each archive.
https://github.com/Zibbp/ganymede
GNU General Public License v3.0
492 stars 25 forks source link

Recorded videos higher pitch/speed than originals #149

Closed c-hri-s closed 1 year ago

c-hri-s commented 1 year ago

I've recently set things up and have been recording some livestreams.

The recorded video which is rendered (the actual video file played in Media Player Classic or VLC) seems to be faster than the original ... at least voices are more high-pitched than they are supposed to be. Not sure if this is a framerate issue or something?

Zibbp commented 1 year ago

Hi, This is due to Twitch embedding advertisement in streams that started last November. For some reason the advertisements have a different audio sample rate that I believe causes this issue. I have not found a fix for this but also haven't looked for awhile. I would take a look at Streamlink's repo to see if there are any updates there. I know there was an open issue awhile back for this problem.

If you are subscribed to a channel (or Turbo), you can use your Twitch token to get served an ad-free stream playlist. Other than that, I would try to archive VODs as much as possible rather than livestreams that VODs are more stable and have less issues.

CappiSteijns commented 1 year ago

Hi, This is due to Twitch embedding advertisement in streams that started last November. For some reason the advertisements have a different audio sample rate that I believe causes this issue. I have not found a fix for this but also haven't looked for awhile. I would take a look at Streamlink's repo to see if there are any updates there. I know there was an open issue awhile back for this problem.

If you are subscribed to a channel (or Turbo), you can use your Twitch token to get served an ad-free stream playlist. Other than that, I would try to archive VODs as much as possible rather than livestreams that VODs are more stable and have less issues.

About the audio issue, I also mentioned something about this over HERE.

I found out there is no audio issue when the live stream is being recorded. So the file is 100% correctly in the /tmp folder. However when it is moved to the end folders the audio will be high pitched.

Please let me know if you need some extra info etc. Hope this helps a little bit.

Zibbp commented 1 year ago

After the video download is complete, an ffmpeg task is run ffmpeg -i source -c:v copy -c:a copy out.mp4 (by default). It just copies the audio/video so it shouldn't effect anything, but maybe it is?

The in-progress video in /tmp is a .ts output from Streamlink. If you run ffmpeg against the in-progress and final video, is there any audio differences (not sure what to look for).

c-hri-s commented 1 year ago

I worked around this by adding the --twitch-disable-ads switch to the streamlink config in the settings page. I can live with 'cuts' where the ads were, but the pitch thing was worse.

CappiSteijns commented 1 year ago

I worked around this by adding the --twitch-disable-ads switch to the streamlink config in the settings page. I can live with 'cuts' where the ads were, but the pitch thing was worse.

What about the chat offset? I love ganymede because it lets me see the chat playback in a nice way.

CappiSteijns commented 1 year ago

the filetype in /tmp is not .ts? It is .mp4.

image

Will try to ffmpeg the file, but it only happens to one channel so I have to wait.

Zibbp commented 1 year ago

Ya, it's a "ts" file saved as an mp4

Zibbp commented 1 year ago

I worked around this by adding the --twitch-disable-ads switch to the streamlink config in the settings page. I can live with 'cuts' where the ads were, but the pitch thing was worse.

What about the chat offset? I love ganymede because it lets me see the chat playback in a nice way.

The parameter does splice out the ads but as Cappi said, it creates an offset between the video/chat. Which is not good for an archiving application.

CappiSteijns commented 1 year ago

So I tried it out.

"Egbert" went live. During the capturing I copied the file from /tmpto my windows machine. The copied file was working just fine, no high pitch or any speed difference.

I then used the command ffmpeg -i source -c:v copy -c:a copy out.mp4on the copied file on my windows pc. And the output file was again high pitched.

So it does make changes to the file? Hope this helps a little. I have captured around 20 livestreams which are not usable. And the /tmp files which where in good condition got removed (obviously).

Zibbp commented 1 year ago

Is there a possibility you can upload the working video so I can take a look?

CappiSteijns commented 1 year ago

Is there a possibility you can upload the working video so I can take a look?

Yes, do you have a good way to share it? It's about 1gb

Zibbp commented 1 year ago

Could try https://send.vis.ee/ or https://transfer.sh/

CappiSteijns commented 1 year ago

Could try https://send.vis.ee/ or https://transfer.sh/

Here you go: https://send.vis.ee/download/cdda7ba08c26dc17/#c0BBZ3h9PeLz5-1qwg4TpA Password = Ganymede

Zibbp commented 1 year ago

Can you try these ffmpeg commands and see if anything of them work to fix the issue? It appears the audio track is not happy DTS discontinuity in stream 2: packet 3 with DTS 5940090, packet 4 with DTS 6120000. I don't really know what that means.

ffmpeg -i video.mp4 -copyts -c:a copy -c:v copy out.mp4
ffmpeg -i video.mp4 -ignore_unknown -c:a copy -c:v copy out.mp4
ffmpeg -i video.mp4 -c:v copy -bsf:a aac_adtstoasc -copyts out.mp4
CappiSteijns commented 1 year ago

Can you try these ffmpeg commands and see if anything of them work to fix the issue? It appears the audio track is not happy DTS discontinuity in stream 2: packet 3 with DTS 5940090, packet 4 with DTS 6120000. I don't really know what that means.

ffmpeg -i video.mp4 -copyts -c:a copy -c:v copy out.mp4
ffmpeg -i video.mp4 -ignore_unknown -c:a copy -c:v copy out.mp4
ffmpeg -i video.mp4 -c:v copy -bsf:a aac_adtstoasc -copyts out.mp4

The first 2 were not good. The third one however had good results! Didn't notice a difference between the original file and the output file.

This is the log of the last option:

C:\Users\CappiSteijns\Desktop\Egbert Ganymede test>ffmpeg -i 40689220952_956ccecc-e5bf-11ed-bfeb-0242ac190002-video.mp4 -ignore_unknown -c:a copy -c:v copy out.mp4
ffmpeg version 2023-04-26-git-e3143703e9-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      58.  6.100 / 58.  6.100
  libavcodec     60. 10.100 / 60. 10.100
  libavformat    60.  5.100 / 60.  5.100
  libavdevice    60.  2.100 / 60.  2.100
  libavfilter     9.  5.100 /  9.  5.100
  libswscale      7.  2.100 /  7.  2.100
  libswresample   4. 11.100 /  4. 11.100
  libpostproc    57.  2.100 / 57.  2.100
[mpegts @ 000001a828a92480] DTS discontinuity in stream 2: packet 3 with DTS 5940090, packet 4 with DTS 6120000
[mpegts @ 000001a828a92480] max resync size reached, could not find sync byte
    Last message repeated 481 times
[mpegts @ 000001a828a92480] stream 0 : no PTS found at end of file, duration not set
[mpegts @ 000001a828a92480] stream 1 : no PTS found at end of file, duration not set
Input #0, mpegts, from '40689220952_956ccecc-e5bf-11ed-bfeb-0242ac190002-video.mp4':
  Duration: N/A, start: 64.000000, bitrate: N/A
  Program 1
  Stream #0:0[0x100]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 130 kb/s
  Stream #0:1[0x101]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080, 30 fps, 30 tbr, 90k tbn
  Stream #0:2[0x102]: Data: timed_id3 (ID3  / 0x20334449)
Output #0, mp4, to 'out.mp4':
  Metadata:
    encoder         : Lavf60.5.100
  Stream #0:0: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080, q=2-31, 30 fps, 30 tbr, 90k tbn
  Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 130 kb/s
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mpegts @ 000001a828a92480] Packet corrupt (stream = 1, dts = 6753060).-0.0kbits/s speed=N/A
[in#0/mpegts @ 000001a828aa7680] corrupt input packet in stream 1
timestamp discontinuity for stream #0:0 (id=256, type=audio): 28844789, new offset= -28844789
[mpegts @ 000001a828a92480] max resync size reached, could not find sync bytebits/s speed= 806x
    Last message repeated 250 times
[out#0/mp4 @ 000001a828af83c0] video:910753kB audio:24777kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.235792%
frame=74403 fps=12509 q=-1.0 Lsize=  937737kB time=00:20:45.62 bitrate=6167.2kbits/s speed= 209x
Zibbp commented 1 year ago

That's good news. I wonder if it's the specific audio codec fixit it, or just re-encoding the audio. You can test that by running this ffmpeg command. Does this also sound high pitched?

ffmpeg -i video.mp4 -c:v copy -c:a aac out.mp4
CappiSteijns commented 1 year ago

That's good news. I wonder if it's the specific audio codec fixit it, or just re-encoding the audio. You can test that by running this ffmpeg command. Does this also sound high pitched?

ffmpeg -i video.mp4 -c:v copy -c:a aac out.mp4

Tested, file sounds good, not high pitched.

Zibbp commented 1 year ago

Huh, nice. Well you can add this your ffmpeg settings in Admin > Settings and replace the -c:a copy with -c:a aac. Then it can be tested with a real stream.

CappiSteijns commented 1 year ago

Huh, nice. Well you can add this your ffmpeg settings in Admin > Settings and replace the -c:a copy with -c:a aac. Then it can be tested with a real stream.

Changed the settings, have to wait till he goes live. Will keep you updated!

CappiSteijns commented 1 year ago

Guess I know the answer, but any chance the older Vods can be fixed using some ffmpeg magic or should I just let it rest?

Zibbp commented 1 year ago

Unsure, you can try running the ffmpeg command on one.

CappiSteijns commented 1 year ago

Huh, nice. Well you can add this your ffmpeg settings in Admin > Settings and replace the -c:a copy with -c:a aac. Then it can be tested with a real stream.

It worked! Will keep these settings :)

As for the older vods it didn't work, but can't have everything :)

Thank you :D

Zibbp commented 1 year ago

Glad we found a fix. I'll point others to this solution.

b1nary-b0b commented 3 days ago

This issue bugged me on and off for over a year now. Finally got time to fix it and landed here. Had exactly the same symptoms in the most recent versions and also versions before. Thanks a ton, "replace the -c:a copy with -c:a aac" fixed it for me ! :)