a-schild / jave2

The JAVE (Java Audio Video Encoder) library is Java wrapper on the ffmpeg project
GNU General Public License v3.0
1.24k stars 247 forks source link

`InputFormatException` while retrieving video information #250

Open rob93c opened 9 months ago

rob93c commented 9 months ago

Hello, I developed a Telegram bot capable of converting images and videos in Telegram stickers and to do so I use Jave2 with FFmpeg 6.1

I noticed that sometimes the code new MultimediaObject(file, FFMPEG_LOCATOR).getInfo() throws an InputFormatException:

Caused by: ws.schild.jave.InputFormatException: null
at ws.schild.jave.MultimediaObject.parseMultimediaInfo(MultimediaObject.java:422)
at ws.schild.jave.MultimediaObject.getInfo(MultimediaObject.java:171)
at com.github.stickerifier.stickerify.media.MediaHelper.retrieveMultimediaInfo(MediaHelper.java:319)

I tried reading the video information using ffprobe and the output was the following:

ffprobe .\malformed
ffprobe version 6.1-full_build-www.gyan.dev Copyright (c) 2007-2023 the FFmpeg developers
  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --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-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --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. 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 @ 000001fc7f319780] Duplicate element
[matroska,webm @ 000001fc7f319780] 0x00 at pos 100 (0x64) invalid as first byte of an EBML number
[matroska,webm @ 000001fc7f319780] Duplicate element
[matroska,webm @ 000001fc7f319780] 0x00 at pos 169 (0xa9) invalid as first byte of an EBML number
[matroska,webm @ 000001fc7f319780] Element at 0x5d ending at 0x2cec0100000066 exceeds containing master element ending at 0x1409
.\malformed: End of file

I created a unit test to show its behavior: https://github.com/Stickerifier/Stickerify/blob/malformed-video-bug/src/test/java/com/github/stickerifier/stickerify/media/MediaHelperTest.java#L230-L235 The file affected by this issue is here.

Let me know if there is anything else I can do to help investigating this issue.

a-schild commented 9 months ago

Hello @rob93c , thanks for reporting this. The problem is very common, since there exist many many broken video files out into the wild. The sample file you linked to the issu is such an example. It looks like a webm file, but ffmpeg and ffprobe are not able to detect the correct details of the video/audio file and therefore it return null. Also I'm not able to open/playback the file with vlc player and a few others, so it seems to be badly broken.

Did you expect jave2 to behave differently?

rob93c commented 9 months ago

Given the file is broken I would expect for the exception to highlight it, if possible; I think InputFormatException: null might be too generic in this case

Thanks for looking into this @a-schild! Feel free to close the issue if you don't need it