FFMPEG Video Encoding Example Not Working: Troubleshooting Guide
This article provides a comprehensive guide to help you troubleshoot common issues when using the FFmpeg video encoding example. If you have tried the example code from the FFmpeg official documentation, but it's not working on your Ubuntu system with the latest FFmpeg build, follow the steps below.
Check the return value of avcodec_send_frame()
The most common issue when using the FFmpeg video encoding example is a failure when calling the avcodec_send_frame() function. This function sends a frame to the encoder and returns an error code if the frame could not be encoded. To check the return value of this function, add the following code snippet to the example:
Code Example
int ret;
// ...
ret = avcodec_send_frame(enc_ctx, frame);
if (ret < 0) {
fprintf(stderr, "Error: %s
", av_err2str(ret));
exit(1);
}
This code snippet prints an error message and exits the program if avcodec_send_frame() returns an error. Replace the existing call to avcodec_send_frame() with this snippet and run the example again.
Check the FFmpeg build and installation
Make sure you have installed the latest FFmpeg build on your Ubuntu system. You can install FFmpeg using the following command:
sudo apt update
sudo apt install ffmpeg
Check the input file format and codec
Make sure the input file format and codec are supported by FFmpeg. You can check the supported formats and codecs using the following command:
ffmpeg -formats
ffmpeg -codecs