62,625
社区成员
发帖
与我相关
我的任务
分享package com.slit.zhuanma.test;
import java.util.ArrayList;
import java.util.List;
public class ExecuteCodecs {
public static void main(String[] args) {
ExecuteCodecs ecs = new ExecuteCodecs();
String ffmpegPath = "d:\\FFmpeg\\bin\\ffmpeg.exe"; // ffmpeg.exe的目录
String upFilePath = "E:\\video\\old\\test1.mp4";
String codcFilePath = "E:\\video\\succ.mp4"; // 截图的视频目录;
try {
ecs.exchangeToMp4(ffmpegPath, upFilePath, codcFilePath);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 视频转码 (PC端MP4)
* @param ffmpegPath 转码工具的存放路径
* @param upFilePath 用于指定要转换格式的文件,要截图的视频源文件
* @param codcFilePath 格式转换后的的文件保存路径
* @return
* @throws Exception
*/
public boolean exchangeToMp4(String ffmpegPath, String upFilePath, String codcFilePath) throws Exception {
// 创建List集合来保存转换视频文件为flv格式的命令
List<String> convert = new ArrayList<String>();
convert.add(ffmpegPath); // 添加转换工具路径
convert.add("-y"); // 该参数指定将覆盖已存在的文件
convert.add("-i");
convert.add(upFilePath);
convert.add("-c:v");
convert.add("libx264");
convert.add("-c:a");
convert.add("aac");
convert.add("-strict");
convert.add("-2");
convert.add("-pix_fmt");
convert.add("yuv420p");
convert.add("-movflags");
convert.add("faststart");
//convert.add("-vf"); // 添加水印
//convert.add("movie=watermark.gif[wm];[in][wm]overlay=20:20[out]");
convert.add(codcFilePath);
boolean mark = true;
try {
Process videoProcess = new ProcessBuilder(convert).redirectErrorStream(true).start();
new PrintStream(videoProcess.getInputStream()).start();
//videoProcess.waitFor(); // 加上这句,系统会等待转换完成。不加,就会在服务器后台自行转换。
} catch (Exception e) {
mark = false;
System.out.println(e);
e.printStackTrace();
}
return mark;
}
}
ffmpeg version N-87353-g183fd30 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib
libavutil 55. 76.100 / 55. 76.100
libavcodec 57.106.101 / 57.106.101
libavformat 57. 82.101 / 57. 82.101
libavdevice 57. 8.101 / 57. 8.101
libavfilter 6.105.100 / 6.105.100
libswscale 4. 7.103 / 4. 7.103
libswresample 2. 8.100 / 2. 8.100
libpostproc 54. 6.100 / 54. 6.100
[mp2 @ 00000000005682a0] Header missing
Last message repeated 15 times
[mpeg @ 00000000004d8680] decoding for stream 1 failed
[mpeg @ 00000000004d8680] Could not find codec parameters for stream 1 (Audio: mp2, 0 channels, s16p): unspecified frame size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mpeg, from 'E:\video\old\test1.mp4':
Duration: 00:31:05.19, start: 20910.836067, bitrate: 1092 kb/s
Stream #0:0[0x1e0]: Video: h264 (Baseline), yuv420p(progressive), 1024x768, 30 fps, 100 tbr, 90k tbn, 60 tbc
Stream #0:1[0x1c0]: Audio: mp2, 0 channels, s16p
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (mp2 (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 00000000005ce540] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 00000000005ce540] profile High, level 3.1
[libx264 @ 00000000005ce540] 264 - core 152 r2851 ba24899 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
frame= 90 fps=0.0 q=0.0 size= 0kB time=-577014:32:22.77 bitrate= -0.0kbits/s speed=N/A
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
frame= 145 fps=141 q=0.0 size= 0kB time=-577014:32:22.77 bitrate= -0.0kbits/s speed=N/A
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
[mp2 @ 0000000002829b20] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
Too many packets buffered for output stream 0:0.
[libx264 @ 00000000005ce540] frame I:1 Avg QP:20.47 size:151888
[libx264 @ 00000000005ce540] frame P:36 Avg QP:20.72 size: 6987
[libx264 @ 00000000005ce540] frame B:92 Avg QP:30.81 size: 436
[libx264 @ 00000000005ce540] consecutive B-frames: 2.3% 6.2% 2.3% 89.2%
[libx264 @ 00000000005ce540] mb I I16..4: 16.1% 11.5% 72.4%
[libx264 @ 00000000005ce540] mb P I16..4: 0.5% 0.6% 0.3% P16..4: 11.3% 2.4% 2.2% 0.0% 0.0% skip:82.7%
[libx264 @ 00000000005ce540] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 3.5% 0.5% 0.2% direct: 0.2% skip:95.5% L0:40.7% L1:51.6% BI: 7.7%
[libx264 @ 00000000005ce540] 8x8 transform intra:22.4% inter:29.9%
[libx264 @ 00000000005ce540] coded y,uvDC,uvAC intra: 63.4% 61.8% 28.5% inter: 2.4% 2.8% 0.3%
[libx264 @ 00000000005ce540] i16 v,h,dc,p: 58% 21% 9% 12%
[libx264 @ 00000000005ce540] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 17% 22% 41% 3% 2% 3% 3% 2% 5%
[libx264 @ 00000000005ce540] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 24% 11% 6% 7% 6% 8% 5% 10%
[libx264 @ 00000000005ce540] i8c dc,h,v,p: 51% 21% 21% 7%
[libx264 @ 00000000005ce540] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 00000000005ce540] ref P L0: 84.0% 8.8% 5.9% 1.2%
[libx264 @ 00000000005ce540] ref B L0: 94.5% 4.9% 0.6%
[libx264 @ 00000000005ce540] ref B L1: 96.5% 3.5%
[libx264 @ 00000000005ce540] kb/s:825.11
Conversion failed!