Separate Audio from Video withΒ ffmpeg and Powershell

Hello πŸ‘‹,

A while ago I wrote an article on how to separate audio from video with ffmpeg on Linux using bash. The article can be read here:

Now I want to introduce you to the Windows version with some little Powershell functions that I’ve wrote.

But why?

If you’re a content creator and you are not using the free program Audacity for editing your audio files, I believe you’re missing out on some great features. In my opinion, the noise gate feature is very usefull for eliminating background sounds and breaths from your audio. My PC fan and keyboard strokes are pretty loud and I can easily eliminate them with these settings:

I tested both the Final Cut Pro and Davinci’s Resolve voice isolation feature and I find that the Noise Gate from Audacity works best for me.

My Workflow

I have an raw and unedited video which I record with OBS, then I split the audio by running:

 Split-Video .\InstallDockerAndDockerCompose.mkv

Then I open up the audio file InstallPythonAndPycharmTemp.aup3 in Audacity, apply my desired effects and save the file in the same directory with the name InstallDockerAndDockerComposeTemp.wav.

Then I run:

Join-Video .\InstallDockerAndDockerCompose.mkv

And it will give me the final video named InstallDockerAndDockerComposeFinal.mp4 with the audio edited in Audacity! πŸ˜„

Powershell Functions

You can add these functions to your PowerShell profile by typing code $PROFILE. It should open a Visual Studio Code instance and your PS profile file.

Then paste the following functions into the file:

function global:Split-Video {
  [CmdletBinding()]
  [Alias('vsplit')]
  param (
    [Parameter(Mandatory=$True,Position=0,ValueFromRemainingArguments=$False)]
    [String] $VideoPath
  )
  begin {
    $filename = Get-ChildItem -Path $VideoPath
    $filename_wo_extension = $filename.basename
  }
  process {
    ffmpeg -i "$VideoPath" -vn -c:a copy "${filename_wo_extension}Temp.m4a"
    ffmpeg -i "$VideoPath" -an -c:v copy "${filename_wo_extension}Temp.mp4"
  }
}

function global:Join-Video {
  [CmdletBinding()]
  [Alias('vjoin')]
  param (
    [Parameter(Mandatory=$True,Position=0,ValueFromRemainingArguments=$False)]
    [String] $VideoPath,
    [Parameter(Mandatory=$False,Position=1,ValueFromRemainingArguments=$False)]
    [String] $AudioPath
  )
  begin {
    $filename = Get-ChildItem -Path $VideoPath
    $filename_wo_extension = $filename.basename
    # Test AudioPath for Null
    if ($AudioPath -notmatch '\S') {
      $audio_file = "./${filename_wo_extension}Temp.wav"
    } else {
      $audio_file = $AudioPath
    }
  }
  process {
    ffmpeg -i "./${filename_wo_extension}Temp.mp4" -i "$audio_file" -c:v copy -c:a aac "./${filename_wo_extension}AudioFix.mp4"
    Remove-Item -Force "./${filename_wo_extension}Temp.mp4"
    Remove-Item -Force "./${filename_wo_extension}Temp.m4a"
  }
}

Ensure that you have ffmpeg installed. I’ve installed it with:

choco install ffmpeg

Conclusion

Thanks for reading!

What do you think about this workflow, do you have any ideas how it can be improved?

Denis

How to fix DaVinci Resolve audio issues on Ubuntu 20.10

Hello πŸ‘‹,

To fix audio issues on a fresh install of DaVinci Resolve 18 on my Ubuntu 20.10 PC I did the following things:

1. List all the available sound cards

cat /proc/asound/cards
 0 [NVidia         ]: HDA-Intel - HDA NVidia
                      HDA NVidia at 0xfc080000 irq 94
 1 [AI1            ]: USB-Audio - RODE AI-1
                      RODE Microphones RODE AI-1 at usb-0000:2d:00.3-1.3, full speed
 2 [Generic        ]: HDA-Intel - HD-Audio Generic
                      HD-Audio Generic at 0xfc400000 irq 96
 3 [U0x46d0x81b    ]: USB-Audio - USB Device 0x46d:0x81b
                      USB Device 0x46d:0x81b at usb-0000:2d:00.3-1.4, high speed

List all the available sound cards a chose a default. I like playing audio though my headphones when editing and the headphones are connected to my USB Audio Interface RODE AI-1, this is what I want to use as the default card.

2. Set the default card for Alsa

To set the default card I’ve created a new file /etc/asound.conf and pasted the following contents into it:

   defaults.pcm.card 1
   defaults.ctl.card 1

The number 1 represents the number of the default sound card, in my case it is:

 1 [AI1            ]: USB-Audio - RODE AI-1
                      RODE Microphones RODE AI-1 at usb-0000:2d:00.3-1.3, full speed

After it’s set, reload alsa with: sudo alsa force-reload

3. Start DaVinci Resolve 18 and restart pipewire

Each time you start DaVinci Resolve 18 you may need to run the following command in order to get audio working:

systemctl restart –user pipewire

Note: DaVinci Resolve can’t play AAC audio files on Linux.

Note: Your audio may stop working outside DaVinci resolve while editing and after closing it, to fix it run the above command again.

4. If this breaks your audio on other software

Remove /etc/asound.conf file and restart Alsa & Pipewire. We need to wait for an official fix. 😦


Thanks for reading! I hope you’ll find this useful.

Happy hacking! 🦾