22
Function List Printable version Text version int av_open_input_file (AVFormatContext **ptr, const char * filename, AVInputFormat *fmt, int buf_size, AVFormatParameters *ap) Opens a media file filename, stores the format context in the address pointed to by ptr. fmt forces file format if not NULL. buf_size: optional buffer size. ap: AVFormatParameters struct setting parameters (see data reference). void av_close_input_file (AVFormatContext *s) Closes a media file. It does not close its codecs, however. int av_dup_packet (AVPacket *pkt) This apparently is a hack: if this packet wasn't allocated, we allocate it here. It returns 0 on success or AVERROR_NOMEM on failure. int av_find_stream_info (AVFormatContext *s) This function searches the stream to find information about it that might not have been obvious like frame rate. This is useful for file formats without headers like MPEG. It's recommended that you call this after opening a file. It returns >= 0 on success, AVERROR_* on error. void av_free (void *ptr) Frees memory allocated by av_malloc() or av_realloc(). You are allowed to call this function with ptr == NULL. It is recommended you call av_freep() instead. void av_freep (void *ptr) Frees memory and sets the pointer to NULL. Uses av_free () internally. void av_free_packet (AVPacket *pkt) A wrapper around the packet's destruct method (pkt->destruct). int64_t av_gettime ()

Ffmpeg Reference

Embed Size (px)

Citation preview

Page 1: Ffmpeg Reference

Function List

Printable version Text version

int av_open_input_file(AVFormatContext **ptr, const char * filename, AVInputFormat *fmt, int buf_size, AVFormatParameters *ap)

Opens a media file filename, stores the format context in the address pointed to by ptr.

fmt forces file format if not NULL.

buf_size: optional buffer size.

ap: AVFormatParameters struct setting parameters (see data reference).

void av_close_input_file(AVFormatContext *s)

Closes a media file. It does not close its codecs, however.

int av_dup_packet(AVPacket *pkt)

This apparently is a hack: if this packet wasn't allocated, we allocate it here. It returns 0 on success or AVERROR_NOMEM on failure.

int av_find_stream_info(AVFormatContext *s)

This function searches the stream to find information about it that might not have been obvious like frame rate. This is useful for file formats without headers like MPEG. It's recommended that you call this after opening a file. It returns >= 0 on success, AVERROR_* on error.

void av_free(void *ptr)

Frees memory allocated by av_malloc() or av_realloc(). You are allowed to call this function with ptr == NULL. It is recommended you call av_freep() instead.

void av_freep(void *ptr)

Frees memory and sets the pointer to NULL. Uses av_free() internally.

void av_free_packet(AVPacket *pkt)

A wrapper around the packet's destruct method (pkt->destruct).

int64_t av_gettime()

Gets the current time in microseconds.

void av_init_packet(AVPacket *pkt)

Initialize optional fields of a packet.

void *av_malloc(unsigned int size)

Memory allocation of size byte with alignment suitable for all memory accesses (including vectors if available on the CPU). av_malloc(0) must return a non NULL pointer.

Page 2: Ffmpeg Reference

void *av_mallocz(unsigned int size)

Same as av_malloc() but it initializes the memory to zero.

double av_q2d(AVRational a)

Converts an AVRational to a double.

int av_read_frame(AVFormatContext *s, AVPacket *pkt)

Return the next frame of a stream. The information is stored as a packet in pkt.

The returned packet is valid until the next av_read_frame() or untilav_close_input_file() and must be freed with av_free_packet. For video, the packet contains exactly one frame. For audio, it contains an integer number of frames if each frame has a known fixed size (e.g. PCM or ADPCM data). If the audio frames have a variable size (e.g. MPEG audio), then it contains one frame.

pkt->pts, pkt->dts and pkt->duration are always set to correct values in AVStream.timebase units (and guessed if the format cannot provided them). pkt->pts can be AV_NOPTS_VALUE if the video format has B frames, so it is better to rely on pkt->dts if you do not decompress the payload.

Returns: 0 if OK, < 0 if error or end of file.

void av_register_all();

Registers all codecs with the library.

int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)

Returns a * bq / cq.

int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)

Seeks to the key frame at timestamp.

stream_index: If stream_index is -1, a default stream is selected, and timestamp is automatically converted from AV_TIME_BASE units to the stream specific time_base.

timestamp is measured in AVStream.time_base units or if there is no stream specified then in AV_TIME_BASE units.

flags: Set options regarding direction and seeking mode.AVSEEK_FLAG_ANY: Seek to any frame, not just keyframesAVSEEK_FLAG_BACKWARD: Seek backwardAVSEEK_FLAG_BYTE: Seeking based on position in bytes

AVFrame *avcodec_alloc_frame()

Allocates an AVFrame and initializes it. This can be freed withav_free().

int avcodec_decode_audio(AVCodecContext *codecCtx, int16_t *samples, int *frame_size_ptr, uint8_t *buf, int buf_size)

Page 3: Ffmpeg Reference

Deprecated. Use avcodec_decode_audio2.

int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, uint8_t *buf, int buf_size)

Decodes an audio frame from buf into samples. Theavcodec_decode_audio2() function decodes a frame of audio from the input buffer buf of size buf_size. To decode it, it makes use of the audiocodec which was coupled with avctx using avcodec_open(). The resulting decoded frame is stored in output buffer samples. If no frame could be decompressed, frame_size_ptr is zero. Otherwise, it is the decompressed frame size in bytes.

Warning: You must set frame_size_ptr to the allocated size of the output buffer before calling avcodec_decode_audio2(). The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end. The end of the input buffer buf should be set to 0 to ensure that no overreading happens for damaged MPEG streams.

Note: You might have to align the input buffer buf and output buffer samples. The alignment requirements depend on the CPU: on some CPUs it isn't necessary at all, on others it won't work at all if not aligned and on others it will work but it will have an impact on performance. In practice, the bitstream should have 4 byte alignment at minimum and all sample data should be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If the linesize is not a multiple of 16 then there's no sense in aligning the start of the buffer to 16.

avctx: The codec context.samples: The output buffer.frame_size_ptr: The output buffer size in bytes.buf: The input buffer.buf_size: The input buffer size in bytes.

Returns: On error a negative value is returned, otherwise the number of bytes used or zero if no frame could be decompressed.

int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, int *frameFinished, uint8_t *buf, int buf_size)

Decodes a video frame from buf into picture. Theavcodec_decode_video() function decodes a frame of video from the input buffer buf of size buf_size. To decode it, it makes use of the videocodec which was coupled with avctx using avcodec_open(). The resulting decoded frame is stored in picture.

Warning: The sample alignment and buffer problems that apply toavcodec_decode_audio apply to this function as well.

avctx: The codec context.picture: The AVFrame in which the decoded video will be stored.buf: The input buffer.buf_size: The size of the input buffer in bytes.frameFinished Zero if no frame could be decompressed, otherwise it is non-zero.

Returns: On error a negative value is returned, otherwise the number of bytes used or zero if no frame could be decompressed.

Page 4: Ffmpeg Reference

int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic)

Default function for interally allocating a frame buffer. You should know this call for when you want to override an AVCodecContextget_buffer function. Returns < 0 on failure.

void avcodec_default_release_buffer(AVCodecContext *s, AVFrame*pic)

Default function for interally freeing a frame buffer. You should know this call for when you want to override an AVCodecContextrelease_buffer function.

AVCodec *avcodec_find_decoder(enum CodecID id)

Find the decoder with the CodecID id. Returns NULL on failure. This should be called after getting the desired AVCodecContext from a stream in AVFormatContext, using codecCtx->codec_id.

void avcodec_flush_buffers(AVCodecContetx *avctx)

Flush buffers, should be called when seeking or when switching to a different stream.

int avcodec_open(AVCodecContext *avctx, AVCodec *codec)

Initializes avctx to use the codec given in codec. This should be used after avcodec_find_decoder. Returns zero on success, and a negative value on error.

int avpicture_fill(AVPicture *picture, uint8_t *ptr, int pix_fmt, int width, int height)

Sets up the struct pointed to by picture with the buffer ptr, pic formatpix_fmt and the given width and height. Returns the size of the image data in bytes.

int avpicture_get_size(int pix_fmt, int width, int height)

Calculates how many bytes will be required for a picture of the given width, height, and pic format.

int img_convert(AVPicture *dst, int dst_pix_fmt, const AVPicture *src, int pix_fmt, int width, int height)

Converts the image from src into dst_pix_fmt format and stores it indst. Deprecated. Use sws_scale instead.

struct SwsContext* sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, double *param)

Returns an SwsContext to be used in sws_scale.

Params:srcW, srcH, srcFormat: source width, height, and pix formatdstW, dstH, dstFormat: destination width, height, and pix formatflags: Method of scaling to use. Choices are SWS_FAST_BILINEAR, SWS_BILINEAR, SWS_BICUBIC, SWS_X, SWS_POINT, SWS_AREA, SWS_BICUBLIN, SWS_GAUSS, SWS_SINC, SWS_LANCZOS, SWS_SPLINE. Other flags include CPU capability flags: SWS_CPU_CAPS_MMX, SWS_CPU_CAPS_MMX2, SWS_CPU_CAPS_3DNOW, SWS_CPU_CAPS_ALTIVEC. Other flags include (currently not completely implemented) SWS_FULL_CHR_H_INT, SWS_FULL_CHR_H_INP, and SWS_DIRECT_BGR. Finally we have SWS_ACCURATE_RND and perhaps the most useful for beginners, SWS_PRINT_INFO. I have no idea what most of these do. Maybe email me?

Page 5: Ffmpeg Reference

srcFilter, dstFilter: SwsFilter for source and destination. SwsFilter involves chroma/luminsence filtering. A value of NULL sets these to the default.param: should be a pointer to an int[2] buffer with coefficients. Not documented. Looks like it's used to alter the default scaling algorithms slightly. A value of NULL sets this to the default. Experts only!

int sws_scale(SwsContext *c, uint8_t *src, int srcStride[], int srcSliceY, int srcSliceH, uint8_t dst[], int dstStride[]

sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, is->video_st->codec->height, pict.data, pict.linesize);

Scales the data in src according to our settings in our SwsContext c.srcStride and dstStride are the source and destination linesize.

int url_ferror(ByteIOContext *s)

Returns non-zero if there is an error at the ByteIOContext level. Usually used to check an AVFormatContext (url_ferror(avctx->pb)).

void url_set_interrupt_cb(URLInterruptBC *interrupt_cb())

The callback is called in blocking functions to test regulary if asynchronous interruption is needed. AVERROR(EINTR) is returned in this case by the interrupted function. 'NULL' means no interrupt callback is given.

SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param)

Adds a callback function to be run after the specified number of milliseconds has elapsed. The callback function is passed the current timer interval and the user supplied parameter from theSDL_AddTimer call and returns the next timer interval. (If the returned value from the callback is the same as the one passed in, the timer continues at the same rate.) If the returned value from the callback is 0, the timer is cancelled.

Another way to cancel a currently-running timer is by calling SDL_RemoveTimer with the timer's ID (which was returned fromSDL_AddTimer).

The timer callback function may run in a different thread than your main program, and so shouldn't call any functions from within itself. However, you may always call SDL_PushEvent.

The granularity of the timer is platform-dependent, but you should count on it being at least 10 ms as this is the most common number. This means that if you request a 16 ms timer, your callback will run approximately 20 ms later on an unloaded system. If you wanted to set a flag signaling a frame update at 30 frames per second (every 33 ms), you might set a timer for 30 ms (see example below). If you use this function, you need to pass SDL_INIT_TIMER to SDL_Init.

Returns an ID value for the added timer or NULL if there was an error.

Format for callback is: Uint32 callback(Uint32 interval, void *param).

int SDL_CondSignal(SDL_cond *cond)

Page 6: Ffmpeg Reference

Restart one of the threads that are waiting on the condition variable, cond. Returns 0 on success of -1 on an error.

int SDL_CondWait(SDL_cond *cond, SDL_mutex *mut);

Unlock the provided mutex and wait for another thread to callSDL_CondSignal or SDL_CondBroadcast on the condition variable cond, then re-lock the mutex and return. The mutex must be locked before entering this function. Returns 0 when it is signalled, or -1 on an error.

SDL_cond *SDL_CreateCond(void);

Creates a condition variable.

SDL_Thread *SDL_CreateThread(int (*fn)(void *), void *data);

SDL_CreateThread creates a new thread of execution that shares all of its parent's global memory, signal handlers, file descriptors, etc, and runs the function fn passing it the void pointer data. The thread quits when fn returns.

void SDL_Delay(Uint32 ms);

Wait a specified number of milliseconds before returning. SDL_Delaywill wait at least the specified time, but possible longer due to OS scheduling.

Note: Count on a delay granularity of at least 10 ms. Some platforms have shorter clock ticks but this is the most common.

SDL_Overlay *SDL_CreateYUVOverlay(int width, int height, Uint32 format, SDL_Surface *display);

SDL_CreateYUVOverlay creates a YUV overlay of the specified width, height and format (see SDL_Overlay for a list of available formats), for the provided display. A SDL_Overlay structure is returned.

display needs to actually be the surface gotten fromSDL_SetVideoMode otherwise this function will segfault.

The term 'overlay' is a misnomer since, unless the overlay is created in hardware, the contents for the display surface underneath the area where the overlay is shown will be overwritten when the overlay is displayed.

int SDL_LockYUVOverlay(SDL_Overlay *overlay)

SDL_LockYUVOverlay locks the overlay for direct access to pixel data. Returns 0 on success, or -1 on an error.

void SDL_UnlockYUVOverlay(SDL_Overlay *overlay)

Unlocks a previously locked overlay. An overlay must be unlocked before it can be displayed.

int SDL_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *dstrect)

Page 7: Ffmpeg Reference

Blit the overlay to the surface specified when it was created. TheSDL_Rect structure, dstrect, specifies the position and size of the destination. If the dstrect is a larger or smaller than the overlay then the overlay will be scaled, this is optimized for 2x scaling. Returns 0 on success.

void SDL_FreeYUVOverlay(SDL_Overlay *overlay)

Frees an overlay created by SDL_CreateYUVOverlay.

int SDL_Init(Uint32 flags);

Initializes SDL. This should be called before all other SDL functions. The flags parameter specifies what part(s) of SDL to initialize.

SDL_INIT_TIMER Initializes the timer subsystem.SDL_INIT_AUDIO Initializes the audio subsystem.SDL_INIT_VIDEO Initializes the video subsystem.SDL_INIT_CDROM Initializes the cdrom subsystem.SDL_INIT_JOYSTICK Initializes the joystick subsystem.SDL_INIT_EVERYTHING Initialize all of the above.SDL_INIT_NOPARACHUTE Prevents SDL from catching fatal signals.SDL_INIT_EVENTTHREAD Run the event manager in a separate thread.

Returns -1 on an error or 0 on success. You can get extended error message by calling SDL_GetError. Typical cause of this error is using a particular display without having according subsystem support, such as missing mouse driver when using with framebuffer device. In this case you can either compile SDL without mouse device, or set "SDL_NOMOUSE=1" environment variable before running your application.

SDL_mutex *SDL_CreateMutex(void);

Creates a new, unlocked mutex.

int SDL_LockMutex(SDL_mutex *mutex)

SDL_LockMutex is an alias for SDL_mutexP. It locks mutex, which was previously created with SDL_CreateMutex. If the mutex is already locked by another thread then SDL_mutexP will not return until the thread that locked it unlocks it (with SDL_mutexV). If called repeatedly on a mutex, SDL_mutexV (a.k.a. SDL_UnlockMutex) must be called equal amount of times to return the mutex to unlocked state. Returns 0 on success, or -1 on an error.

int SDL_UnlockMutex(SDL_Mutex *mutex)

Unlocks mutex.

int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained)

This function opens the audio device with the desired parameters, and returns 0 if successful, placing the actual hardware parameters in the structure pointed to by obtained. If obtained is NULL, the audio data passed to the callback function will be guaranteed to be in the requested format, and will be automatically converted to the hardware audio format if necessary. This function returns -1 if it failed to open the audio device, or couldn't set up the audio thread.

Page 8: Ffmpeg Reference

To open the audio device a desired SDL_AudioSpec must be created. You must then fill this structure with your desired audio specifications.

desired->freq: The desired audio frequency in samples-per-second.desired->format: The desired audio format (see SDL_AudioSpec)desired->channels: The desired channels (1 for mono, 2 for stereo, 4 for surround, 6 for surround with center and lfe).desired->samples: The desired size of the audio buffer in samples. This number should be a power of two, and may be adjusted by the audio driver to a value more suitable for the hardware. Good values seem to range between 512 and 8192 inclusive, depending on the application and CPU speed. Smaller values yield faster response time, but can lead to underflow if the application is doing heavy processing and cannot fill the audio buffer in time. A stereo sample consists of both right and left channels in LR ordering. Note that the number of samples is directly related to time by the following formula: ms = (samples*1000)/freqdesired->callback: This should be set to a function that will be called when the audio device is ready for more data. It is passed a pointer to the audio buffer, and the length in bytes of the audio buffer. This function usually runs in a separate thread, and so you should protect data structures that it accesses by calling SDL_LockAudio and SDL_UnlockAudio in your code. The callback prototype is void callback(void *userdata, Uint8 *stream, int len). userdata is the pointer stored in the userdata field of theSDL_AudioSpec. stream is a pointer to the audio buffer you want to fill with information and len is the length of the audio buffer in bytes.desired->userdata: This pointer is passed as the first parameter to the callback function.

SDL_OpenAudio reads these fields from the desired SDL_AudioSpecstructure passed to the function and attempts to find an audio configuration matching your desired. As mentioned above, if the obtained parameter is NULL then SDL with convert from your desired audio settings to the hardware settings as it plays.

If obtained is NULL then the desired SDL_AudioSpec is your working specification, otherwise the obtained SDL_AudioSpec becomes the working specification and the desired specification can be deleted. The data in the working specification is used when building SDL_AudioCVT's for converting loaded data to the hardware format.

SDL_OpenAudio calculates the size and silence fields for both the desired and obtained specifications. The size field stores the total size of the audio buffer in bytes, while the silence stores the value used to represent silence in the audio buffer

The audio device starts out playing silence when it's opened, and should be enabled for playing by calling SDL_PauseAudio(0) when you are ready for your audio callback function to be called. Since the audio driver may modify the requested size of the audio buffer, you should allocate any local mixing buffers after you open the audio device.

void SDL_PauseAudio(int pause_on)

This function pauses and unpauses the audio callback processing. It should be called with pause_on=0 after opening the audio device to start playing sound. This is so you can safely initialize data for your callback function after opening the audio device. Silence will be written to the audio device during the pause.

int SDL_PushEvent(SDL_Event *event)

The event queue can actually be used as a two way communication channel. Not only can events be read from the queue, but the user can also push their own events onto it. event

Page 9: Ffmpeg Reference

is a pointer to the event structure you wish to push onto the queue. The event is copied into the queue, and the caller may dispose of the memory pointed to afterSDL_PushEvent returns. This function is thread safe, and can be called from other threads safely. Returns 0 on success or -1 if the event couldn't be pushed.

int SDL_WaitEvent(SDL_Event *event)

Waits indefinitely for the next available event, returning 0 if there was an error while waiting for events, 1 otherwise. If event is not NULL, the next event is removed from the queue and stored in that area.

void SDL_Quit()

SDL_Quit shuts down all SDL subsystems and frees the resources allocated to them. This should always be called before you exit.

SDL_Surface *SDL_SetVideoMode(int width, int height, int bitsperpixel, Uint32 flags)

Set up a video mode with the specified width, height and bitsperpixel. As of SDL 1.2.10, if width and height are both 0, it will use the width and height of the current video mode (or the desktop mode, if no mode has been set). If bitsperpixel is 0, it is treated as the current display bits per pixel. The flags parameter is the same as the flags field of the SDL_Surface structure. OR'd combinations of the following values are valid:

SDL_SWSURFACE Create the video surface in system memorySDL_HWSURFACE Create the video surface in video memorySDL_ASYNCBLIT Enables the use of asynchronous updates of the display surface. This will usually slow down blitting on single CPU machines, but may provide a speed increase on SMP systems.SDL_ANYFORMAT Normally, if a video surface of the requested bits-per-pixel (bpp) is not available, SDL will emulate one with a shadow surface. Passing SDL_ANYFORMAT prevents this and causes SDL to use the video surface, regardless of its pixel depth. SDL_HWPALETTE Give SDL exclusive palette access. Without this flag you may not always get the the colors you request with SDL_SetColors or SDL_SetPalette. SDL_DOUBLEBUF Enable hardware double buffering; only valid with SDL_HWSURFACE. Calling SDL_Flip will flip the buffers and update the screen. All drawing will take place on the surface that is not displayed at the moment. If double buffering could not be enabled then SDL_Flip will just perform a SDL_UpdateRect on the entire screen. SDL_FULLSCREEN SDL will attempt to use a fullscreen mode. If a hardware resolution change is not possible (for whatever reason), the next higher resolution will be used and the display window centered on a black background. SDL_OPENGL Create an OpenGL rendering context. You should have previously set OpenGL video attributes with SDL_GL_SetAttribute. (IMPORTANT: Please see this page for more.)SDL_OPENGLBLIT Create an OpenGL rendering context, like above, but allow normal blitting operations. The screen (2D) surface may have an alpha channel, and SDL_UpdateRects must be used for updating changes to the screen surface. NOTE: This option is kept for compatibility only, and will be removed in next versions. Is not recommended for new code. SDL_RESIZABLECreate a resizable window. When the window is resized by the user a SDL_VIDEORESIZE event is generated andSDL_SetVideoMode can be called again with the new size. SDL_NOFRAME If possible, SDL_NOFRAME causes SDL to create a window with no title bar or frame decoration. Fullscreen modes automatically have this flag set. 

Note: Whatever flags SDL_SetVideoMode could satisfy are set in the flags member of the returned surface. 

Page 10: Ffmpeg Reference

Note: A bitsperpixel of 24 uses the packed representation of 3 bytes/pixel. For the more common 4 bytes/pixel mode, use a bitsperpixel of 32. Somewhat oddly, both 15 and 16 will request a 2 bytes/pixel mode, but different pixel formats. Note: Use SDL_SWSURFACE if you plan on doing per-pixel manipulations, or blit surfaces with alpha channels, and require a high framerate. When you use hardware surfaces (SDL_HWSURFACE), SDL copies the surfaces from video memory to system memory when you lock them, and back when you unlock them. This can cause a major performance hit. (Be aware that you may request a hardware surface, but receive a software surface. Many platforms can only provide a hardware surface when using SDL_FULLSCREEN.) SDL_HWSURFACE is best used when the surfaces you'll be blitting can also be stored in video memory. Note: If you want to control the position on the screen when creating a windowed surface, you may do so by setting the environment variables "SDL_VIDEO_CENTERED=center" or "SDL_VIDEO_WINDOW_POS=x,y". You can set them via SDL_putenv.

Return Value: The framebuffer surface, or NULL if it fails. The surface returned is freed by SDL_Quit and should not be freed by the caller. Note: This rule includes consecutive calls toSDL_SetVideoMode (i.e. resize or rez change) - the pre-existing surface will be released automatically.

email:

dranger at gmail dot com

Back to dranger.com

This work is licensed under the Creative Commons Attribution-Share Alike 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA. 

Much of this documentation is based off of FFmpeg, Copyright (c) 2003 Fabrice Bellard, and from the SDL Documentation Wiki.

Page 11: Ffmpeg Reference

Data List

Printable version Text version

AVCodecContext

All the codec information from a stream, from AVStream->codec. Some important data members:

AVRational time_base: frames per secint sample_rate: samples per secint channels: number of channels

For a full list (this thing is huge), seehttp://www.irisa.fr/texmex/people/dufouil/ffmpegdoxy/structAVCodecContext.htmlMany of the options are used mostly for encoding rather than decoding.

AVFormatContext

Data fields:

const AVClass * av_class AVInputFormat * iformat AVOutputFormat * oformat void * priv_data: ByteIOContext pb: ByteIOContext of the file, used for the low level file manipulation unsigned int nb_streams: Number of streams in the fileAVStream * streams [MAX_STREAMS]: Stream data for each stream is stored here.char filename [1024]: duh

File Informationint64_t timestamp: char title [512]: char author [512]: char copyright [512]: char comment [512]: char album [512]: int year: int track: char genre [32]: 

int ctx_flags: Any of AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, AVFMT_RAWPICTURE, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_GENERIC_INDEX AVPacketList * packet_buffer: This buffer is only needed when packets were already buffered but not decoded, for example to get the codec parameters in mpeg streamsint64_t start_time: decoding: position of the first frame of the component, in AV_TIME_BASE fractional seconds. NEVER set this value directly: it is deduced from the AVStream values.int64_t duration: decoding: duration of the stream, in AV_TIME_BASE fractional seconds. NEVER set this value directly: it is deduced from the AVStream values.int64_t file_size: total file size, 0 if unknownint bit_rate: decoding: total stream bitrate in bit/s, 0 if not available. Never set it directly if

Page 12: Ffmpeg Reference

the file_size and the duration are known as ffmpeg can compute it automatically.AVStream * cur_st const uint8_t * cur_ptr int cur_len AVPacket cur_pkt: int64_t data_offset: int index_built: offset of the first packetint mux_rate: int packet_size: int preload: int max_delay: int loop_output: number of times to loop output in formats that support itint flags: int loop_input: unsigned int probesize: decoding: size of data to probe; encoding unusedint max_analyze_duration: maximum duration in AV_TIME_BASE units over which the input should be analyzed in av_find_stream_info()const uint8_t * key: int keylen: 

AVFormatParameters

This is used to force certain parameters when decoding:

AVRational time_base int sample_rate int channels int width int height enum PixelFormat pix_fmt int channel: used to select dv channel const char * device: video, audio or DV device const char * standard: tv standard, NTSC, PAL, SECAM int mpeg2ts_raw:1: force raw MPEG2 transport stream output, if possible int mpeg2ts_compute_pcr:1: compute exact PCR for each transport stream packet (only meaningful if mpeg2ts_raw is TRUEint initial_pause:1: do not begin to play the stream immediately (RTSP only)int prealloced_context:1 enum CodecID video_codec_id enum CodecID audio_codec_id 

AVFrame

This struct is dependent upon the type of codec, and therefore is dynamically defined. There are common data members for this struct, though:

uint8_t *data[4]: int linesize[4]: Stride informationuint8_t *base[4]: int key_frame: int pict_type: int64_t pts: This is not the pts you want when decoding.int coded_picture_number: int display_picture_number: 

Page 13: Ffmpeg Reference

int quality: int age: int reference: int8_t *qscale_table: int qstride: uint8_t *mbskip_table: int16_t (*motion_val[2])[2]: uint32_t *mb_type: uint8_t motion_subsample_log2: void *opaque: User-defined datauint64_t error[4]: int type: int repeat_pict: Indicates we should repeat this picture this number of times int qscale_type: int interlaced_frame: int top_field_first: AVPanScan *pan_scan: int palette_has_changed: int buffer_hints: short *dct_coeff: int8_t *ref_index[2]: 

AVPacket

The struct in which raw packet data is stored. This data should be given to avcodec_decode_audio2 or avcodec_decode_video to to get a frame.

int64_t pts: presentation time stamp in time_base unitsint64_t dts: decompression time stamp in time_base unitsuint8_t * data: the raw dataint size: size of dataint stream_index: the stream it came from, based on the number in the AVFormatContextint flags: set to PKT_FLAG_KEY if packet is a key frameint duration: presentation duration in time_base units (0 if not available)void(* destruct )(struct AVPacket *): deallocation function for this packet (defaults to av_destruct_packet) void * priv:int64_t pos: byte position in stream, -1 if unknown

AVPacketList

A simple linked list for packets.

AVPacket pktAVPacketList * next

AVPicture

This struct is the exact same as the first two data members ofAVFrame, so it is often casted from that. This is usually used in sws functions.

uint8_t * data [4]int linesize [4]: number of bytes per line

Page 14: Ffmpeg Reference

AVRational

Simple struct to represent rational numbers.

int num: numeratorint den: denominator

AVStream

Struct for the stream. You will probably use the information in codecmost often.

int index:int id:AVCodecContext * codec:AVRational r_frame_rate:void * priv_data:int64_t codec_info_duration:int codec_info_nb_frames:AVFrac pts:AVRational time_base:int pts_wrap_bits:int stream_copy:enum AVDiscard discard: selects which packets can be discarded at will and dont need to be demuxedfloat quality:int64_t start_time:int64_t duration:char language [4]:int need_parsing: 1->full parsing needed, 2->only parse headers dont repackAVCodecParserContext * parser:int64_t cur_dts:int last_IP_duration:int64_t last_IP_pts:AVIndexEntry * index_entries:int nb_index_entries:unsigned int index_entries_allocated_size:int64_t nb_frames: number of frames in this stream if known or 0int64_t pts_buffer [MAX_REORDER_DELAY+1]:

ByteIOContext

Struct that stores the low-level file information about our movie file.

unsigned char * buffer: int buffer_size: unsigned char * buf_ptr: unsigned char * buf_end: void * opaque: int(* read_packet )(void *opaque, uint8_t *buf, int buf_size): int(* write_packet )(void *opaque, uint8_t *buf, int buf_size): offset_t(* seek )(void *opaque, offset_t offset, int whence): offset_t pos: int must_flush: 

Page 15: Ffmpeg Reference

int eof_reached: int write_flag: int is_streamed: int max_packet_size: unsigned long checksum: unsigned char * checksum_ptr: unsigned long(* update_checksum )(unsigned long checksum,: const uint8_t *buf, unsigned int size): int error: contains the error code or 0 if no error happened 

SDL_AudioSpec

The SDL_AudioSpec structure is used to describe the format of some audio data. Data members:

freq: Audio frequency in samples per secondformat: Audio data formatchannels: Number of channels: 1 mono, 2 stereo, 4 surround, 6 surround with center and lfesilence: Audio buffer silence value (calculated)samples: Audio buffer size in samplessize: Audio buffer size in bytes (calculated)callback(..): Callback function for filling the audio bufferuserdata: Pointer the user data which is passed to the callback function

The following format values are acceptable:AUDIO_U8 Unsigned 8-bit samples.AUDIO_S8 Signed 8-bit samples.AUDIO_U16 or AUDIO_U16LSB not supported by all hardware (unsigned 16-bit little-endian)AUDIO_S16 or AUDIO_S16LSBnot supported by all hardware (signed 16-bit little-endian)AUDIO_U16MSB not supported by all hardware (unsigned 16-bit big-endian)AUDIO_S16MSBnot supported by all hardware (signed 16-bit big-endian)AUDIO_U16SYS Either AUDIO_U16LSB or AUDIO_U16MSB depending on hardware CPU endiannessAUDIO_S16SYS Either AUDIO_S16LSB or AUDIO_S16MSB depending on hardware CPU endianness

SDL_Event

General event structure. Data members:

type: The type of eventactive: Activation event (see SDL_ActiveEvent)key: Keyboard event (see SDL_KeyboardEvent)motion: Mouse motion event (see SDL_MouseMotionEvent)button: Mouse button event (see SDL_MouseButtonEvent)jaxis: Joystick axis motion event (see SDL_JoyAxisEvent)jball: Joystick trackball motion event (see SDL_JoyBallEvent)jhat: Joystick hat motion event (see SDL_JoyHatEvent)jbutton: Joystick button event (see SDL_JoyButtonEvent)resize: Application window resize event (see SDL_ResizeEvent)expose: Application window expose event (see SDL_ExposeEvent)quit: Application quit request event (see SDL_QuitEvent)

Page 16: Ffmpeg Reference

user: User defined event (see SDL_UserEvent)syswm: Undefined window manager event (see SDL_SysWMEvent)

Here are the event types. See the SDL documentation for more info:

SDL_ACTIVEEVENT SDL_ActiveEventSDL_KEYDOWN/UP SDL_KeyboardEventSDL_MOUSEMOTION SDL_MouseMotionEventSDL_MOUSEBUTTONDOWN/UP SDL_MouseButtonEventSDL_JOYAXISMOTION SDL_JoyAxisEventSDL_JOYBALLMOTION SDL_JoyBallEventSDL_JOYHATMOTION SDL_JoyHatEventSDL_JOYBUTTONDOWN/UP SDL_JoyButtonEventSDL_VIDEORESIZE SDL_ResizeEventSDL_VIDEOEXPOSE SDL_ExposeEventSDL_QUIT SDL_QuitEventSDL_USEREVENT SDL_UserEventSDL_SYSWMEVENT SDL_SysWMEvent

SDL_Overlay

A YUV Overlay. Data members:

format: Overlay format (see below)w, h: Width and height of overlayplanes: Number of planes in the overlay. Usually either 1 or 3pitches: An array of pitches, one for each plane. Pitch is the length of a row in bytes.pixels: An array of pointers to the data of each plane. The overlay be locked before these pointers are used.hw_overlay: This will be set to 1 if the overlay is hardware accelerated.

SDL_Rect

Defines a rectangular area.

Sint16 x, y Uint16 w, h

x, y: Position of the upper-left corner of the rectangle w, h: The width and height of the rectangle

A SDL_Rect defines a rectangular area of pixels. It is used by SDL_BlitSurface to define blitting regions and by several other video functions.

SDL_Surface

Graphical Surface Structure

Uint32 flags (Read-only): Surface flagsSDL_PixelFormat *format (Read-only)int w, h (Read-only): Width and heightUint16 pitch (Read-only): stridevoid *pixels (Read-write): pointer to actual pixel dataSDL_Rect clip_rect (Read-only): Surface clip rectangle

Page 17: Ffmpeg Reference

int refcount (Read-mostly): used for mem allocationThis structure also contains private fields not shown here.

An SDL_Surface represents an area of "graphical" memory, memory that can be drawn to. The video framebuffer is returned as a SDL_Surface by SDL_SetVideoMode and SDL_GetVideoSurface. The w and h fields are values representing the width and height of the surface in pixels. The pixels field is a pointer to the actual pixel data. Note: the surface should be locked (via SDL_LockSurface) before accessing this field. The clip_rect field is the clipping rectangle as set by SDL_SetClipRect.

The flags field supports the following OR-ed values:SDL_SWSURFACE Surface is stored in system memorySDL_HWSURFACE Surface is stored in video memorySDL_ASYNCBLIT Surface uses asynchronous blits if possibleSDL_ANYFORMAT Allows any pixel-format (Display surface)SDL_HWPALETTE Surface has exclusive paletteSDL_DOUBLEBUF Surface is double buffered (Display surface)SDL_FULLSCREEN Surface is full screen (Display Surface)SDL_OPENGL Surface has an OpenGL context (Display Surface)SDL_OPENGLBLIT Surface supports OpenGL blitting (Display Surface). NOTE: This option is kept for compatibility only, and is not recommended for new code.SDL_RESIZABLE Surface is resizable (Display Surface)SDL_HWACCEL Surface blit uses hardware accelerationSDL_SRCCOLORKEY Surface use colorkey blittingSDL_RLEACCEL Colorkey blitting is accelerated with RLESDL_SRCALPHA Surface blit uses alpha blendingSDL_PREALLOC Surface uses preallocated memory

SDL_Thread

This struct is is system independent and you probably don't have to use it. For more info, see src/thread/sdl_thread_c.h in the source code.

SDL_cond

This struct is is system independent and you probably don't have to use it. For more info, see src/thread/<system&rt;/SDL_syscond.c in the source code.

SDL_mutex

This struct is is system independent and you probably don't have to use it. For more info, see src/thread/<system&rt;/SDL_sysmutex.c in the source code.

email:

dranger at gmail dot com

Back to dranger.com

This work is licensed under the Creative Commons Attribution-Share Alike 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA. 

Code examples are based off of FFplay, Copyright (c) 2003 Fabrice Bellard, and a tutorial by Martin Bohme.