Sunday, December 4, 2016

Combining audio with different sample and bit rates with a video track


There's lots of way to go about changing sample rates, bit rates, merging files, and most result in noise.  There likely is a way to do it all in one sox command line, if one has a lifetime to play with sox flags, and most wav merge tools I tried produced static, but conversion to a Matroska container just worked.   The below steps are simple, and they provide the wanted result.

Audio from one source (Cannon SX260HS camera, in file 16-edgeofsteel.wav ) is at 16bit 48khz and audio from another source (Zoom H4N, in file 16-edgeofsteel2.wav) is at 24bit 96khz.  Video track is 1080p from the Cannon SX260HS (in file edgeofsteel.mov).

1) Up sample 16-edgeofsteel2.wav from 48k to 96k using sox:

sox 16-edgeofsteel2.wav 16-edgeofsteel-96.wav rate 96000

2) Put both .wav files into to a .mkv container using ffmpeg:

ffmpeg -i 16-edgeofsteel.wav  -acodec aac -strict -2 -b:a 500k 16-edgeofsteel3.mkv

ffmpeg -i 16-edgeofsteel-96.wav -acodec aac -strict -2 -b:a 500k 16-edgeofsteel4.mkv

3) Merge the .mkv files using mkvmerge:

mkvmerge -o 16-edgeofsteel-final.mkv 16-edgeofsteel3.mkv +16-edgeofsteel4.mkv

4) Combine the audio and video tracks into one file:

ffmpeg -i 16-edgeofsteel-final.mkv -i edgeofsteel.mov -acodec copy -vcodec copy 16-edgeofsteel.mkv -y

Here the results below, the transition is at 4:20:



  • --------

    Some more tricks, I mixed a track from a CD in with a live clip and kept the last 29 seconds of the live sound:

    1) Put final 29 seconds from video into aac file:

    ffmpeg -i 20140503_195452.mp4 -ss 00:04:40 -t 00:05:09 -acodec copy wolf2.aac -y

    2) Convert to FLAC:

    ffmpeg -i wolf2.aac -f flac wolf2.flac

    3) Cut 4:40 out of the studio track:

    ffmpeg -i 11.Wolf_and_Dog.flac -ss 00:00:01 -t 00:04:41 -acodec copy wolf.flac -y
    4) Convert to 48k so it matches the sample rate of the video:

    sox wolf.flac wolf48.flac rate 48000
    5) Combine the two audio tracks:

    sox wolf48.flac wolf2.flac wolftotal.flac

    6) Combine the video and complete audio track:

    ffmpeg -i wolftotal.flac -i 20140503_195452.mp4 -acodec copy -vcodec copy wolf.mkv -y

    Results below, sound transition at 4:40


    ReVamp - Wolf and Dog Live Slim's San Francisco


    Replacing audio on a video:

    ffmpeg -i 01_Sonata_Arctica_-_Wolf_And_Raven_2001.VOB -i 16_-_Wolf___Raven__Remake_2008_.flac -vcodec copy -acodec copy -map 0:v -map 1:a -strict -2 output.mp4


    No comments:

    Post a Comment