import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.volcengine.tos.TOSV2;
import com.volcengine.tos.TOSV2ClientBuilder;
import com.volcengine.tos.TosClientException;
import com.volcengine.tos.TosServerException;
import com.volcengine.tos.internal.util.TosUtils;
import com.volcengine.tos.model.object.GetObjectV2Input;
import com.volcengine.tos.model.object.GetObjectV2Output;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class VideoInfoExample {
static class VideoInfo {
@JsonProperty("streams")
@JsonProperty("nb_streams")
@JsonProperty("nb_programs")
@JsonProperty("format_name")
@JsonProperty("format_long_name")
@JsonProperty("start_time")
@JsonProperty("duration")
@JsonProperty("bit_rate")
@JsonProperty("probe_score")
static class FormatTags {
@JsonProperty("major_brand")
@JsonProperty("minor_version")
@JsonProperty("compatible_brands")
String CompatibleBrands;
@JsonProperty("encoder")
@JsonProperty("codec_name")
@JsonProperty("codec_long_name")
@JsonProperty("profile")
@JsonProperty("codec_type")
@JsonProperty("codec_tag_string")
@JsonProperty("codec_tag")
@JsonProperty("coded_width")
@JsonProperty("coded_height")
@JsonProperty("sample_aspect_ratio")
String SampleAspectRatio;
@JsonProperty("display_aspect_ratio")
String DisplayAspectRatio;
@JsonProperty("pix_fmt")
@JsonProperty("chroma_location")
@JsonProperty("nal_length_size")
@JsonProperty("r_frame_rate")
@JsonProperty("avg_frame_rate")
@JsonProperty("time_base")
@JsonProperty("start_pts")
@JsonProperty("start_time")
@JsonProperty("duration_ts")
@JsonProperty("duration")
@JsonProperty("bit_rate")
@JsonProperty("bits_per_raw_sample")
String BitsPerRawSample;
@JsonProperty("nb_frames")
@JsonProperty("extradata_size")
@JsonProperty("disposition")
Disposition disposition;
@JsonProperty("sample_fmt")
@JsonProperty("sample_rate")
@JsonProperty("channels")
@JsonProperty("channel_layout")
static class Disposition {
@JsonProperty("default")
@JsonProperty("original")
@JsonProperty("comment")
@JsonProperty("karaoke")
@JsonProperty("hearing_impaired")
@JsonProperty("visual_impaired")
@JsonProperty("clean_effects")
@JsonProperty("attached_pic")
@JsonProperty("timed_thumbnails")
@JsonProperty("captions")
@JsonProperty("descriptions")
@JsonProperty("metadata")
@JsonProperty("dependent")
@JsonProperty("still_image")
@JsonProperty("language")
@JsonProperty("handler_name")
@JsonProperty("vendor_id")
public static void main(String[] args) {
String endpoint = "your endpoint";
String region = "your region";
String accessKey = System.getenv("TOS_ACCESS_KEY");
String secretKey = System.getenv("TOS_SECRET_KEY");
String bucketName = "bucket-example";
String objectKey = "video.mp4";
String style = "video/info";
TOSV2 tos = new TOSV2ClientBuilder().build(region, endpoint, accessKey, secretKey);
GetObjectV2Input input = new GetObjectV2Input().setBucket(bucketName).setKey(objectKey).setProcess(style);
try (ByteArrayOutputStream stream = new ByteArrayOutputStream();
GetObjectV2Output output = tos.getObject(input)) {
byte[] buffer = new byte[1024];
while ((length = output.getContent().read(buffer)) != -1) {
stream.write(buffer, 0, length);
String respBody = stream.toString("UTF-8");
System.out.println("Get video info success, video info is " + respBody);
VideoInfo info = TosUtils.getJsonMapper().readValue(respBody, new TypeReference<VideoInfo>() {
System.out.println("Video info stream length:" + info.streams.size());
} catch (JacksonException e) {
System.out.println("parse response data failed");
} catch (IOException e) {
System.out.println("read response data failed");
} catch (TosClientException e) {
System.out.println("get video info failed");
System.out.println("Message: " + e.getMessage());
if (e.getCause() != null) {
e.getCause().printStackTrace();
} catch (TosServerException e) {
System.out.println("get video info failed");
System.out.println("StatusCode: " + e.getStatusCode());
System.out.println("Code: " + e.getCode());
System.out.println("Message: " + e.getMessage());
System.out.println("RequestID: " + e.getRequestID());
System.out.println("get video info failed");
System.out.println("unexpected exception, message: " + t.getMessage());