Help piping command with file name modification

I’m wanting to convert a number of mkv files which I want to host in Plex to mp4 using ffmpeg.
The code I am using is:
ls -filter *.mkv | %{ ffmpeg -i $_.Name -codec copy $_.Basename + ".mp4"}

So the command I wish to execute for each mkv file in the directory is:
ffmpeg -i Name.mkv -codec copy Name.mp4

It’s important to note that the mp4 file extension is necessary in the above command, as it informs ffmpeg which wrapper to use after it’s unwrapped the mkv container.

I have tried several variations and they all fail. The failure is always either:

  1. The new filename is set as “$_.Basename+.mp4” which causes filename collisions (and besides I want to retain the original filename) or
  2. ffmpeg fails to understand what to do, because the only filename it is being given is the actual name of the file less the mkv file extension, meaning $_Basename .

I thought the way to do this was the variable name ($_Basename) and then add the string text using + "ext", but this does not work. Neither does putting brackets around both the $_Basename and the extension, etc.

what is the mistake I am making?

Fluid,
Welcome to the forum. :wave:t4:

Usually using the subexpression operator helps …

Get-ChildItem -Filter *.mkv | 
	ForEach-Object { 
		ffmpeg -i $_.Name -codec copy $($_.Basename + '.mp4')
	}

thanks!.. lol.
It’s so obvious as a means of expressing a unit, it’s painful; and, yet,… I’m new to powershell and never heard or seen the subexpression operator: I don’t think it would have occurred to me.

thanks again.