1 #ifndef FFMPEGVIDEODECODER_H
2 #define FFMPEGVIDEODECODER_H
5 * Copyright (C) 2005-2013 Team XBMC
8 * This Program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This Program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with XBMC; see the file COPYING. If not, see
20 * <http://www.gnu.org/licenses/>.
24 #include "utils/StdString.h"
32 struct AVFormatContext;
33 struct AVCodecContext;
38 * A simple FFMpeg-based background video decoder.
40 * This class only decodes the video using the standard FFmpeg calls, so likely no hardware acceleration.
41 * No audio decoding, and no rendering.
44 class FFmpegVideoDecoder
48 ~FFmpegVideoDecoder();
51 * Opens the video file for decoding. Supports all the formats supported by the used FFmpeg.
52 * The file must have at least one video track. If it has more than one, the first video track
55 * If an existing stream was opened, it is automatically closed and the new stream is opened.
57 * Returns true if the file was opened successfully, and false otherwise, in which case
58 * the getErrorMsg() function could be used to retrieve the reason.
60 * @param filename The video file name, which must be translated through CSpecialProtocol::TranslatePath()
62 bool open( const CStdString& filename );
65 * Returns true if the decoder has the video file opened.
67 bool isOpened() const;
70 * Returns the movie duration in seconds or 0.0 if the duration is not available. For some formats
71 * is calculated through the heuristics, and the video might not really be that long (for example if it is incomplete).
72 * The total number of frames is calculated by multiplying the duration by getFramesPerSecond()
74 double getDuration() const;
77 * Returns the frames per second for this video
79 double getFramesPerSecond() const;
82 * Returns the original video width or 0 if the video wasn't opened.
84 unsigned int getWidth() const;
87 * Returns the original video height or 0 if the video wasn't opened.
89 unsigned int getHeight() const;
92 * Returns the last rendered frame number.
94 double getLastFrameTime() const;
97 * Returns the AVFormatContext structure associated with this video format
99 const AVFormatContext * getAVFormatContext() const;
102 * Returns the AVCodecContext structure associated with this video codec
104 const AVCodecContext * getAVCodecContext() const;
107 * Returns the AVCodec structure associated with this video codec
109 const AVCodec * getAVCodec() const;
112 * Returns the error message text if opening the video failed
114 CStdString getErrorMsg() const;
117 * Decodes and renders the next video frame into the provided texture which
118 * must be in a XB_FMT_A8R8G8B8 format.
119 * The frame will be rescaled to fit the whole texture (i.e. texture width/height)
120 * so make sure the texture aspect ratio is the same as in the original movie.
122 * @param texture The texture to render the frame into. Must be preallocated,
123 * have the appropriate width/height and in XB_FMT_A8R8G8B8 format.
125 * @return true if the frame rendered, false if there are no more frames
127 bool nextFrame( CBaseTexture * texture );
130 * Seeks to a specific time position in the video file. Note that the seek is limited to the keyframes only.
131 * @param time The time to seek to, in seconds
132 * @return true if the seek succeed, false if failed
134 bool seek( double time );
137 * Closes the video stream.
142 bool readFrame( int frame );
144 DllAvFormat *m_dllAvFormat;
145 DllAvCodec *m_dllAvCodec;
146 DllAvUtil *m_dllAvUtil;
147 DllSwScale *m_dllSwScale;
148 AVFormatContext *m_pFormatCtx;
149 AVCodecContext *m_pCodecCtx;
152 AVPicture *m_pFrameRGB;
154 double m_lastFrameTime;
156 // The dimensions of the allocated pFrameRGB
157 unsigned int m_frameRGBwidth;
158 unsigned int m_frameRGBheight;
160 CStdString m_errorMsg;