3
回答
ffmpeg转码flv文件失败.
终于搞明白,存储TCO原来是这样算的>>>   

其他格式的视频转码都正常,但是flv转flv就出现转出来的文件大小为0k.负责转码方法如下:

/* 将文件转换为flv文件并生成截图
	 * @param inputVideoPath 上传的视频全路径
	 * @param videoRealPath 视频文件(输出路径)
	 * @param imageRealPath 截图的路径(输出路径)
	 * @return
	 */
	private static boolean processFLV(String inputVideoPath, String videoRealPath, String imageRealPath) {
		List<String> commend = new ArrayList<String>();
		//转换为FLV
		commend.add(FFMPEG_PATH);
		commend.add("-i");
		commend.add(inputVideoPath);
		commend.add("-ab");
		commend.add("56");
		commend.add("-ar");
		commend.add("22050");
		commend.add("-qscale");
		commend.add("6");
		commend.add("-r");
		commend.add("15");
		commend.add("-s");
		commend.add("600x500");
		commend.add("-aspect");//设置横纵比
		commend.add("16:9");
		commend.add(videoRealPath);
		try {
	    	/**********视频转码 start*****************/
			if(ffmpegTransImage( inputVideoPath,  imageRealPath)){
				ProcessBuilder builder = new ProcessBuilder(commend);
				builder.command(commend);
				 Process process = builder.start(); 
				//根据输出流来判断是否结束
				InputStream is = process.getErrorStream(); 
		        InputStreamReader inputStreamReader = new InputStreamReader(is); 
		        BufferedReader inputBufferedReader = new BufferedReader( inputStreamReader); 
		        String line = null; 
		        StringBuilder stringBuilder = new StringBuilder(); 
		        while ((line = inputBufferedReader.readLine()) != null) { 
		          stringBuilder.append(line); 
		        } 
		        inputBufferedReader.close(); 
		        inputBufferedReader = null; 
		        inputStreamReader.close(); 
		        inputStreamReader = null; 
		        is.close(); 
		        is = null; 
			}
	      	/**********视频转码 end*****************/
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

这是什么原因呢??

另外,对于不同分辨率的处理上,大伙有什么比较好的方案不??ffmpeg是直接将画面拉伸到设置的分辨率上,这样容易导致画面变形呢.还有其他类似的工具不??

举报
Cycle_C
发帖于5年前 3回/1K+阅
共有3个答案 最后回答: 5年前

我用了一个第三方包,也是封装的ffmpeg:

import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.InputFormatException;
import it.sauronsoftware.jave.VideoAttributes;
import it.sauronsoftware.jave.VideoInfo;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncodingAttributes;
import it.sauronsoftware.jave.VideoSize;

import java.lang.Object;
import java.io.*;


/**
 * 获取编码
 * @author Administrator
 *
 */

public class Encode {
	
	public Encode(){
		
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		File source = new File("f:\\Game.of.Thrones.S02E06.720p.HDTV.DD5.1.x264-EbP.mkv");
		File target = new File("f:\\target.flv");
		AudioAttributes audio = new AudioAttributes();
		audio.setCodec("ac3");
		audio.setBitRate(new Integer(64000));
		audio.setChannels(new Integer(1));
		audio.setSamplingRate(new Integer(22050));
		VideoAttributes video = new VideoAttributes();
		video.setCodec("flv");
		video.setBitRate(new Integer(160000));
		video.setFrameRate(new Integer(15));
		video.setSize(new VideoSize(400, 300));
		EncodingAttributes attrs = new EncodingAttributes();
		attrs.setFormat("flv");
		attrs.setAudioAttributes(audio);
		attrs.setVideoAttributes(video);
		Encoder encoder = new Encoder();
		try {
			encoder.encode(source, target, attrs);
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InputFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (EncoderException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
包的地址和文档:

http://www.sauronsoftware.it/projects/home/

--- 共有 1 条评论 ---
林胤请问如何判断转码是否完成了? 5年前 回复
顶部