title: Transcode PCM Audio to MP3 using MediaTranscoder with C#
body: <p>I am trying to transcode a PCM formatted audio file that I saved from a WebRTC call. The format of the audio stream, reported by WebRTC, is 16 bit depth, 1 channel and 48000 Hz sample rate. I want to convert the audio to MP3 so I can add the audio as a background track to a screen recording of my Unity UWP app afterwards (using MediaComposition). I'm having trouble with the first part: trying to transcode my PCM audio file to a MP3 file. <code>preparedTranscodeResult.CanTranscode</code> is returning <code>false</code> when I try to prepare the transcode. The following is my code.</p>
  
  <pre class="lang-cs prettyprint-override"><code>StorageFile remoteAudioPCMFile = await StorageFile.GetFileFromPathAsync(Path.Combine(Application.temporaryCachePath, "remote.pcm").Replace("/", "\\"));
  StorageFolder tempFolder = await StorageFolder.GetFolderFromPathAsync(Application.temporaryCachePath.Replace("/", "\\"));
  StorageFile remoteAudioMP3File = await tempFolder.CreateFileAsync("remote.mp3", CreationCollisionOption.ReplaceExisting);
  
  MediaEncodingProfile profile = MediaEncodingProfile.CreateMp3(AudioEncodingQuality.Auto);
  profile.Audio.BitsPerSample = 16;
  profile.Audio.ChannelCount = 1;
  profile.Audio.SampleRate = 48000;
  
  MediaTranscoder transcoder = new MediaTranscoder();
  var preparedTranscodeResult = await transcoder.PrepareFileTranscodeAsync(remoteAudioPCMFile, remoteAudioMP3File, profile);
  
  if (preparedTranscodeResult.CanTranscode)
  {
      await preparedTranscodeResult.TranscodeAsync();
  }
  else
  {
      if (remoteAudioPCMFile != null)
      {
          await remoteAudioPCMFile.DeleteAsync();
      }
  
      if (remoteAudioMP3File != null)
      {
          await remoteAudioMP3File.DeleteAsync();
      }
  
      switch (preparedTranscodeResult.FailureReason)
      {
          case TranscodeFailureReason.CodecNotFound:
              Debug.LogError("Codec not found.");
              break;
          case TranscodeFailureReason.InvalidProfile:
              Debug.LogError("Invalid profile.");
              break;
          default:
              Debug.LogError("Unknown failure.");
              break;
      }
  }
  </code></pre>