我创建了一个类来调整视频大小。我用在人像模式下在手机上拍摄的视频对它进行了测试。视频可以在手机和计算机上的任何媒体播放器展台中以纵向模式正确显示。但是,当使用我的程序调整视频大小时,会正确调整视频大小,但是旋转元数据会丢失。
通过mediainfo查询输入视频的元数据会得到以下输出:
Method: POST
https://graph.facebook.com/860599774051206_4548643168486465/comments?access_token=APP_ID|APP_SECRET
body:
{
"message": "Thanks"
}
如您所见,旋转设置为90度。
这是我的代码:
主要类别: 打包test.video;
General
Complete name : /home/sneese/Downloads/20190708_095754.mp4
Format : MPEG-4
Format profile : Base Media / Version 2
Codec ID : mp42 (isom/mp42)
File size : 22.7 MiB
Duration : 6s 741ms
Overall bit rate : 28.3 Mbps
Encoded date : UTC 2019-07-08 07:58:02
Tagged date : UTC 2019-07-08 07:58:02
com.android.version : 8.0.0
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4.2
Format settings, CABAC : Yes
Format settings, ReFrames : 1 frame
Format settings, GOP : M=1, N=60
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 6s 732ms
Bit rate : 28.0 Mbps
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Rotation : 90°
Frame rate mode : Variable
Frame rate : 60.000 fps
Minimum frame rate : 59.094 fps
Maximum frame rate : 60.934 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.225
Stream size : 22.5 MiB (99%)
Title : VideoHandle
Language : English
Encoded date : UTC 2019-07-08 07:58:02
Tagged date : UTC 2019-07-08 07:58:02
mdhd_Duration : 6732
Audio
ID : 2
Format : AAC
Format/Info : Advanced Audio Codec
Format profile : LC
Codec ID : 40
Duration : 6s 741ms
Source duration : 6s 745ms
Source_Duration_FirstFrame : 3ms
Bit rate mode : Constant
Bit rate : 256 Kbps
Channel(s) : 2 channels
Channel positions : Front: L R
Sampling rate : 48.0 KHz
Frame rate : 46.875 fps (1024 spf)
Compression mode : Lossy
Stream size : 211 KiB (1%)
Source stream size : 211 KiB (1%)
Title : SoundHandle
Language : English
Encoded date : UTC 2019-07-08 07:58:02
Tagged date : UTC 2019-07-08 07:58:02
mdhd_Duration : 6741
MediaToolAdapter: 打包test.video;
import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.xuggler.ICodec;
import com.xuggle.xuggler.IContainer;
import com.xuggle.xuggler.IMetaData;
import com.xuggle.xuggler.IStream;
import com.xuggle.xuggler.IStreamCoder;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
public class MediaConverter {
private static final String INPUT_FILE = "/home/user/input_video.mp4";
private static final String OUTPUT_FILE = "/home/user/output_video.mp4";
public static void main(String[] args) throws IOException {
convertVideo(INPUT_FILE, OUTPUT_FILE, 640, 360);
}
private static void convertVideo(String inputFile, String outputFile, int width, int height){
// reader
IMediaReader reader = ToolFactory.makeReader(inputFile);
Resizer resizer = new Resizer(width, height);
reader.addListener(resizer);
// writer
IMediaWriter writer = ToolFactory.makeWriter(outputFile, reader);
resizer.addListener(writer);
while (reader.readPacket() == null) {
// no need to do anything here just let him read
}
writer.flush();
}
}
预期的结果是,如果转换后的视频是横向模式,则转换后的视频将以纵向模式显示。谢谢