lay295 / TwitchDownloader

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

ChatRender Fails with Broken Socket #753

Open gamedazed opened 1 year ago

gamedazed commented 1 year ago

Checklist

Edition

Command Line Interface

Describe your issue here

The chatrender command fails in Ubuntu 20.04, but works in WIndows (CLI version using the same command). The JSON being used as input was created with the emotes embedded in the file and was produced with the same instance of TwitchDownloaderCLI. The stacktrace looks like it's complaining about the options I used, but I'm pretty sure the issue is something related to the way ffmpeg was built on Ubuntu (admittedly, my own doing).

Ubuntu 20.04 (Focal)

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.6 LTS"

Latest TwitchDownloaderCLI

TwitchDownloaderCLI 1.53.0

ffmpeg built for hardware encoding

ffmpeg version N-111283-g9b6d191a66 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
configuration: --enable-openssl --enable-nonfree --enable-cuda-nvcc --enable-libnpp --disable-shared --extra-cflags=-I/usr/local/include --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
libavutil      58. 13.101 / 58. 13.101
libavcodec     60. 21.100 / 60. 21.100
libavformat    60.  9.100 / 60.  9.100
libavdevice    60.  2.100 / 60.  2.100
libavfilter     9.  8.102 /  9.  8.102
libswscale      7.  3.100 /  7.  3.100
libswresample   4. 11.100 /  4. 11.100

Consider the following command:

TwitchDownloaderCLI chatrender -i /path/to/source/'stream_chat.json'  --outline --font-size 17 --skip-drive-waiting -h 1080 -w 422  --output /path/to/destination/'stream_chat.mp4'
2023-07-03T00:55:25.536-0500    warning
[STATUS] - Fetching Images [1/2]
[STATUS] - Rendering Video: 0% [2/2]Unhandled exception. System.AggregateException: One or more errors occurred. (Broken pipe)
 ---> System.IO.IOException: Broken pipe
 ---> System.Net.Sockets.SocketException (32): Broken pipe
   at System.IO.Pipes.PipeStream.WriteCore(ReadOnlySpan`1 )
   --- End of inner exception stack trace ---
   at System.IO.Pipes.PipeStream.WriteCore(ReadOnlySpan`1 )
   at System.IO.Pipes.PipeStream.Write(Byte[] , Int32 , Int32 )
   at System.IO.BinaryWriter.Write(Byte[] )
   at TwitchDownloaderCore.ChatRenderer.RenderVideoSection(Int32 startTick, Int32 endTick, FfmpegProcess ffmpegProcess, FfmpegProcess maskProcess, CancellationToken cancellationToken)
   at TwitchDownloaderCore.ChatRenderer.<>c__DisplayClass26_0.<RenderVideoAsync>b__1()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object )
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread , ExecutionContext , ContextCallback , Object )
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread , ExecutionContext , ContextCallback , Object )
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& , Thread )
--- End of stack trace from previous location ---
   at TwitchDownloaderCore.ChatRenderer.RenderVideoAsync(CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean )
   at System.Threading.Tasks.Task.Wait(Int32 , CancellationToken )
   at System.Threading.Tasks.Task.Wait()
   at TwitchDownloaderCLI.Modes.RenderChat.Render(ChatRenderArgs inputOptions)
   at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
   at TwitchDownloaderCLI.Program.Main(String[] args)
Aborted

Passing the same command to Windows works great using the same JSON as input and the same destination as the output.

Now here's a point of isolation to consider. Passing the --fmpeg-path option to the Ubuntu side command and referencing the ffmpeg instance in Windows actually works (albeit slower). Here's the ffmpeg build used in Windows:

ffmpeg version n4.4.2-2-g7ffb7d4b04-20220806 Copyright (c) 2000-2021 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 --disable-frei0r --enable-libgme --enable-libass --enable-libbluray --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 --disable-vulkan --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=20220806
libavutil      56. 70.100 / 56. 70.100
libavcodec     58.134.100 / 58.134.100
libavformat    58. 76.100 / 58. 76.100
libavdevice    58. 13.100 / 58. 13.100
libavfilter     7.110.100 /  7.110.100
libswscale      5.  9.100 /  5.  9.100
libswresample   3.  9.100 /  3.  9.100
libpostproc    55.  9.100 / 55.  9.100

Which build option am I missing? Is it instead a later version of libavformat or something like that causing the issues? All other TwitchDownloaderCLI commands work.

Add any related files or extra information here

VOD ID: 1861806201

ScrubN commented 1 year ago

I'm unable to reproduce on both Manjaro (Native) and Debian (WSL1). I can only assume the problem is your custom ffmpeg build.

If this helps, here is the ffmpeg banner output from my Manjaro install

ffmpeg version n6.0 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 13.1.1 (GCC) 20230429
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libjxl --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librav1e --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-opencl --enable-opengl --enable-shared --enable-version3 --enable-vulkan
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
lay295 commented 1 year ago

Could you try with --verbose-ffmpeg and see the ffmpeg output?

tomShoutTheSecond commented 1 year ago

I saw this issue on OSX, using TwitchDownloaderCLI 1.53.2

--verbose-ffmpeg gives:

<FFMPEG LOG>   libavutil      58.  6.100 / 58.  6.100
<FFMPEG LOG>   libavcodec     60.  9.100 / 60.  9.100
<FFMPEG LOG>   libavdevice    60.  2.100 / 60.  2.100
<FFMPEG LOG>   libavformat    60.  4.101 / 60.  4.101
<FFMPEG LOG>   libavfilter     9.  5.100 /  9.  5.100
<FFMPEG LOG>   libswscale      7.  2.100 /  7.  2.100
<FFMPEG LOG> Unrecognized option 'preset'.
<FFMPEG LOG>   libswresample   4. 11.100 /  4. 11.100
<FFMPEG LOG> Error splitting the argument list: Option not found

I solved this by removing other versions of ffmpeg from PATH and reinstalling it with brew install ffmpeg

ScrubN commented 1 year ago

I figured that would be the solution. I wonder what version of FFmpeg you were using because the libs are more or less up to date.

Also I believe if you put an FFmpeg binary in the same folder as TwitchDownloaderCLI, that will be prioritized over PATH.

cc @gamedazed