加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

无纸化办公系列--影音文件转flash

发布时间:2020-12-15 20:04:45 所属栏目:百科 来源:网络整理
导读:package com.util; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Calendar; import java.util.List; /** ?* 影音转换及截图 ?*? ?* @author lanxum ?* ?*/ public class Co

package com.util;

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

/**
?* 影音转换及截图
?*?
?* @author lanxum
?*
?*/
public class ConvertVideo {

?? ?private static String FFMPEG_PATH = "C:/ffmpeg";

?? ?private static String OUT_PUT_FILE_PATH = "c:ffmpegoutput";

?? ?private static String TEMP_FILE_TYPE = "avi";

?? ?private static String CONVERT_FILE_TYPE_VIDEO = "flv";
?? ?private static String CONVERT_FILE_TYPE_JPG = "jpg";

?? ?public static void main(String[] args) {

?? ??? ?//String pathString = "c:ffmpeginput14327136307738026.avi";
?? ??? ?String pathString = "c:ffmpeginput14327136307738026.rmvb";
?? ??? ?String outPutFileName = "2222";

?? ??? ?if (!checkfile(pathString)) {
?? ??? ??? ?System.out.println(pathString + " is not file");
?? ??? ??? ?return;
?? ??? ?}
?? ??? ?if (process(pathString,OUT_PUT_FILE_PATH,outPutFileName)) {
?? ??? ??? ?System.out.println("ok");
?? ??? ?}
?? ?}

?? ?private static boolean process(String filePath,String outputFilePath,String outPutFileName) {
?? ??? ?int type = checkContentType(filePath);
?? ??? ?boolean status = false;
?? ??? ?if (type == 0) {
?? ??? ??? ?System.out.println("直接将文件转为flv文件");
?? ??? ??? ?status = processFLV(filePath,outputFilePath,outPutFileName);// 直接将文件转为flv文件
?? ??? ?} else if (type == 1) {
?? ??? ??? ?String avifilepath = processAVI(type,filePath,outPutFileName,TEMP_FILE_TYPE);
?? ??? ??? ?if (avifilepath == null)
?? ??? ??? ??? ?return false;// avi文件没有得到
?? ??? ??? ?status = processFLV(avifilepath,outPutFileName);// 将avi转为flv
?? ??? ?}
?? ??? ?return status;
?? ?}

?? ?private static int checkContentType(String filePath) {
?? ??? ?String type = filePath.substring(filePath.lastIndexOf(".") + 1,filePath.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)转换为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)转换为avi(ffmpeg能解析的)格式.
?? ?private static String processAVI(int type,String filePath,String outPutFileName,String fileType) {
?? ??? ?List<String> commend = new ArrayList<String>();
?? ??? ?commend.add(FFMPEG_PATH + "/mencoder");
?? ??? ?commend.add(filePath);
?? ?
?? ??? ?/* 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("avi");
?? ??? ? commend.add("-o");*/
?? ??? ??
?? ??? ?commend.add("-oac");
?? ??? ?commend.add("mp3lame");
?? ??? ?commend.add("-lameopts");
?? ??? ?commend.add("preset=64");
?? ??? ?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("avi");
?? ??? ?commend.add("-o");
?? ??? ?commend.add(outputFilePath + outPutFileName + "." + fileType);

?? ??? ?try {
?? ??? ??? ?/*
?? ??? ??? ? * ProcessBuilder builder = new ProcessBuilder();
?? ??? ??? ? * builder.command(commend); builder.start();
?? ??? ??? ? */
?? ??? ??? ?// 预处理进程

?? ??? ??? ?ProcessBuilder builder = new ProcessBuilder();
?? ??? ??? ?builder.command(commend);
?? ??? ??? ?builder.redirectErrorStream(true);
?? ??? ??? ?// 进程信息输出到控制台
?? ??? ??? ?Process p = builder.start();
?? ??? ??? ?/*BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
?? ??? ??? ?String line = null;
?? ??? ??? ?while ((line = br.readLine()) != null) {
?? ??? ??? ??? ?System.out.println(line);
?? ??? ??? ?}
*/?? ??? ??? ?p.waitFor();// 直到上面的命令执行完,才向下执行
?? ??? ??? ?// doWaitFor(p);
?? ??? ??? ?return outputFilePath + outPutFileName + "." + fileType;
?? ??? ?} catch (Exception e) {
?? ??? ??? ?e.printStackTrace();
?? ??? ??? ?return null;
?? ??? ?}
?? ?}

?? ?/**
?? ? *?
?? ? * @param filePath
?? ? * @param outputFilePath
?? ? * @param fileName
?? ? * @param flag
?? ? * ? ? ? ? ? ?是否是经过memcoder转换
?? ? * @return
?? ? */
?? ?// ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)
?? ?private static boolean processFLV(String filePath,String fileName) {

?? ??? ?if (!checkfile(filePath)) {
?? ??? ??? ?System.out.println(filePath + " is not file");
?? ??? ??? ?return false;
?? ??? ?} /*else {
?? ??? ??? ?System.out.println(checkfile(filePath));
?? ??? ??? ?while (!checkfile(filePath)) {
?? ??? ??? ??? ?System.out.println(checkfile(filePath));
?? ??? ??? ?}
?? ??? ?}*/

?? ??? ?// 文件命名
?? ??? ?Calendar c = Calendar.getInstance();
?? ??? ?String savename = String.valueOf(c.getTimeInMillis()) + Math.round(Math.random() * 100000);
?? ??? ?List<String> commend = new ArrayList<String>();
?? ??? ?commend.add(FFMPEG_PATH + "/ffmpeg");
?? ??? ?commend.add("-i");
?? ??? ?commend.add(filePath);
?? ??? ?commend.add("-ab");
?? ??? ?commend.add("56");
?? ??? ?commend.add("-ar");
?? ??? ?commend.add("22050");
?? ??? ?commend.add("-qscale");
?? ??? ?commend.add("8");
?? ??? ?commend.add("-r");
?? ??? ?commend.add("15");
?? ??? ?commend.add("-s");
?? ??? ?commend.add("600x500");
?? ??? ?commend.add(outputFilePath + fileName + "." + CONVERT_FILE_TYPE_VIDEO);
?? ??? ?try {
?? ??? ??? ?Runtime runtime = Runtime.getRuntime();
?? ??? ??? ?Process proce = null;
?? ??? ??? ?String cmd = "";
?? ??? ??? ?String cut = " ? ?" + FFMPEG_PATH + "/ffmpeg.exe ? -i ? " + filePath
?? ??? ??? ??? ??? ?+ " ? -y ? -f ? image2 ? -ss ? 8 ? -t ? 0.001 ? -s ? 600x500 ? " + outputFilePath + fileName + "."
?? ??? ??? ??? ??? ?+ CONVERT_FILE_TYPE_JPG;
?? ??? ??? ?String cutCmd = cmd + cut;
?? ??? ??? ?proce = runtime.exec(cutCmd);

?? ??? ??? ?ProcessBuilder builder = new ProcessBuilder(commend);
?? ??? ??? ?builder.command(commend);
?? ??? ??? ?builder.start();
?? ??? ??? ?return true;
?? ??? ?} catch (Exception e) {
?? ??? ??? ?e.printStackTrace();
?? ??? ??? ?return false;
?? ??? ?}
?? ?}

?? ?public static int doWaitFor(Process p) {
?? ??? ?InputStream in = null;
?? ??? ?InputStream err = null;
?? ??? ?int exitValue = -1; // returned to caller when p is finished
?? ??? ?try {
?? ??? ??? ?System.out.println("comeing");
?? ??? ??? ?in = p.getInputStream();
?? ??? ??? ?err = p.getErrorStream();
?? ??? ??? ?boolean finished = false; // Set to true when p is finished

?? ??? ??? ?while (!finished) {
?? ??? ??? ??? ?try {
?? ??? ??? ??? ??? ?while (in.available() > 0) {
?? ??? ??? ??? ??? ??? ?Character c = new Character((char) in.read());
?? ??? ??? ??? ??? ??? ?System.out.print(c);
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?while (err.available() > 0) {
?? ??? ??? ??? ??? ??? ?Character c = new Character((char) err.read());
?? ??? ??? ??? ??? ??? ?System.out.print(c);
?? ??? ??? ??? ??? ?}

?? ??? ??? ??? ??? ?exitValue = p.exitValue();
?? ??? ??? ??? ??? ?finished = true;

?? ??? ??? ??? ?} catch (IllegalThreadStateException e) {
?? ??? ??? ??? ??? ?Thread.currentThread().sleep(500);
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?} catch (Exception e) {
?? ??? ??? ?System.err.println("doWaitFor();: unexpected exception - " + e.getMessage());
?? ??? ?} finally {
?? ??? ??? ?try {
?? ??? ??? ??? ?if (in != null) {
?? ??? ??? ??? ??? ?in.close();
?? ??? ??? ??? ?}

?? ??? ??? ?} catch (IOException e) {
?? ??? ??? ??? ?System.out.println(e.getMessage());
?? ??? ??? ?}
?? ??? ??? ?if (err != null) {
?? ??? ??? ??? ?try {
?? ??? ??? ??? ??? ?err.close();
?? ??? ??? ??? ?} catch (IOException e) {
?? ??? ??? ??? ??? ?System.out.println(e.getMessage());
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?}
?? ??? ?return exitValue;
?? ?}

}

?

?

Windows下FFmpeg快速入门

ffmpeg参数解释

mencoder和ffmpeg参数详解(Java处理视频)

Java 生成视频缩略图(ffmpeg)

使用ffmpeg进行视频文件转换成FLV整理

java 视频处理 mencoder

java 视频处理 ffmped+mencoder

?

????ffmpeg+mencoder几乎可以完成目前基于web的播客平台任何音视频处理的操作.如果还需要添加一些什么的话,那么就是视频在线录制功能了,这个也可以用ffmpeg+fms来完成,因此一般的类似于YouTube的一些可见功能都可以在ffmpeg+mencoder+fms来做后台实现.由于fms没有实践,因此这里不描述.
?本文有三部分:
?1)ffmpeg+mencoder环境搭建
?2)常见操作说明
?3)个人的一些使用心得

1.ffmpeg+mencoder环境搭建

?1)概论
?音视频界众多的编解码协议和各个公司定义的专用格式导致目前的视频音频文件纷繁复杂,单纯的ffmpeg支持的格式并不完全包括所有种类,至少 swf,rmvb(rv4)目前的版本是不支持的.同时wma9似乎可以支持了.但没有测试.同时mencoder能支持rm,rmvb等格式,但是从视频中获取某帧截图的工作只能由ffmpeg完成.因此可以采用ffmpeg+mencoder完成目前所有流行格式的视频压缩转换,设置视频信息,截取视频中的图片等功能了,同时,采用其他的一些开源工具如MediaInfo可以获取视频的元数据信息.

?2)ffmpeg篇
?首先获取软件包:ffmpeg,lame(支持mp3),ogg vorbis,x264(h264 codec),xvid,3gp,libdts,mpeg4 aac.这些软件包在71.21的/home/zhengyu/tools里面都能找到.如果需要网上下载的话,可以提供下载地址.
? ?ffmpeg官网下载:http://ffmpeg.mplayerhq.hu/ffmpeg-checkout-snapshot.tar.bz2(svn).
? ?如果官网下载有问题的,xplore也提供了1月30的snapshot:下载ffmpeg.

? ?lame下载:当前版本为3.97,http://sourceforge.net/project/showfiles.php?group_id=290&package_id=309?或者到xplore下载lame.
? ?ogg vorbis:这个一般的redhat自带,不需要下载.可以去看看/usr/lib/libvorbis.a在不在,如果不在可以yum install或apt-get install.
? ?xvid下载:http://downloads.xvid.org/downloads/xvidcore-1.1.0.tar.gz,xplore下载xvid.
? ?x264下载:这个可以去ftp://ftp.videolan.org/下寻找最近的snapshot下载,或者svn获取,注意如果ffmpeg是什么时候的,x264的snapshot也应该是什么时候的,不然编译的时候容易报错.ftp://ftp.videolan.org/pub /videolan/x264/snapshots/
? ?xplore下载x264的1月29日的snapshot.
? ?libdts:http://download.chinaunix.net/down.php?id=11568&ResourceID=5785&site=1,xplore下载libdts:
?上面的软件包除了ffmpeg之外,在下载完成后解包,编译的参数都是./configure --prefix=/usr --enable-shared;make;sudo make install

? ?mpeg4 aac/aad2:http://www.audiocoding.com/modules/mydownloads/visit.php?cid=1&lid=25&PHPSESSID=8267ff75b7c18826fe75eb1c15690862,http://www.audiocoding.com/modules/mydownloads/visit.php?cid=1&lid=23&PHPSESSID=8267ff75b7c18826fe75eb1c15690862.
?faac和faad2在下载解包之后需要自己automake生成编译文件.其中faac的1.25版本需要将内置的configure.in文件最后的AM_OUTPUT中的几个续行去掉,并取消分行.然后按照bootstrap里面的操作进行,无非是aclocal -I .;autoheader;libtoolize --automake;automake -a --copy;autoconfig(或者前面的由autoreconf -vif替代);./configure --prefix=/usr --enable-shared;make;sudo make install;
?faad2的2.5版本需要修改内置的configure.in文件,不然会在没有libbmp时编译会通不过.找到configure.in中下面一段:

引用

if test x$WITHBMP = xyes; then
?AC_DEFINE([HAVE_BMP],1,[User wants beep media player plugin built])
?AM_CONDITIONAL([HAVE_XMMS],true)
?AM_CONDITIONAL([HAVE_BMP],true)
fi

if test x$WITHDRM = xyes; then
?改成
if test x$WITHBMP = xyes; then
?AC_DEFINE([HAVE_BMP],true)
else
?AC_MSG_NOTICE(no bmp build configured)
?AM_CONDITIONAL([HAVE_BMP],false)
fi

if test x$WITHDRM = xyes; then


?然后autoreconf -vif;./configure --prefix=/usr --enable-shared;make;sudo make install;
? ? ?这里提供两个已经修改好的.只需要make clean;make;sudo make install;的tar包.faac1.25下载,faad2.5下载.

? ?3gp支持:在编译ffmpeg加入--enable-amr_nb --enable-amr_wb的时候,会有提示,下载:http://www.3gpp.org/ftp/Specs/archive /26_series/26.204/26204-510.zip,解压的源代码文件以后把里面的文件都拷贝到ffmpeg的源代码目录下 libavcodec/amrwb_float;然后下载:http://www.3gpp.org/ftp/Specs/archive /26_series/26.104/26104-510.zip,解压得源代码文件以后把里面的文件都拷贝到ffmpeg解包目录下的 libavcodec/amr_float,然后交给ffmpeg编译去做了.
? ?也可以在这里下载这两个包:amrwb_float下载,amr_float下载.

???这些codec都安装完毕之后便可以编译ffmpeg了,编译参数如下:
?./configure --prefix=/usr/local --enable-gpl --enable-shared --enable-mp3lame --enable-amr_nb --enable-amr_wb --enable-amr_if2 --enable-libogg --enable-vorbis --enable-xvid --enable-a52 --enable-a52bin --enable-faadbin --enable-dts --enable-pp --enable-faad --enable-faac --enable-x264 --enable-pthreads --disable-ffserver --disable-ffplay
?make
?(sudo make install)
?然后就可以尝试用ffmpeg做视频转换截图了.

???3)mencoder篇
? ?首先获取mplayer软件包极其mplayer官网上自带的codecs.如果喜欢mplayer,也可以下载gui和font.关于 mplayer-1.0rc1在71.21的/home/zhengyu/tools中能找到.如果需要网上下载,可以去官网:http: //www.mplayerhq.hu/design7/dload.html.下载rc1地址如下:http://www1.mplayerhq.hu /MPlayer/releases/MPlayer-1.0rc1.tar.bz2.最新的svn版本:http: //www1.mplayerhq.hu/MPlayer/releases/mplayer-checkout-snapshot.tar.bz2.官网同时也给出了一些codec,其中就有rm格式的codec:http://www1.mplayerhq.hu/MPlayer/releases /codecs/essential-20061022.tar.bz2(x86).
? ? xplore也提供下载,mplayer1.0rc1下载,codec下载.

? ?下载完成之后,将tar vxjf essential-20061022.tar.bz2;sudo mkdir -p /usr/lib/codecs;sudo cp -rf essential-20061022/* /usr/lib/codecs;然后解包mplayer,按如下方式编译:

./configure --prefix=/usr/local --enable-gui --enable-largefiles ?--enable-gif --enable-png --enable-jpeg --language=zh_CN --with-codecsdir=/usr/lib/codecs/
make
(sudo make install)

? ?然后就可以使用mencoder,当然也有一个没有gui的mplayer可以播放各种视频了.不过我们需要的是mencoder.至此,ffmpeg+mencoder搭建完成.

2.常见操作说明
?对于ffmpeg,可以将除swf,rmvb,wmav9以外的视频/音频格式转换成flv/mp3,同时可以截取这些视频文件中的某个时间的该帧图片.这些实际上就是一个视频播客显示的部分.对于mencoder,支持各种常见格式的视频/音频转换成flv/mp3.或者转换成avi.
?1)ffmpeg篇:
?ffmpeg的命令行参数因为太多,这里不列出,可以用ffpmeg -h可以查看到.列出非高级参数如下:

引用

Main options:
-L ? ? ? ? ? ? ? ? ?show license
-h ? ? ? ? ? ? ? ? ?show help
-version ? ? ? ? ? ?show version
-formats ? ? ? ? ? ?show available formats,codecs,protocols,...
-f fmt ? ? ? ? ? ? ?force format
-i filename ? ? ? ? input file name
-y ? ? ? ? ? ? ? ? ?overwrite output files
-t duration ? ? ? ? set the recording time
-fs limit_size ? ? ?set the limit file size
-ss time_off ? ? ? ?set the start time offset
-itsoffset time_off ?set the input ts offset
-title string ? ? ? set the title
-timestamp time ? ? set the timestamp
-author string ? ? ?set the author
-copyright string ? set the copyright
-comment string ? ? set the comment
-album string ? ? ? set the album
-v verbose ? ? ? ? ?control amount of logging
-target type ? ? ? ?specify target file type ("vcd","svcd","dvd","dv","dv50","pal-vcd","ntsc-svcd",...)
-dframes number ? ? set the number of data frames to record
-scodec codec ? ? ? force subtitle codec ('copy' to copy stream)
-newsubtitle ? ? ? ?add a new subtitle stream to the current output stream
-slang code ? ? ? ? set the ISO 639 language code (3 letters) of the current subtitle stream

Video options:
-vframes number ? ? set the number of video frames to record
-r rate ? ? ? ? ? ? set frame rate (Hz value,fraction or abbreviation)
-s size ? ? ? ? ? ? set frame size (WxH or abbreviation)
-aspect aspect ? ? ?set aspect ratio (4:3,16:9 or 1.3333,1.7777)
-croptop size ? ? ? set top crop band size (in pixels)
-cropbottom size ? ?set bottom crop band size (in pixels)
-cropleft size ? ? ?set left crop band size (in pixels)
-cropright size ? ? set right crop band size (in pixels)
-padtop size ? ? ? ?set top pad band size (in pixels)
-padbottom size ? ? set bottom pad band size (in pixels)
-padleft size ? ? ? set left pad band size (in pixels)
-padright size ? ? ?set right pad band size (in pixels)
-padcolor color ? ? set color of pad bands (Hex 000000 thru FFFFFF)
-vn ? ? ? ? ? ? ? ? disable video
-vcodec codec ? ? ? force video codec ('copy' to copy stream)
-sameq ? ? ? ? ? ? ?use same video quality as source (implies VBR)
-pass n ? ? ? ? ? ? select the pass number (1 or 2)
-passlogfile file ? select two pass log file name
-newvideo ? ? ? ? ? add a new video stream to the current output stream

Subtitle options:
-scodec codec ? ? ? force subtitle codec ('copy' to copy stream)
-newsubtitle ? ? ? ?add a new subtitle stream to the current output stream
-slang code ? ? ? ? set the ISO 639 language code (3 letters) of the current subtitle stream

Audio/Video grab options:
-vd device ? ? ? ? ?set video grab device
-vc channel ? ? ? ? set video grab channel (DV1394 only)
-tvstd standard ? ? set television standard (NTSC,PAL (SECAM))
-ad device ? ? ? ? ?set audio device
-grab format ? ? ? ?request grabbing using
-gd device ? ? ? ? ?set grab device

Advanced options:
-map file:stream[:syncfile:syncstream] ?set input stream mapping
-map_meta_data outfile:infile ?set meta data information of outfile from infile
-benchmark ? ? ? ? ?add timings for benchmarking
-dump ? ? ? ? ? ? ? dump each input packet
-hex ? ? ? ? ? ? ? ?when dumping packets,also dump the payload
-re ? ? ? ? ? ? ? ? read input at native frame rate
-loop_input ? ? ? ? loop (current only works with images)
-loop_output ? ? ? ?number of times to loop output in formats that support looping (0 loops forever)
-threads count ? ? ?thread count
-vsync ? ? ? ? ? ? ?video sync method
-async ? ? ? ? ? ? ?audio sync method
-vglobal ? ? ? ? ? ?video global header storage type
-copyts ? ? ? ? ? ? copy timestamps
-shortest ? ? ? ? ? finish encoding within shortest input
-dts_delta_threshold ? timestamp discontinuity delta threshold
-ps size ? ? ? ? ? ?set packet size in bits
-muxdelay seconds ? set the maximum demux-decode delay
-muxpreload seconds ?set the initial demux-decode delay



? ? ?如果这些都明白了,并且有编程基础,你就可以去参与ffmpeg开发了.其实这些堆积起来的命令95%一般是用不上的.这里介绍一些简单的常见的命令:
-fromats 显示可用的格式
-f fmt 强迫采用格式fmt
-I filename 输入文件
-y 覆盖输出文件
-t duration 设置纪录时间 hh:mm:ss[.xxx]格式的记录时间也支持(截图需要)
-ss position 搜索到指定的时间 [-]hh:mm:ss[.xxx]的格式也支持
-title string 设置标题
-author string 设置作者
-copyright string 设置版权
-comment string 设置评论
-target type 设置目标文件类型(vcd,svcd,dvd),所有的格式选项(比特率,编解码以及缓冲区大小)自动设置,只需要输入如下的就可以了:ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg
-hq 激活高质量设置

-b bitrate 设置比特率,缺省200kb/s
-r fps 设置帧频,缺省25
-s size 设置帧大小,格式为WXH,缺省160X128.下面的简写也可以直接使用:Sqcif 128X96 qcif 176X144 cif 252X288 4cif 704X576
-aspect aspect 设置横纵比 4:3 16:9 或 1.3333 1.7777
-croptop/botton/left/right size 设置顶部切除带大小,像素单位
-padtop/botton/left/right size 设置顶部补齐的大小,像素单位
-padcolor color 设置补齐条颜色(hex,6个16进制的数,红:绿:蓝排列,比如 000000代表黑色)
-vn 不做视频记录
-bt tolerance 设置视频码率容忍度kbit/s
-maxrate bitrate设置最大视频码率容忍度
-minrate bitreate 设置最小视频码率容忍度
-bufsize size 设置码率控制缓冲区大小
-vcodec codec 强制使用codec编解码方式. 如果用copy表示原始编解码数据必须被拷贝.(很重要)

-ab bitrate 设置音频码率
-ar freq 设置音频采样率
-ac channels 设置通道,缺省为1
-an 不使能音频纪录
-acodec codec 使用codec编解码

-vd device 设置视频捕获设备,比如/dev/video0
-vc channel 设置视频捕获通道 DV1394专用
-tvstd standard 设置电视标准 NTSC PAL(SECAM)
-dv1394 设置DV1394捕获
-av device 设置音频设备 比如/dev/dsp

-map file:stream 设置输入流映射
-debug 打印特定调试信息
-benchmark 为基准测试加入时间
-hex 倾倒每一个输入包
-bitexact 仅使用位精确算法?用于编解码测试
-ps size 设置包大小,以bits为单位
-re 以本地帧频读数据,主要用于模拟捕获设备
-loop 循环输入流。只工作于图像流,用于ffserver测试

? ? ?ffmpeg进行操作的常用方法:

? ?1.转换成flv文件:ffmpeg -i infile.* -y (-ss second_offset -ar ar -ab ab -r vr -b vb -s vsize) outfile.flv
? ? ? ? ? ? ? 其中second_offset是从开始的多好秒钟.可以支持**:**:**格式,至于ar,ab是音频的参数,可以指定 ar=22050,24000,44100(PAL制式),48000(NTSC制式),后两种常见,ab=56(视音频协议的codec而定,如果要听高品质,则80以上).vr,vb,vsize是视频参数,可以指定 vr=15,25(PAL),29(NTSC),vb=200,500,800,1500(视视频协议的codec而定,可以通过查看专业的codec说明文档获取,如果你手头有一份详细的各种codec的文档,请提供一份给我,不胜感激.)
? ? ? ? ? ? ? 还有一些参数-acodec ac -vcodec vc(ac指定音频codec,ar和ab可以省去,vc指定视频codec,vr和vb可以省去,自动采用相应的codec参数)
? ? ? ? ? ? ? 还有很多高级参数,如-qmin,-qcale等,请查看详细文档.
? ? ? ? ? ? ? 还有-an和-vn参数,分别从多媒体文件中提取出纯粹视频和音频.
? ? ? ? ? ? ? 另,如果你是用shell批量处理,请使用-y参数覆盖生成flv.

? ?2.截取图片:ffmpeg -i infile.* -y (-ss second_offset) -t 0.001 -s msize (-f image_fmt) outfile.jpg
? ? ? ? ? ? 其中second_offset同上,msize同vsize,图片大小.image_fmt=image2强制使用jpg,image_fmt=gif,强制使用gif格式.
? ? ? ? ? ? 还可以用-vframes fn指定截取某帧图片,fn=1,2,3,...

?
?2)mencoder篇:
?mencoder的作用主要在视频转码方面.在安装完mplayer后,mencoder也编译生成了.可以man mencoder获取mencoder的说明文档.
?mencoder的参数更加复杂,不过也无非是音频处理视频处理两个方面,可以参看网络例子:http://www.masoncn.com/post/144.html.这里不作详细的列举了.

? ?mencoder进行操作的常用方法: mencoder infile.* -o outfile.* [-ovc 目标视频格式] [-oac 目标音频格式] [-of 目标文件格式]

? ?1.转换成flv文件: mencoder infile.* -o outfile.flv -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=150:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -srate 22050
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? mencoder infile.rmvb -o outfile.flv -vf scale=-3:150 -ofps 12 -oac mp3lame -ovc xvid -xvidencopts bitrate=112?

? ?2.转换成avi文件: mencoder infile.* -o outfile.avi -of avi -oac mp3lame -lameopts preset=64 -ovc xvid -xvidencopts bitrate=600

? ?3.转换成wmv文件(复杂写法,其中高级参数可以省去): mencoder infile.* -o outfile.wmv -of lavf -ofps 25 -oac mp3lame -lameopts cbr:preset=128 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=768:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -vf scale=320:240 -srate 22050 -sws 9 -subcp cp936 -subpos 0 -subalign 0 -subfont-text-scale 3 -lavfopts i_certify_that_my_video_strea

? ?4.截图: ?mplayer infile -ss START_TIME -noframedrop -nosound -vo jpeg -frames N

? ?其中-ovc,-oac和-of是必须的,-ovc是指定视频codec,指定了ovc之后通常带一个该codec的opt参数,-oac是指定音频 codec,也会在其后带一个codec的opt参数.可以指定细节以决定视频音频质量和转换速率.具体的细节可以参看专业的技术文档.

3.个人的一些心得
?在视频播客网站上,对于音视频本身一般存在如下几个问题:
? ?1)有些格式的音视频文件不支持.不能做到全的问题.
? ?2)上传的同样内容,但不同格式音视频排重的问题.从存储和应用两个方面描述这个问题会有不同层次的解决方案.
? ?3)对于某些格式的音视频文件,既有可能是纯粹音频的,也可以是纯粹视频的.如rm格式.怎样区分这种文件以方便应用的问题.
? ?4)音视频检索,视频描述能不能做到内容方式而不是用户定义关键字的方式.
? ?5)音视频相似度的利用和处理.
? ?6)音视频文件的下载获取.

? ?对于第一个问题采用ffmpeg+mencoder可以获取一个让人可以接受的解决办法.第三个问题可以在上传之后安装一个前端过滤程序,区分音频文件和视频文件,已经有相应的开源工具和代码做这些事情.对于第二个问题,首先是统一格式,然后计算音视频文件的hash,在存储部分采用分布式CAS技术存储,应用方面构架在CAS之上.而第四个问题,第五个问题有待深入研究.第六个问题可以考虑p2p的方式,不过这个不是太重要.
? ? 对于采用shell在ffmpeg+mencoder+MediaInfo环境下处理视频队列和截取视频文件,可以参看这篇文章.

博文来源:http://www.voidcn.com/article/p-xjelftow-bdw.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读