Youtube 不接受我用 javacv 从 mp3 和 jpeg 生成的 mp4

Youtube doesn't accept the mp4 I generate with javacv from an mp3 and a jpeg

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 说:

The video has failed to process. Please make sure you are uploading a supported file type.

编辑:文件在 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);

也尝试了很多其他视频编解码器,但没有任何效果。
有谁知道我做错了什么?

我最终设法让它像这样工作

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;
         }  

    }