Fix #5230: video upload 500 error (StatementInvalid) & empty error panel on page
Fix StatementInvalid exception when uploading https://files.catbox.moe/vxoe2p.mp4. This was a result of multiple bugs: * First, generating thumbnails for the video failed. This was because the video uses the AV1 codec, which FFmpeg failed to decode. It failed because our version of FFmpeg was built without the `--enable-libdav1d` flag, so it uses the builtin AV1 decoder, which apparently can't handle this particular video (it spews a bunch of errors about "Failed to get pixel format" and "missing sequence header" and "failed to get reference frame"). * Because generating the thumbnails failed, an exception was raised. We tried to save the error message in the upload_media_assets.error field. However, this also failed because the error message was 77kb long (it contained the entire output of the ffmpeg command), but the `upload_media_assets` table had a btree index on the `error` column, which meant the maximum length of the error column was limited to ~2.7kb. This lead to a StatementInvalid exception being raised. * Because the StatementInvalid exception was raised while we were trying to set the upload media asset's status to `failed`, the upload was left stuck in the `processing` state rather than being set to the `failed` state. * Because the upload was stuck in the `processing` state, the upload page would hang forever waiting for the upload to complete. The fixes are to: * Build FFmpeg with `--enable-libdav1d` to use libdav1d for decoding AV1 videos instead of the builtin AV1 decoder. * Remove the index on the `upload_media_assets.error` column so that setting overly long error messages won't fail. * Catch unexpected exceptions in ProcessUploadMediaAssetJob so we can mark uploads as failed, even if `process_upload!` itself fails because it raises an unexpected exception inside its own exception handler. * Check that the video is playable with `MediaFile::Video#is_corrupt?` before allowing it to be uploaded. This way we can return a better error message if we can't generate thumbnails because the video isn't playable. This requires decoding the entire video, so it means uploads may take several seconds longer for long videos. It's also a security risk in case ffmpeg has any bugs. * Define `MediaAsset#preview!` as raising an exception on error, so it's clear that generating thumbnails can fail. Define `MediaAsset#preview` as returning nil on error for when we don't care about the cause of the error.
This commit is contained in:
@@ -14,7 +14,7 @@ COMMON_BUILD_DEPS="
|
||||
curl ca-certificates build-essential pkg-config git
|
||||
"
|
||||
RUBY_BUILD_DEPS="libssl-dev zlib1g-dev libgmp-dev"
|
||||
FFMPEG_BUILD_DEPS="libvpx-dev nasm"
|
||||
FFMPEG_BUILD_DEPS="libvpx-dev libdav1d-dev nasm"
|
||||
MOZJPEG_BUILD_DEPS="cmake nasm libpng-dev zlib1g-dev"
|
||||
VIPS_BUILD_DEPS="
|
||||
libfftw3-dev libwebp-dev liborc-dev liblcms2-dev libpng-dev
|
||||
@@ -24,7 +24,7 @@ EXIFTOOL_RUNTIME_DEPS="perl perl-modules libarchive-zip-perl"
|
||||
DANBOORU_RUNTIME_DEPS="
|
||||
ca-certificates mkvtoolnix rclone libpq5 openssl libgmpxx4ldbl
|
||||
zlib1g libfftw3-3 libwebp7 libwebpmux3 libwebpdemux2 liborc-0.4.0 liblcms2-2
|
||||
libpng16-16 libexpat1 libglib2.0 libgif7 libexif12 libheif1 libvpx7
|
||||
libpng16-16 libexpat1 libglib2.0 libgif7 libexif12 libheif1 libvpx7 libdav1d6
|
||||
libseccomp2 libseccomp-dev libjemalloc2
|
||||
"
|
||||
COMMON_RUNTIME_DEPS="
|
||||
@@ -77,7 +77,7 @@ install_ffmpeg() {
|
||||
curl -L "$FFMPEG_URL" | tar -C /usr/local/src -xzvf -
|
||||
cd /usr/local/src/FFmpeg-n${FFMPEG_VERSION}
|
||||
|
||||
./configure --disable-ffplay --disable-network --disable-doc --enable-libvpx
|
||||
./configure --disable-ffplay --disable-network --disable-doc --enable-libvpx --enable-libdav1d
|
||||
make -j "$(nproc)"
|
||||
cp ffmpeg ffprobe /usr/local/bin
|
||||
|
||||
|
||||
Reference in New Issue
Block a user