Поскольку Apple является одним из ведущих поставщиков устройств, обеспечивающих доступ к мультимедиа и потоковую передачу, очень важно оптимизировать видеоконтент для воспроизведения в этих операционных системах. В этом руководстве основное внимание будет уделено преобразованию видео в MOV, формат видеофайлов по умолчанию для устройств Apple, с использованием Java. С помощью этого API вы можете настроить размеры видео, соотношение сторон, частоту кадров и качество, чтобы наилучшим образом удовлетворить ваши потребности в контенте.

Во-первых, нам нужно установить наш Java SDK:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Затем мы можем добавить ссылку на зависимость в pom.xml:

<dependencies>
<dependency>
    <groupId>com.github.Cloudmersive</groupId>
    <artifactId>Cloudmersive.APIClient.Java</artifactId>
    <version>v3.54</version>
</dependency>
</dependencies>

Теперь мы можем вызвать нашу функцию VideoConvertToMov:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.VideoApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");
VideoApi apiInstance = new VideoApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
String fileUrl = "fileUrl_example"; // String | Optional; URL of a video file being used for conversion. Use this option for files larger than 2GB.
Integer maxWidth = 56; // Integer | Optional; Maximum width of the output video, up to the original video width. Defaults to original video width.
Integer maxHeight = 56; // Integer | Optional; Maximum height of the output video, up to the original video width. Defaults to original video height.
Boolean preserveAspectRatio = true; // Boolean | Optional; If false, the original video's aspect ratio will not be preserved, allowing customization of the aspect ratio using maxWidth and maxHeight, potentially skewing the video. Default is true.
Integer frameRate = 56; // Integer | Optional; Specify the frame rate of the output video. Defaults to original video frame rate.
Integer quality = 56; // Integer | Optional; Specify the quality of the output video, where 100 is lossless and 1 is the lowest possible quality with highest compression. Default is 50.
try {
    byte[] result = apiInstance.videoConvertToMp4(inputFile, fileUrl, maxWidth, maxHeight, preserveAspectRatio, frameRate, quality);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling VideoApi#videoConvertToMp4");
    e.printStackTrace();
}

Теперь вы можете оптимизировать свой видеоконтент для самых популярных мультимедийных устройств. Вы можете получить доступ к бесплатному API-ключу на веб-сайте Cloudmersive. Это даст вам доступ к 800 ежемесячным вызовам в нашей библиотеке API.