

The last three arguments are used to specify the file format, buffer size, and format options, but by setting this to NULL or 0, libavformat will auto-detect these.

This function reads the file header and stores information about the file format in the AVFormatContext structure we have given it. We get our filename from the first argument. If( avformat_open_input(&pFormatCtx, argv, NULL, 0, NULL)!=0) If you like, it's possible to register only certain individual file formats and codecs, but there's usually no reason why you would have to do that. Note that you only need to call av_register_all() once, so we do it here in main(). This registers all available file formats and codecs with the library so they will be used automatically when a file with the corresponding format/codec is opened. With ffmpeg, you have to first initialize the library. So in this tutorial, we're going to open a file, read from the video stream inside it, and our DO SOMETHING is going to be writing the frame to a PPM file.įirst, let's see how we open a file in the first place. Handling multimedia with ffmpeg is pretty much as simple as this program, although some programs might have a very complex "DO SOMETHING" step. For our purposes, each packet contains complete frames, or multiple frames in the case of audio.Īt its very basic level, dealing with video and audio streams is very easy:Ģ0 READ packet FROM video_stream INTO frame

Packets are pieces of data that can contain bits of data that are decoded into raw frames that we can finally manipulate for our application. The codec defines how the actual data is COded and DECoded - hence the name CODEC. Each stream is encoded by a different kind of codec. (A "stream" is just a fancy word for "a succession of data elements made available over time".) The data elements in a stream are called frames. Next, you have a bunch of streams for example, you usually have an audio stream and a video stream. Examples of containers are AVI and Quicktime. First, the file itself is called a container, and the type of container determines where the information in the file goes. Text version Tutorial 01: Making Screencaps Code: tutorial01.c Overview
