gpt4 book ai didi

java - 如何在android中使用mp4parser在视频上添加水印?

转载 作者:太空宇宙 更新时间:2023-11-04 13:50:27 35 4
gpt4 key购买 nike

我已经使用 mp4parser 成功将录制的视频转换为“out.h264”格式,并将音频转换为“.AAC”格式。现在我想在我录制的视频上实现“水印图像”。 mp4parser 可以在视频上添加水印吗?我也检查了 GPUimages。但是没有办法给视频添加效果,它的example仅显示图像效果。所以我的问题是如何在视频上添加水印?

下面是我的音频视频代码:

    File sdCard = Environment.getExternalStorageDirectory();
IsoFile isoFile = new IsoFile(videosPath);
TrackBox trackBox = (TrackBox) Path.getPath(isoFile, "/moov/trak/mdia/minf/stbl/stsd/avc1/../../../../../");
SampleList sl = new SampleList(trackBox);
File out = new File(sdCard + "/out.h264");
if (out.exists()) {
out.delete();
}
FileChannel fc = new RandomAccessFile(out, "rw").getChannel();
ByteBuffer separator = ByteBuffer.wrap(new byte[] { 0, 0, 0, 1 });

fc.write((ByteBuffer) separator.rewind());
// Write SPS
fc.write(ByteBuffer.wrap(((AvcConfigurationBox) Path.getPath(trackBox, "mdia/minf/stbl/stsd/avc1/avcC")).getSequenceParameterSets().get(0)));
// Warning:
// There might be more than one SPS (I've never seen that but it is possible)

fc.write((ByteBuffer) separator.rewind());
// Write PPS
fc.write(ByteBuffer.wrap(((AvcConfigurationBox) Path.getPath(trackBox, "mdia/minf/stbl/stsd/avc1/avcC")).getPictureParameterSets().get(0)));
// Warning:
// There might be more than one PPS (I've never seen that but it is possible)

int lengthSize = ((AvcConfigurationBox) Path.getPath(trackBox, "mdia/minf/stbl/stsd/avc1/avcC")).getLengthSizeMinusOne() + 1;
for (Sample sample : sl) {
ByteBuffer bb = sample.asByteBuffer();
while (bb.remaining() > 0) {
int length = (int) IsoTypeReaderVariable.read(bb, lengthSize);
fc.write((ByteBuffer) separator.rewind());
fc.write((ByteBuffer) bb.slice().limit(length));
bb.position(bb.position() + length);
}

}
fc.close();

Log.e(TAG, "Converted Path: " + out.getAbsolutePath() + " Start Time Convert: " + new Date());

H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl(out.getAbsoluteFile()));

AACTrackImpl aacTrack = new AACTrackImpl(new FileDataSourceImpl(audioPath));
CroppedTrack aacTrackShort = new CroppedTrack(aacTrack, 1, aacTrack.getSamples().size());
// MP3TrackImpl accTrackImpl = new MP3TrackImpl(new FileDataSourceImpl(audioPath));

Movie movie = new Movie();
movie.addTrack(h264Track);
movie.addTrack(aacTrackShort);

Container mp4file = new DefaultMp4Builder().build(movie);
File output = new File(sdCard + "/output_KanAK.mp4");

if (output.exists()) {
output.delete();
}
@SuppressWarnings("resource")
FileChannel fc1 = new RandomAccessFile(output, "rw").getChannel();
mp4file.writeContainer(fc1);
fc1.close();

Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.velfee);
gpuImage.saveToPictures(largeIcon, output, 100, new OnPictureSavedListener() {

@Override
public void onPictureSaved(Uri uri) {
// TODO Auto-generated method stub
Log.e(TAG, "Picture save Uri");
GPUImageDifferenceBlendFilter filter;
filter.setBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
}
});

如有任何帮助,我们将不胜感激!提前致谢。

最佳答案

您可以使用 github 页面中的字幕示例将字符串用作水印。设置您自己的限制,但您当然无法使用图像。

关于java - 如何在android中使用mp4parser在视频上添加水印?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30349421/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com