title: FFmpeg - H264 encoder could not find a valid device and can't configure encoder
body: <p>I am trying to encode using the H264 encoder, but when I do, I get the following error:</p>
  <pre><code>[h264_v4l2m2m @ 0x55682d2416c0] Could not find a valid device
  [h264_v4l2m2m @ 0x55682d2416c0] can't configure encoder
  </code></pre>
  <p>I made sure that I enabled the encoder when I configured FFmpeg. When I run the command <code>ffmpeg -codecs</code> I see that the H264 codec is listed as an encoder:</p>
  <pre><code>DEV.LS h264    H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
  (decoders: h264 h264_v4l2m2m )
  (encoders: libx264 libx264rgb h264_v4l2m2m h264_vaapi )
  </code></pre>
  <p>The source video's video codec is H264 so I am not sure why I am not able to encode with H264 when there is both a decoder and encoder for it. Even when I run <code>avcodec_find_encoder_by_name</code> to find the <code>libx264</code> encoder, it isn't able to.</p>
  <p>This is the chunk of code where it fails:</p>
  <pre><code>codec = avcodec_find_encoder(AV_CODEC_ID_H264);
  if (!codec) {
      printf(&quot;[ERROR] Failed to find video output codec\n&quot;);
      return -1;
  }
  outputCodecContext = avcodec_alloc_context3(codec);
  if (!outputCodecContext) {
      printf(&quot;[ERROR] Failed to allocate memory for video output codec context\n&quot;);
      return -1;
  }
  av_opt_set(outputCodecContext-&gt;priv_data, &quot;preset&quot;, &quot;slow&quot;, 0);
  outputCodecContext-&gt;bit_rate = inputCodecContext-&gt;bit_rate;
  outputCodecContext-&gt;width = inputCodecContext-&gt;width;
  outputCodecContext-&gt;height = inputCodecContext-&gt;height;
  outputCodecContext-&gt;time_base = (AVRational){1, 60};
  outputCodecContext-&gt;framerate = (AVRational){60, 1};
  outputCodecContext-&gt;pix_fmt = inputCodecContext-&gt;pix_fmt;
  outputCodecContext-&gt;extradata = inputCodecContext-&gt;extradata;
  outputCodecContext-&gt;extradata_size = inputCodecContext-&gt;extradata_size;
  
  // This if statement fails as a result of the encoder error
  if (avcodec_open2(outputCodecContext, codec, NULL) &lt; 0) {
      printf(&quot;[ERROR] Failed to open video output codec\n&quot;);
      return -1;
  }
  return 0;
  </code></pre>
  <p>When I encode with H264 using the <code>ffmpeg</code> command, I don't receive any of these errors. Any help is appreciated.</p>