gpt4 book ai didi

java - 合并两个带音频和不带音频的剪辑会导致音频从生成的视频的开头开始

转载 作者:行者123 更新时间:2023-12-01 18:44:01 24 4
gpt4 key购买 nike

我正在尝试使用 MP4Parser 将两个视频(mp4 文件)(一个有音频,一个没有音频)合并为一个视频。生成的最终视频始终具有从头开始的音频。例如第一个视频时长 20 秒,没有音频。第二个视频时长 10 秒,有音频。最终生成的视频长度为 30 秒,但音频将在视频开头播放 10 秒(其余 20 秒不会有任何音频),而它应该开始 20 秒没有音频,结束 10 秒有音频。

Movie[] clips = new Movie[2];

//location of the movie clip storage
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "TestMerge");

//Build the two clips into movies
Movie firstClip = MovieCreator.build(first);
Movie secondClip = MovieCreator.build(second);

//Add both movie clips
clips[0] = firstClip;
clips[1] = secondClip;

//List for audio and video tracks
List<Track> videoTracks = new LinkedList<Track>();
List<Track> audioTracks = new LinkedList<Track>();

//Iterate all the movie clips and find the audio and videos
for (Movie movie: clips) {
for (Track track : movie.getTracks()) {
if (track.getHandler().equals("soun"))
audioTracks.add(track);
if (track.getHandler().equals("vide"))
videoTracks.add(track);
}
}

//Result movie from putting the audio and video together from the two clips
Movie result = new Movie();

//Append all audio and video
if (videoTracks.size() > 0)
result.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));

if (audioTracks.size() > 0)
result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));

}

我尝试通过更改以下几行来添加静音轨道

//List for audio and video tracks
List<Track> videoTracks = new LinkedList<Track>();
List<Track> audioTracks = new LinkedList<Track>();
Track audioSourceTrack = null;

for (final Movie movie : inMovies) {
for (final Track t : movie.getTracks()) {
if (isAudioTrack(t)) {
audioSourceTrack = t;
break;
}
}
if (audioSourceTrack != null) break;
}

//Iterate all the movie clips and find the audio and videos
for (Movie movie: clips) {
if (movie.getTracks().size() == 1) {
videoTracks.add(movie.getTracks().get(0));
audioTracks.add(new SilenceTrackImpl(audioSourceTrack, movie.getTracks().get(0).getDuration() / 2));
} else {
for (final Track t : movie.getTracks()) {
if (isAudioTrack(t)) {
audioTracks.add(t);
}
if (isVideoTrack(t)) {
videoTracks.add(t);
}
}
}
}

最佳答案

我可以通过附加带有静音轨道的静音剪辑来做到这一点。问题在于,react-native-video 无法像 Q 播放器那样正确播放静音轨道。我必须对视频进行转码才能看到附加静音是否正常工作。

关于java - 合并两个带音频和不带音频的剪辑会导致音频从生成的视频的开头开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59872533/

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