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...
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
  • 12,348
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,212