3

I am trying to run this program from ffmpeg c documentation. It is compiled successfully. But showing "codec not found" when I am trying to execute. I am using below command to compile.

gcc -o video_encode video_encode.c -lavutil -lavformat -lavcodec -lz -lm

I use following command to run this file.

./video_encode videoplayback mpeg-4

I used the codec mpeg4 like

./video_encode videoplayback mpeg4

You can see the result in image

click here to see the result

But it is showing codec 'mpeg-4' and 'mpeg4' not found. I use different codecs available, still facing the same issue. I have installed new versions of ffmpeg libavcodec and other related libraries and ubuntu 16.04 LTS.

Please help me through this.

emb-pro
  • 31

3 Answers3

2

I wanted to use the H264 codec, and ran into a similar problem. I was sure the codec was installed on my machine, since I was able to encode with the ffmpeg CLI without any issues.

What fixed the problem was to add av_register_all() before looking the codec up:

/* find the mpeg1video encoder */
codec = avcodec_find_encoder_by_name(codec_name);
// codec = avcodec_find_encoder(AV_CODEC_ID_H264);
if (!codec)
{
    fprintf(stderr, "Codec '%s' not found\n", codec_name);
    exit(1);
}
// rest of the program...
  • I think you meant avcodec_register_all. Older versions of ffmpeg require that. Newer examples will be missing this. – theicfire Jun 22 '22 at 22:31
1

compile

A simple guide:

sudo apt-get install build-essential pkg-config
wget https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xvf ffmpeg-snapshot.tar.bz2
cd ffmpeg
./configure
make -j4 examples
  • This will compile all of the examples in-tree using the source code from the current git master branch and may be less error prone than using gcc.
  • The compile and make commands will take several minutes to complete.
  • For more info see doc/examples/README.
  • As doug mentioned the example in question is named encode_video.c.

encoder name

The codec name is mpeg4 (no hyphen). See ffmpeg -encoders for a list of encoder names supported by your particular build.

llogan
  • 11,868
  • Hi, First of all, thanks for answering. Yes I tried like you said, it is still giving me the same issue. Tried with all the codecs available. You can suggest me or you can say where I can get the exact code which I need to convert this video into images in c language. – emb-pro Jul 27 '18 at 05:58
  • Hi @LordNeckbeard, so you want me to install the pkg-config? Compiling and executing requires this package? what's this package exactly does? is it because of compatibility issues? – emb-pro Jul 30 '18 at 06:59
  • @emb-pro pkg-config helps locate libraries, and you may already have it installed. You may not need it depending on the configure options you use when you compile ffmpeg, but it is recommended to make things easier. – llogan Jul 30 '18 at 18:29
  • How can I see the images from this program? Do I need any extra modifications to capture the pictures? – emb-pro Aug 02 '18 at 05:50
  • @emb-pro It really depends on the encoder you chose, but mpeg4 should be playable by just about any desktop player. Sorry, but I don't understand your second question. – llogan Aug 02 '18 at 07:10
  • I have seen a code here. I executed it. It creates no.of images based on frame rate. Like this, I want to produce images from this. – emb-pro Aug 02 '18 at 08:59
  • @emb-pro You should ask the libav-user mailing list. It is the mailing list for FFmpeg library & API users and questions about programatic usage. My answer was specifically trying to resolve the "codec not found" issue. Did you resolve that? – llogan Aug 02 '18 at 18:41
  • Yes, I resolved it. The program didn't have the line av_register_all(). – emb-pro Aug 03 '18 at 05:50
1

Are you building "video_encode" in or out of tree? If later you'd need to have libavcodec-dev installed. If former then you'd first need to build the ffmpeg source. Based on you using a gcc command I'd guess out of tree.

Note that it's actually named encode_video.c in the ffmpeg source ( no matter.

Works fine here in an out of tree build to produce the expected encoding ( i.e, 1 sec.

Ex.

$ ./video_encode videotest.m4v mpeg4 Send frame 0 Send frame 1 Write packet 0 (size= 6467) Send frame 2 Write packet 2 (size= 3281) Send frame 3 Write packet 1 (size= 1874) Send frame 4 Write packet 4 (size= 3579) Send frame 5 Write packet 3 (size= 2069) Send frame 6 Write packet 6 (size= 4389) Send frame 7 Write packet 5 (size= 2204) Send frame 8 Write packet 8 (size= 3538) Send frame 9 Write packet 7 (size= 2348) Send frame 10 Write packet 10 (size=13024) Send frame 11 Write packet 9 (size= 2303) Send frame 12 Write packet 12 (size= 4718) Send frame 13 Write packet 11 (size= 2504) Send frame 14 Write packet 14 (size= 5082) Send frame 15 Write packet 13 (size= 1898) Send frame 16 Write packet 16 (size= 4186) Send frame 17 Write packet 15 (size= 1842) Send frame 18 Write packet 18 (size= 4676) Send frame 19 Write packet 17 (size= 1782) Send frame 20 Write packet 20 (size=12942) Send frame 21 Write packet 19 (size= 2237) Send frame 22 Write packet 22 (size= 5180) Send frame 23 Write packet 21 (size= 2312) Send frame 24 Write packet 24 (size= 4520) Write packet 23 (size= 2523)

enter image description here `

doug
  • 17,026
  • Thank you for your help. Do I need to reinstall the libraries again, like libavcodec-dev. But Why I am getting the errors like this? Is it because of the codecs missing? or libraries missing? – emb-pro Jul 30 '18 at 06:56
  • Well install libavcodec-dev and try again. You do understand that that code is just an example, you can't use it as is to 'convert' a video. All its going to do is create a 1 sec test video – doug Jul 30 '18 at 23:57
  • Thank you @doug, I got the exact output. But how can I see the images? – emb-pro Aug 02 '18 at 05:47
  • In the folder that has the 'video_encode` binary there would be a 1 sec long video that looks like attached.. – doug Aug 02 '18 at 22:20