Youtube不接受使用javacv从mp4和jpeg生成的mp3
我使用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);也尝试过很多其他的视频编解码器,但是都没有用。
有人知道我做错了什么吗?
发布于 2018-04-15 19:35:53
我终于让它像这样工作了
public static void MergeMp3AndJpegIntoMp4(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.setVideoCodec(avcodec.AV_CODEC_ID_H264 );//AV_CODEC_ID_VORBIS
recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);//AV_CODEC_ID_MP3 //AV_CODEC_ID_AAC
recorder.setFormat("mp4");
recorder.setAudioChannels(2);
recorder.start();
Frame frame = null;
while ((frame = audioFileGrabber.grabFrame())!=null)
{ recorder.record(grabberConverter.convert(ipl));
recorder.record(frame);
}
recorder.stop();
audioFileGrabber.stop();
}
catch (org.bytedeco.javacv.FrameRecorder.Exception e){
e.printStackTrace();
throw e;
}
}https://stackoverflow.com/questions/49816845
复制相似问题