Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to check if a file is really an image file? #235

Open
tjuxiaoyi opened this issue Aug 11, 2021 · 0 comments
Open

how to check if a file is really an image file? #235

tjuxiaoyi opened this issue Aug 11, 2021 · 0 comments
Labels

Comments

@tjuxiaoyi
Copy link

tjuxiaoyi commented Aug 11, 2021

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.

@Euklios Euklios changed the title how to check if a file is a really image file? how to check if a file is really an image file? Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants