溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

java項目中怎么調(diào)整視頻大小

發(fā)布時間:2022-02-28 10:58:40 來源:億速云 閱讀:126 作者:iii 欄目:開發(fā)技術(shù)

這篇“java項目中怎么調(diào)整視頻大小”文章的知識點大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“java項目中怎么調(diào)整視頻大小”文章吧。

當您的受眾分散在當前和新興的在線媒體平臺上時,優(yōu)化您的品牌形象可能是一項艱巨的任務。實現(xiàn)目標和建立品牌知名度的一種方法是共享視頻內(nèi)容。這可以成為分享視覺效果、交流信息和接觸不同受眾的一種引人入勝的方法。不巧的是,由于不同平臺的大小要求不同,管理視頻格式可能會變得有點困難。

如果需要調(diào)整視頻大小,那么確定您是希望保持當前的縱橫比還是對其進行自定義以適應新參數(shù)非常重要。澄清一下,縱橫比是圖像的寬度與高度的比率,它會影響調(diào)整大小的視頻與原始視覺相比的外觀。如果您想改變視頻大小,但又不想改變其觀看方式,則有必要保留縱橫比。另一方面,您可能愿意稍微調(diào)整尺寸以適應新格式。

以下 API 將為您提供兩個用于在 Java 中調(diào)整視頻大小的自動選項;一個將保持您的原始縱橫比,另一個將允許您輸入新的可自定義尺寸。這兩個功能都支持多種輸入視頻格式,包括 AVI、FLV、MP4、MOV 等。它們每 10 MB 文件大小使用 1 個 API 調(diào)用,并且在 5 分鐘內(nèi)每增加一分鐘的處理時間使用 1 個 API 調(diào)用,總處理時間最多為 25 分鐘。最大輸出文件大小為 50GB。

首先,我們將通過在 pom.xml 中添加對 jitpack 存儲庫的引用來安裝 Maven SDK:

java:

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

然后,我們將添加對依賴項的引用:

java:

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

安裝完成后,我們可以討論我們的第一個 API。下面的功能將在保持原始縱橫比和編碼的同時調(diào)整視頻大小,這將允許您保留原始視覺并以您選擇的風格傳達內(nèi)容。要執(zhí)行操作,我們需要將導入添加到控制器的頂部并調(diào)用函數(shù):

java:

// 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.
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.
String extension = "extension_example"; // String | Optional; Specify the file extension of the input video. This is recommended when inputting a file directly, without a file name. If no file name is available and no extension is provided, the extension will be inferred from the file data, which may cause a different extension to be used in the output.
try {
    byte[] result = apiInstance.videoResizeVideo(inputFile, fileUrl, maxWidth, maxHeight, frameRate, quality, extension);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling VideoApi#videoResizeVideo");
    e.printStackTrace();
}

現(xiàn)在,如果您更喜歡可自定義的編輯體驗,可以使用以下功能調(diào)整視頻大小而不保留原始縱橫比;這將允許您通過稍作改動來適應任何視頻格式。但是,在選擇這種方法時請記住,它確實會增加圖像傾斜的可能性。 

java:

// 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.
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.
String extension = "extension_example"; // String | Optional; Specify the file extension of the input video. This is recommended when inputting a file directly, without a file name. If no file name is available and no extension is provided, the extension will be inferred from the file data, which may cause a different extension to be used in the output.
try {
    byte[] result = apiInstance.videoResizeVideoSimple(inputFile, fileUrl, maxWidth, maxHeight, frameRate, quality, extension);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling VideoApi#videoResizeVideoSimple");
    e.printStackTrace();
}

為確保兩個調(diào)整大小功能順利運行,您需要滿足幾個必需的參數(shù),并可以選擇輸入其他一些參數(shù):

  • 輸入文件(必填):您希望對其執(zhí)行操作的特定視頻文件。

  • API Key(必填):您的個人API密鑰;如果您還沒有,可以通過在 Cloudmersive 網(wǎng)站上注冊一個免費帳戶來檢索。

  • 文件 URL(可選):您要對其執(zhí)行操作的文件的 URL;推薦用于超過 2GB 的任何文件。

  • Max Width(可選):輸出視頻的最大寬度,可達原始視頻寬度;默認為原始視頻寬度。

  • Max Height(可選):輸出視頻的最大高度,可達原始視頻寬度;默認為原始視頻高度。

  • Frame Rate(可選):輸出視頻的幀率;默認為原始視頻幀率。

  • 質(zhì)量(可選):輸出視頻的質(zhì)量,其中 100 是無損的,1 是具有最高壓縮率的最低質(zhì)量;默認值為 50。

  • 擴展名(可選):輸入視頻的文件擴展名;直接輸入文件時建議使用此選項,無需文件名。如果沒有可用的文件名且未提供擴展名,則將從文件數(shù)據(jù)中推斷出擴展名,這可能會導致在輸出中使用不同的擴展名。

無論您選擇保持還是調(diào)整縱橫比,我們都希望本教程適合您的視頻調(diào)整大小需求。

以上就是關(guān)于“java項目中怎么調(diào)整視頻大小”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對大家有幫助,若想了解更多相關(guān)的知識內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI