我使用了如下命令:

ffmpeg -i video.avi -i audio.mp3 -vcodec codec -acodec codec output_video.avi -newaudio

在最新版本添加新的音轨到视频(不混合)。

但是我更新了ffmpeg到最新版本(ffmpeg版本git-2012-06-16-809d71d),现在在这个版本中参数-newaudio不起作用。

请告诉我如何添加新的音频到我的视频(不混合)使用ffmpeg。


当前回答

取代音频

ffmpeg -i video.mp4 -i audio.wav -map 0:v -map 1:a -c:v copy -shortest output.mp4

The -map option allows you to manually select streams / tracks. See FFmpeg Wiki: Map for more info. This example uses -c:v copy to stream copy (mux) the video. No re-encoding of the video occurs. Quality is preserved and the process is fast. If your input audio format is compatible with the output format then change -c:v copy to -c copy to stream copy both the video and audio. If you want to re-encode video and audio then remove -c:v copy / -c copy. The -shortest option will make the output the same duration as the shortest input.

添加音频

ffmpeg -i video.mkv -i audio.mp3 -map 0 -map 1:a -c:v copy -shortest output.mkv

The -map option allows you to manually select streams / tracks. See FFmpeg Wiki: Map for more info. This example uses -c:v copy to stream copy (mux) the video. No re-encoding of the video occurs. Quality is preserved and the process is fast. If your input audio format is compatible with the output format then change -c:v copy to -c copy to stream copy both the video and audio. If you want to re-encode video and audio then remove -c:v copy / -c copy. The -shortest option will make the output the same duration as the shortest input.

混合/组合两个音频输入为一个

使用video.mkv中的视频。混合音频和视频。MKV和音频。M4a使用合并滤波器:

ffmpeg -i video.mkv -i audio.m4a -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map 0:v -map "[a]" -c:v copy -ac 2 -shortest output.mkv

更多信息请参见FFmpeg Wiki:音频通道。

生成无声音频

你可以使用anullsrc过滤器来制作一个无声的音频流。过滤器允许您选择所需的频道布局(单声道,立体声,5.1等)和采样率。

ffmpeg -i video.mp4 -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 \
-c:v copy -shortest output.mp4

也看到

将两个音频流合并为一个 FFmpeg Wiki:音频通道操作 FFmpeg mux视频和音频从另一个视频

其他回答

如果你正在使用旧版本的FFMPEG,你不能升级,你可以做以下:

ffmpeg -i PATH/VIDEO_FILE_NAME.mp4 -i PATH/AUDIO_FILE_NAME.mp3 -vcodec copy -shortest DESTINATION_PATH/NEW_VIDEO_FILE_NAME.mp4

注意,我使用了-vcodec

这展示了如何用ffmpeg将所有音轨合并到一个完整的目录:

ffmpeg -i video.mp4 -i audio.mp3 -map 0:v -map 1:a -c:v copy -shortest output.mp4

使用ffmpeg将音频添加到视频的代码。

如果音频长度大于视频长度,它会将音频切成视频长度。 如果你想要完整的音频视频删除-最短从cmd。

String [] cmd = new String[]{“我”,“我”,selectedVideoPath audiopath,“地图”、“1:一个”,“地图”、“0:v”、“编码”,“复制”,outputFile.getPath ()};

private void execFFmpegBinaryShortest(final String[] command) {



            final File outputFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/videoaudiomerger/"+"Vid"+"output"+i1+".mp4");




            String[] cmd = new String[]{"-i", selectedVideoPath,"-i",audiopath,"-map","1:a","-map","0:v","-codec","copy","-shortest",outputFile.getPath()};


            try {

                ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
                    @Override
                    public void onFailure(String s) {
                        System.out.println("on failure----"+s);
                    }

                    @Override
                    public void onSuccess(String s) {
                        System.out.println("on success-----"+s);
                    }

                    @Override
                    public void onProgress(String s) {
                        //Log.d(TAG, "Started command : ffmpeg "+command);
                        System.out.println("Started---"+s);

                    }

                    @Override
                    public void onStart() {


                        //Log.d(TAG, "Started command : ffmpeg " + command);
                        System.out.println("Start----");

                    }

                    @Override
                    public void onFinish() {
                        System.out.println("Finish-----");


                    }
                });
            } catch (FFmpegCommandAlreadyRunningException e) {
                // do nothing for now
                System.out.println("exceptio :::"+e.getMessage());
            }


        }

没有什么对我很有效(我想这是因为我输入的。mp4视频没有任何音频),所以我发现这对我很有效:

Ffmpeg -i input_video.mp4 -i balipraavid .wav -map 0:v:0 -map 1:a:0 output.mp4

这些解决方案对我来说都不太管用。我的原始音频被覆盖了,或者我在更复杂的“合并”示例中出现了“未能映射内存”之类的错误。似乎我需要-filter_complex amix。

ffmpeg -i videowithaudioyouwanttokeep.mp4 -i audiotooverlay.mp3 -vcodec copy -filter_complex amix -map 0:v -map 0:a -map 1:a -shortest -b:a 144k out.mkv