【发布时间】:2018-09-23 19:18:37
【问题描述】:
Youtube 不接受我用 javacv 从 mp3 和 jpeg 生成的 mp4
我正在使用 youtube java api 上传这个并且上传时没有抛出异常。我在下面粘贴的错误仅在我访问 youtube 网站时发生。要么查看上传的视频,要么手动上传视频。
mp4 文件的长度为 00:59,大小为 506 kb,所以我认为这不是问题。
这是代码:
public static void MergeMp3Mp4JavaCv(String path2ImageFile,String path2AudioFile, String path2OutputFile) throws IOException
{
IplImage ipl = cvLoadImage(path2ImageFile);
int height = ipl.height();
int width = ipl.width();
if(height%2!=0) height = height+1;
if(width%2!=0) width = width+1;
OpenCVFrameConverter.ToIplImage grabberConverter = new OpenCVFrameConverter.ToIplImage();
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(path2OutputFile,width,height);
FrameGrabber audioFileGrabber = new FFmpegFrameGrabber(path2AudioFile);
try
{
audioFileGrabber.start();
recorder.setFrameRate(1);
recorder.setVideoBitrate(audioFileGrabber.getAudioBitrate());
recorder.setFormat("mp4");
recorder.setAudioChannels(1);
recorder.start();
recorder.record(grabberConverter.convert(ipl));
Frame frame = null;
while ((frame = audioFileGrabber.grabFrame())!=null)
{
recorder.record(frame);
}
recorder.stop();
audioFileGrabber.stop();
}
catch (org.bytedeco.javacv.FrameRecorder.Exception e){
e.printStackTrace();
}
}
Youtube 说:
视频处理失败。请确保您正在上传 支持的文件类型。
编辑:文件在 Windows 媒体播放器中完美播放
编辑 2:
我检查了
https://support.google.com/youtube/answer/1722171?hl=en
Audio codec: AAC-LC
Channels: Stereo or Stereo + 5.1
Sample rate 96khz or 48khz
Video codec: H.264
Progressive scan (no interlacing)
High Profile
2 consecutive B frames
Closed GOP. GOP of half the frame rate.
CABAC
Variable bitrate. No bitrate limit required, though we offer recommended bit rates below for reference
Chroma subsampling: 4:2:0
我试过了
recorder.setAudioCodec(avcodec.AV_CODEC_ID_H264 );
recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);
也尝试了很多其他视频编解码器,但没有任何效果。
有谁知道我做错了什么?
【问题讨论】:
-
视频是否在您的媒体播放器上播放?
-
@j_d 是的,确实如此,我编辑了这个问题,抱歉没有提到这个
-
没关系。YouTube 视频上传失败的原因有很多。这可能与用于 mp4 的编解码器有关。也许对 YouTube 视频公认的编解码器进行一些研究会有所帮助。
-
在这种情况下,sed 编解码器应该是 opencv,对吧?
-
不,不是。请查看this 问题,了解如何为 FFmpegFrameRecorder 设置编解码器。
标签: java youtube-api mp3 mp4 javacv