Reputation: 426
I am trying to encode using the H264 encoder, but when I do, I get the following error:
[h264_v4l2m2m @ 0x55682d2416c0] Could not find a valid device
[h264_v4l2m2m @ 0x55682d2416c0] can't configure encoder
I made sure that I enabled the encoder when I configured FFmpeg. When I run the command ffmpeg -codecs
I see that the H264 codec is listed as an encoder:
DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
(decoders: h264 h264_v4l2m2m )
(encoders: libx264 libx264rgb h264_v4l2m2m h264_vaapi )
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 avcodec_find_encoder_by_name
to find the libx264
encoder, it isn't able to.
This is the chunk of code where it fails:
codec = avcodec_find_encoder(AV_CODEC_ID_H264);
if (!codec) {
printf("[ERROR] Failed to find video output codec\n");
return -1;
}
outputCodecContext = avcodec_alloc_context3(codec);
if (!outputCodecContext) {
printf("[ERROR] Failed to allocate memory for video output codec context\n");
return -1;
}
av_opt_set(outputCodecContext->priv_data, "preset", "slow", 0);
outputCodecContext->bit_rate = inputCodecContext->bit_rate;
outputCodecContext->width = inputCodecContext->width;
outputCodecContext->height = inputCodecContext->height;
outputCodecContext->time_base = (AVRational){1, 60};
outputCodecContext->framerate = (AVRational){60, 1};
outputCodecContext->pix_fmt = inputCodecContext->pix_fmt;
outputCodecContext->extradata = inputCodecContext->extradata;
outputCodecContext->extradata_size = inputCodecContext->extradata_size;
// This if statement fails as a result of the encoder error
if (avcodec_open2(outputCodecContext, codec, NULL) < 0) {
printf("[ERROR] Failed to open video output codec\n");
return -1;
}
return 0;
When I encode with H264 using the ffmpeg
command, I don't receive any of these errors. Any help is appreciated.
Upvotes: 7
Views: 11494
Reputation: 426
As it turns out, I kept forgetting to call make
and make install
(I'm on Ubuntu) after I used the command ./configure --enable-shared --enable-libx264 --enable-gpl
. This removed the error I was receiving and my code was able to find the libx264
encoder.
Upvotes: 6