如何复用在Android的MP3和MP4文件 [英] How to multiplex mp3 and mp4 files in Android

查看:300
本文介绍了如何复用在Android的MP3和MP4文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题陈述: 我设计一个Android应用程序中,我得从用户的画廊图像,结合他们做一个视频文件,并添加背景音乐。我已经使用ĴcodeC库上使用我的形象资源,打造MP4视频文件(我知道如何从库获得的图像,并显示在ImageViews并从中创建位图)。我有一个MP4文件。现在,我想用一个MP3文件添加背景音乐在里面。

Problem statement: I am designing an android app in which I have to get images from the user's gallery, combine them to make a video file and add background music. I have used jcodec library to create mp4 video file using my image resources (I know how to get images from gallery and show them in ImageViews and create bitmaps from them). I have a mp4 file. Now, I want to add background music in it using a mp3 file.

请任何人可以帮助我呢?使用j个codeC我无法添加,或至少我不知道该怎么做。我可以使用任何库,可以做这个工作,但它应该是在Java中,因为我不希望使用NDK。我试过的ffmpeg和Ope​​nCV的Java,但它增加了我的应用程序的大小超过15MB和j codeC已经完成制作的MP4文件的一半工作。

Please can anybody help me with this? I cannot add it using jcodec or atleast I don't know how to do that. I can use any library that can do this job but it should be in Java because I don't want to use ndk. I tried ffmpeg and opencv for java but it increased the size of my app by more than 15MB and jcodec has already done half job of making a mp4 file.

我可以给你的code,我用来做MP4文件。先谢谢了。

I can give you the code that I used to make mp4 file. Thanks in advance.

推荐答案

我觉得ĴcodeC 不支持增加 MP3 < STRONG> MP4 。而 JAVACV 的支持,加上 MP3 MP4

I think JCODEC not support add mp3 in MP4.But JAVACV Support add mp3 in mp4.

从这个链接 HTTPS下载 JAVACV :// github上。 COM / bytedeco / javacv

download JAVACV from this link https://github.com/bytedeco/javacv.

这个库支持图像制作视频,并在MP4外接MP3

code在MP4外接MP3。

注意:它可能无法正常工作的创建从第j codeC MP4,采用JAVACV创建MP4

FrameGrabber grabber1 = new FFmpegFrameGrabber(videoPath);
            FrameGrabber grabber2 = new FFmpegFrameGrabber(audioPath);
            grabber1.start();
            grabber2.start();
            FrameRecorder recorder = new FFmpegFrameRecorder(OutputPath,
                    grabber1.getImageWidth(), grabber1.getImageHeight(), 2);
            recorder.setFormat("mp4");
            recorder.setVideoQuality(1);
            recorder.setFrameRate(grabber1.getFrameRate());
            recorder.setSampleRate(grabber2.getSampleRate());
            recorder.start();
            Frame frame1, frame2 = null;
            long timestamp = -2;
            int count = 0;
            boolean isFirstTime = false;
            boolean isFirstCheck = true;
            while ((frame1 = grabber1.grabFrame())!=null) {
                //frame1 = grabber1.grabFrame();
                frame2 = grabber2.grabFrame();
                recorder.record(frame1);
                recorder.record(frame2);

                }
            recorder.stop();
            grabber1.stop();
            grabber2.stop();
    } catch (org.bytedeco.javacv.FrameGrabber.Exception e) {
            e.printStackTrace();
        } catch (Exception e1) {

        }

这篇关于如何复用在Android的MP3和MP4文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆