Package io.lumify.storm.util

Source Code of io.lumify.storm.util.FFprobeDimensionsUtil

package io.lumify.storm.util;

import io.lumify.core.util.LumifyLogger;
import io.lumify.core.util.LumifyLoggerFactory;
import org.json.JSONArray;
import org.json.JSONObject;

public class FFprobeDimensionsUtil {
    private static final LumifyLogger LOGGER = LumifyLoggerFactory.getLogger(FFprobeDimensionsUtil.class);

    public static Integer getWidth(JSONObject json) {
        Integer width = getDimension(json, "width");
        if (width == null) {
            LOGGER.debug("Could not retrieve a \"width\" value from the JSON object.");
        }
        return width;
    }

    public static Integer getHeight(JSONObject json) {
        Integer height = getDimension(json, "height");
        if (height == null) {
            LOGGER.debug("Could not retrieve a \"height\" value from the JSON object.");
        }
        return height;
    }

    private static Integer getDimension(JSONObject json, String dimension) {
        if (json == null) {
            return null;
        }

        JSONArray streamsJson = json.optJSONArray("streams");
        if (streamsJson != null) {
            for (int i = 0; i < streamsJson.length(); i++) {
                JSONObject streamsIndexJson = streamsJson.optJSONObject(i);
                if (streamsIndexJson != null) {
                    Double optionalDimension = streamsIndexJson.optDouble(dimension);
                    if (!Double.isNaN(optionalDimension)) {
                        return optionalDimension.intValue();
                    }
                }
            }
        }

        return null;
    }
}
TOP

Related Classes of io.lumify.storm.util.FFprobeDimensionsUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.