bramp / ffmpeg-cli-wrapper

Java wrapper around the FFmpeg command line tool
BSD 2-Clause "Simplified" License
1.72k stars 413 forks source link

Is it possible to convert FFmpegFormat object or FFmpegStream object value to Map? #285

Closed DongJu-Na closed 1 year ago

DongJu-Na commented 1 year ago

Here is my code.

This code seems to generate an error while converting the variable value of Fraction type in the FFmpegStream object. I want to receive video information as a map. Any good way?

     public HashMap<String,Object> getVideoInfo(String fileName) throws IOException {
         HashMap<String,Object> result = new HashMap<String, Object>();
         ObjectMapper objectMapper = new ObjectMapper();

         FFprobe ffprobe = new FFprobe(ffprobePath);
         FFmpegProbeResult probeResult = ffprobe.probe(uploadPath + fileName);

         FFmpegFormat format = probeResult.getFormat();
         HashMap<String, Object> fResult = objectMapper.convertValue(format, new TypeReference<HashMap<String, Object>>(){});
         System.out.format("%nFile: '%s' ; Format: '%s' ; Duration: %.3fs", 
            format.filename, 
            format.format_long_name,
            format.duration
         );

         if(fResult != null) {
             result.putAll(fResult);
         }

         FFmpegStream stream = probeResult.getStreams().get(0);
         HashMap<String, Object> sResult = objectMapper.convertValue(stream, new TypeReference<HashMap<String, Object>>(){});
         System.out.format("%nCodec: '%s' ; Width: %dpx ; Height: %dpx",
            stream.codec_long_name,
            stream.width,
            stream.height
         );

         if(sResult != null) {
             result.putAll(sResult);
         }

         return result;

     }
bramp commented 1 year ago

You need to tell the Jackson object mapper about the fraction type.

I actually have a really old example of this here: https://github.com/bramp/jackson-datatype-commons-lang3/blob/master/src/test/java/net/bramp/jackson/lang3/FractionTest.java

DongJu-Na commented 1 year ago

Thank you for your answer. I don't really understand with that code Can you explain it in detail? 😥

bramp commented 1 year ago

I haven't used this code in a long time, but if you do something like:

mapper.registerModule(new LangModule());

It will tell your object mapper how to decode/encode fractions

DongJu-Na commented 1 year ago

Thanks, I put that code in and the error went away. Is this library dependent vulnerability safe? It is difficult to confirm without knowledge Can you answer me one more time?

Vulnerabilities from dependencies:
CVE-2022-42004
CVE-2021-20190
CVE-2020-9548
CVE-2020-9547
CVE-2020-8840
CVE-2020-36518
CVE-2020-36189
CVE-2020-36188
CVE-2020-36187
CVE-2020-36186
CVE-2020-36185
CVE-2020-36184
CVE-2020-36183
CVE-2020-36182
CVE-2020-36181
CVE-2020-36180
CVE-2020-36179
CVE-2020-35491
CVE-2020-35490
CVE-2020-25649
CVE-2020-24750
CVE-2020-24616
CVE-2020-15250
CVE-2020-10673
CVE-2020-10650
CVE-2019-20330
CVE-2019-17531
CVE-2019-17267
CVE-2019-16943
CVE-2019-16942
CVE-2019-16335
CVE-2019-14892
CVE-2019-14540
CVE-2019-14439
CVE-2019-14379
CVE-2019-12814
CVE-2019-12384
CVE-2019-12086
CVE-2018-7489
CVE-2018-5968
CVE-2018-14719
CVE-2018-14718
CVE-2018-12022
CVE-2018-11307
CVE-2017-7525
CVE-2017-17485
CVE-2017-15095
bramp commented 1 year ago

Sorry I can't help with that

DongJu-Na commented 1 year ago

Thanks for the answer I will close the issue have a nice day