Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Java将ogv视频文件转换为Mp4视频格式_Java_Video_Ffmpeg - Fatal编程技术网

如何使用Java将ogv视频文件转换为Mp4视频格式

如何使用Java将ogv视频文件转换为Mp4视频格式,java,video,ffmpeg,Java,Video,Ffmpeg,我需要将OGV视频格式转换为MP4视频格式 我使用下面的Java代码将MP4视频格式转换为OGV视频格式,工作正常 对于MP4格式,我使用audio.setCodec(“AudioAttributes.DIRECT\u STREAM\u COPY”)和video.setCodec(“VideoAttributes.DIRECT\u STREAM\u COPY”) 但是,如果我通过更改audio.setCodec(“libvorbis”)和video.setCodec(“mpeg4”)来使用相同

我需要将OGV视频格式转换为MP4视频格式

  • 我使用下面的Java代码将MP4视频格式转换为OGV视频格式,工作正常
  • 对于MP4格式,我使用audio.setCodec(“AudioAttributes.DIRECT\u STREAM\u COPY”)和video.setCodec(“VideoAttributes.DIRECT\u STREAM\u COPY”)
  • 但是,如果我通过更改audio.setCodec(“libvorbis”)和video.setCodec(“mpeg4”)来使用相同的代码,它不会从Ogv转换为Mp4格式。我还在我的示例程序中尝试了一些编解码器

  • 我无法从Ogv转换为Mp4格式


我不完全确定您使用的是什么库,但MPEG-4容器格式支持多种不同的视频和音频编解码器

我看到音频的
libfaac
,这让我假设您使用的是基于ffmpeg的东西

对于视频,您可能需要H.264/MPEG-4 AVC,在这种情况下,您将使用
libx264
作为视频编码器。我从来没有见过mpeg4视频编码格式。

我想,你需要JAVE(Java音频视频编码器)库,所以我更改了setCodecAudioAttributes。DIRECT\u STREAM\u COPY

public class VideoConvert {
public static void main(String[] args) throws IOException {
File source = new File("D:\\video\\mp4\\Sample.ogv");
File target = new File("D:\\video\\ogv\\Sample.mp4");
AudioAttributes audio = new AudioAttributes();
audio.setCodec(AudioAttributes.DIRECT_STREAM_COPY);
audio.setBitRate(new Integer(128000));
audio.setSamplingRate(new Integer(44100));
audio.setChannels(new Integer(2));
VideoAttributes video = new VideoAttributes();
video.setBitRate(new Integer(160000));
video.setFrameRate(new Integer(15));
video.setCodec("mpeg4");
video.setCodec(VideoAttributes.DIRECT_STREAM_COPY);
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp4");
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
Encoder encoder = new Encoder();
try {
    encoder.encode(source, target, attrs);
} catch (IllegalArgumentException e) {
    e.printStackTrace();
} catch (InputFormatException e) {
    e.printStackTrace();
} catch (EncoderException e) {
    e.printStackTrace();
}

}

请使用代码标签我使用Jave作为库,我使用音频编解码器作为“setCodec(libfaac)”,视频编解码器使用“setCodec(mpeg4)”。对于编码,我使用“setFormat(mpegvideo)”,它工作得很好,但视频质量很差。对于这个问题,我应该怎么做?我可以将mp4格式转换为ogv格式。但我无法将ogv转换为mp4格式,最终使其正常工作,
VideoAttributes.DIRECT\u STREAM\u COPY
是keyencoder.encode(新的多媒体对象(源)、目标、属性);
public class VideoConvert {
public static void main(String[] args) throws IOException {
File source = new File("D:\\video\\mp4\\Sample.ogv");
File target = new File("D:\\video\\ogv\\Sample.mp4");
AudioAttributes audio = new AudioAttributes();
audio.setCodec(AudioAttributes.DIRECT_STREAM_COPY);
audio.setBitRate(new Integer(128000));
audio.setSamplingRate(new Integer(44100));
audio.setChannels(new Integer(2));
VideoAttributes video = new VideoAttributes();
video.setBitRate(new Integer(160000));
video.setFrameRate(new Integer(15));
video.setCodec("mpeg4");
video.setCodec(VideoAttributes.DIRECT_STREAM_COPY);
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp4");
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
Encoder encoder = new Encoder();
try {
    encoder.encode(source, target, attrs);
} catch (IllegalArgumentException e) {
    e.printStackTrace();
} catch (InputFormatException e) {
    e.printStackTrace();
} catch (EncoderException e) {
    e.printStackTrace();
}