MC, 09:09 wtorek, 21.02.2023 r.
Ilustracja do artykułu: Replacing the audio track in the video file - ffmpeg

Replacing the audio track in the video file - ffmpeg

More than three hours of rendering for a long video, and I found a bug in the soundtrack the first time I reviewed it. Rerender? No - I found it faster to generate only the corrected soundtrack and replace it.

How to change the sound in a video file?

It turns out that the problem is not particularly difficult to solve. In fact, it's hard to find a problem that can't be solved with ffmpeg. Just select the source files (in our case, two) and then indicate which information, from which source, we want to have in the result file.

In practice, it looks like this:

ffmpeg -i video_source.mp4 -i audio_source.wav -c:v copy -map 0:v:0 -map 1:a:0 fixed.mp4

How does it work? All the magic happens in this command part: -map 0:v:0 -map 1:a:0. Bearing in mind that the order, or rather indexes, are counted from zero and not from one, we define here that we want to use the video track from the zero source file as the zero video track of the result file and that we want to take the audio track from the first source file as the zero track audio track in the output file.

The video track will remain copied (-c:v copy).

If the audio track in both files uses the same codec, we can ask ffmpeg to clean copy without encoding the audio track as well, then we change the -c flag to: -c copy.

Komentarze (0) - Nikt jeszcze nie komentował - bądź pierwszy!

Imię:
Treść:
Polish version: Podmieniamy ścieżkę dźwiękową w pliku wideo - ffmpeg