首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Youtube不接受我用javacv从一个mp4和jpeg生成的mp3

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

Stack Overflow用户
提问于 2018-04-13 12:19:38
回答 1查看 260关注 0票数 0

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

我使用youtube java api来上传这个文件,上传时也不会抛出任何异常。一个错误,我粘贴在下面发生时,只有当我去youtube网站。观看上传的视频或手工上传视频。

mp4文件的长度为00:59,大小为506 kb,所以我不认为这是一个问题。

这是代码:

代码语言:javascript
复制
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

代码语言:javascript
复制
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

我试过了

代码语言:javascript
复制
recorder.setAudioCodec(avcodec.AV_CODEC_ID_H264 );
recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);

也尝试过很多其他的视频编解码器,但是都没有用。

有人知道我做错了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-15 19:35:53

我终于让它像这样工作了

代码语言:javascript
复制
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;
         }  

    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49816845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档