ffmpeg-cli-wrapper
ffmpeg-cli-wrapper copied to clipboard
how to check if a file is really an image file?
I want to check whether a file whose name end with .png is a really png file(is valid). And I think I can do this by check the error field in FFmpegProbeResult. But when I use the following code to check a invalid png file, the error in FFmpegProbeResult is null and I think it imply that the file can be decoded normal. This is the code I used.
val ffprobe = FFprobe("/usr/local/bin/ffprobe")
val probeResult = ffprobe.probe(filename)
logger.info("format name is ${probeResult.format.format_name}, " +
"duration is ${probeResult.format.duration} " +
"size is ${probeResult.format.size}" +
" error code is ${probeResult.error.code}")
and I got a exception as follow
java.lang.NullPointerException: Cannot read field "code" because "probeResult.error" is null
Then I use the ffprobe in command line directly by this command.
ffprobe -i test.png
I got info that the PNG is invalid.
[png @ 0x7fa1a5808e00] Invalid PNG signature 0x3C21444F43545950. [image2 @ 0x7fa1a5015a00] decoding for stream 0 failed [image2 @ 0x7fa1a5015a00] Could not find codec parameters for stream 0 (Video: png, none(pc)): unspecified size Consider increasing the value for the 'analyzeduration' and 'probesize' options Input #0, image2, from 'test.png': Duration: 00:00:00.04, start: 0.000000, bitrate: 9780 kb/s Stream #0:0: Video: png, none(pc), 25 tbr, 25 tbn, 25 tbc
so I wonder how can I check if the file is valid by code, thank you for reply.