最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
用java程序調(diào)用ffmpeg執(zhí)行視頻文件格式轉(zhuǎn)換flv

用java小例題說明更直觀:(可以直接編譯運行)

成都創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設,羅甸企業(yè)網(wǎng)站建設,羅甸品牌網(wǎng)站建設,網(wǎng)站定制,羅甸網(wǎng)站建設報價,網(wǎng)絡營銷,網(wǎng)絡優(yōu)化,羅甸網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。

環(huán)境我在windows平臺下測試的。。。

需要在e:/下有ffmpeg.exe;mencoder.exe;drv43260.dll;pncrt.dll共4個文件。

如何得到這4個文件參考文章http://blog.sina.com.cn/u/4a424eca010005kb

還要在e:/input下放各種文件名為a的以下各種視頻文件;還要e:/output;java程序執(zhí)行后能得到一個a.flv的已轉(zhuǎn)換的文件。

ffmpeg.exe能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)
對ffmpeg.exe無法解析的文件格式(wmv9,rm,rmvb等),

可以先用別的工具(mencoder)轉(zhuǎn)換為avi(ffmpeg能解析的)格式;

mencoder.exe;drv43260.dll;pncrt.dll這3個文件是為文件格式(wmv9,rm,rmvb等)

轉(zhuǎn)換為avi(ffmpeg能解析的)格式準備的;再把轉(zhuǎn)換好的avi文件再用ffmpeg.exe轉(zhuǎn)換成flv格式的視頻文件。。。

package com.jh.test;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ConvertVideo {
private static String inputPath = "";

private static String outputPath = "";

private static String ffmpegPath = "";

public static void main(String args[]) throws IOException {

    getPath();

    if (!checkfile(inputPath)) {
        System.out.println(inputPath + " is not file");
        return;
    }
    if (process()) {
        System.out.println("ok");
    }
}

public static void getPath(){
     // 先獲取當前項目路徑,在獲得源文件、目標文件、轉(zhuǎn)換器的路徑
    File diretory = new File("");
    try {
        String currPath = diretory.getAbsolutePath();
        //視頻的地址
        inputPath = "C:\\平行四邊形面積.flv";
        //視頻轉(zhuǎn)完格式存放地址
        outputPath = "E:\\mp4\\";
        //轉(zhuǎn)換視頻的插件位置
        ffmpegPath = "G:\\工具類\\ffmpeg-20171225-be2da4c-win64-static\\ffmpeg-20171225-be2da4c-win64-static\\bin\\";
        System.out.println(currPath);
    }
    catch (Exception e) {
        System.out.println("getPath出錯");
    }
}

public static boolean process() {
    int type = checkContentType();
    boolean status = false;
        System.out.println("直接轉(zhuǎn)成mp4格式");
        status = processMp4(inputPath);// 直接轉(zhuǎn)成mp4格式
    return status;
}

private static int checkContentType() {
    String type = inputPath.substring(inputPath.lastIndexOf(".") + 1, inputPath.length())
            .toLowerCase();
    // ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)
    if (type.equals("avi")) {
        return 0;
    } else if (type.equals("mpg")) {
        return 0;
    } else if (type.equals("wmv")) {
        return 0;
    } else if (type.equals("3gp")) {
        return 0;
    } else if (type.equals("mov")) {
        return 0;
    } else if (type.equals("mp4")) {
        return 0;
    } else if (type.equals("asf")) {
        return 0;
    } else if (type.equals("asx")) {
        return 0;
    } else if (type.equals("flv")) {
        return 0;
    }
    // 對ffmpeg無法解析的文件格式(wmv9,rm,rmvb等),
    // 可以先用別的工具(mencoder)轉(zhuǎn)換為avi(ffmpeg能解析的)格式.
    else if (type.equals("wmv9")) {
        return 1;
    } else if (type.equals("rm")) {
        return 1;
    } else if (type.equals("rmvb")) {
        return 1;
    }
    return 9;
}

private static boolean checkfile(String path) {
    File file = new File(path);
    if (!file.isFile()) {
        return false;
    }
    return true;
}

// 對ffmpeg無法解析的文件格式(wmv9,rm,rmvb等), 可以先用別的工具(mencoder)轉(zhuǎn)換為avi(ffmpeg能解析的)格式.
private static String processAVI(int type) {
    List commend = new ArrayList();
    commend.add(ffmpegPath + "mencoder");
    commend.add(inputPath);
    commend.add("-oac");
    commend.add("lavc");
    commend.add("-lavcopts");
    commend.add("acodec=mp3:abitrate=64");
    commend.add("-ovc");
    commend.add("xvid");
    commend.add("-xvidencopts");
    commend.add("bitrate=600");
    commend.add("-of");
    commend.add("mp4");
    commend.add("-o");
    commend.add(outputPath + "a.AVI");
    try {
        ProcessBuilder builder = new ProcessBuilder();
        Process process = builder.command(commend).redirectErrorStream(true).start();
        new PrintStream(process.getInputStream());
        new PrintStream(process.getErrorStream());
        process.waitFor();
        return outputPath + "a.AVI";
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

// ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)
private static boolean processFlv(String oldfilepath) {

    if (!checkfile(inputPath)) {
        System.out.println(oldfilepath + " is not file");
        return false;
    }
    List command = new ArrayList();
    command.add(ffmpegPath + "ffmpeg");
    command.add("-i");
    command.add(oldfilepath);
    command.add("-ab");
    command.add("56");
    command.add("-ar");
    command.add("22050");
    command.add("-qscale");
    command.add("8");
    command.add("-r");
    command.add("15");
    command.add("-s");
    command.add("600x500");
    command.add(outputPath + "a.flv");
    try {

        // 方案1

// Process videoProcess = Runtime.getRuntime().exec(ffmpegPath + "ffmpeg -i " + oldfilepath
// + " -ab 56 -ar 22050 -qscale 8 -r 15 -s 600x500 "
// + outputPath + "a.flv");

        // 方案2
        Process videoProcess = new ProcessBuilder(command).redirectErrorStream(true).start();

        new PrintStream(videoProcess.getErrorStream()).start();

        new PrintStream(videoProcess.getInputStream()).start();

        videoProcess.waitFor();

        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

private static boolean processMp4(String oldfilepath) {

    if (!checkfile(inputPath)) {
        System.out.println(oldfilepath + " is not file");
        return false;
    }
    List command = new ArrayList();
    command.add(ffmpegPath + "ffmpeg");
    command.add("-i");
    command.add(oldfilepath);
    command.add("-c:v");
    command.add("libx264");
    command.add("-mbd");
    command.add("0");
    command.add("-c:a");
    command.add("aac");
    command.add("-strict");
    command.add("-2");
    command.add("-pix_fmt");
    command.add("yuv420p");
    command.add("-movflags");
    command.add("faststart");
    command.add(outputPath + "a.mp4");
    try {

        // 方案1
//        Process videoProcess = Runtime.getRuntime().exec(ffmpegPath + "ffmpeg -i " + oldfilepath 
//                + " -ab 56 -ar 22050 -qscale 8 -r 15 -s 600x500 "
//                + outputPath + "a.flv");

        // 方案2
        Process videoProcess = new ProcessBuilder(command).redirectErrorStream(true).start();

        new PrintStream(videoProcess.getErrorStream()).start();

        new PrintStream(videoProcess.getInputStream()).start();

        videoProcess.waitFor();

        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

}
class PrintStream extends Thread
{
java.io.InputStream is = null;
public PrintStream(java.io.InputStream is)
{
is = is;
}

public void run() 
{
    try 
    {
        while(this != null) 
        {
            int _ch = __is.read();
            if(_ch != -1) 
                System.out.print((char)_ch); 
            else break;
        }
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    } 
}

}


網(wǎng)站欄目:用java程序調(diào)用ffmpeg執(zhí)行視頻文件格式轉(zhuǎn)換flv
轉(zhuǎn)載注明:http://fisionsoft.com.cn/article/gppiii.html