diff --git a/aegisub/FFmpegSource2/ffavisynth.cpp b/aegisub/FFmpegSource2/ffavisynth.cpp index 2d4a40379..e63f8a674 100644 --- a/aegisub/FFmpegSource2/ffavisynth.cpp +++ b/aegisub/FFmpegSource2/ffavisynth.cpp @@ -18,6 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include #include "ffavisynth.h" #include "utils.h" @@ -74,9 +75,9 @@ AvisynthVideoSource::~AvisynthVideoSource() { FFMS_DestroyVideoSource(VS); } -void AvisynthVideoSource::InitOutputFormat(PixelFormat CurrentFormat, IScriptEnvironment *Env) { +void AvisynthVideoSource::InitOutputFormat(enum PixelFormat CurrentFormat, IScriptEnvironment *Env) { int Loss; - PixelFormat BestFormat = avcodec_find_best_pix_fmt((1 << PIX_FMT_YUVJ420P) | (1 << PIX_FMT_YUV420P) | (1 << PIX_FMT_YUYV422) | (1 << PIX_FMT_RGB32) | (1 << PIX_FMT_BGR24), CurrentFormat, 1 /* Required to prevent pointless RGB32 => RGB24 conversion */, &Loss); + enum PixelFormat BestFormat = avcodec_find_best_pix_fmt((1 << PIX_FMT_YUVJ420P) | (1 << PIX_FMT_YUV420P) | (1 << PIX_FMT_YUYV422) | (1 << PIX_FMT_RGB32) | (1 << PIX_FMT_BGR24), CurrentFormat, 1 /* Required to prevent pointless RGB32 => RGB24 conversion */, &Loss); switch (BestFormat) { case PIX_FMT_YUVJ420P: // stupid yv12 distinctions, also inexplicably completely undeniably incompatible with all other supported output formats diff --git a/aegisub/FFmpegSource2/ffavisynth.h b/aegisub/FFmpegSource2/ffavisynth.h index ce7bdc7eb..a4bb1fda5 100644 --- a/aegisub/FFmpegSource2/ffavisynth.h +++ b/aegisub/FFmpegSource2/ffavisynth.h @@ -41,7 +41,7 @@ private: int FPSNum; int FPSDen; - void InitOutputFormat(PixelFormat CurrentFormat, IScriptEnvironment *Env); + void InitOutputFormat(enum PixelFormat CurrentFormat, IScriptEnvironment *Env); PVideoFrame OutputFrame(const AVFrameLite *SrcPicture, IScriptEnvironment *Env); public: AvisynthVideoSource(const char *SourceFile, int Track, FrameIndex *TrackIndices, int FPSNum, int FPSDen, const char *PP, int Threads, int SeekMode, IScriptEnvironment* Env, char *ErrorMsg, unsigned MsgSize); diff --git a/aegisub/FFmpegSource2/ffms.cpp b/aegisub/FFmpegSource2/ffms.cpp index 101151daa..3f9bd8a09 100644 --- a/aegisub/FFmpegSource2/ffms.cpp +++ b/aegisub/FFmpegSource2/ffms.cpp @@ -18,6 +18,10 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +extern "C" { +#include +} + #include "ffms.h" #include "ffvideosource.h" #include "ffaudiosource.h" @@ -205,3 +209,6 @@ FFMS_API(int) FFMS_WriteIndex(const char *IndexFile, FrameIndex *TrackIndices, c return WriteIndex(IndexFile, TrackIndices, ErrorMsg, MsgSize); } +FFMS_API(enum PixelFormat) FFMS_GetPixFmt(const char *Name) { + return avcodec_get_pix_fmt(Name); +} \ No newline at end of file diff --git a/aegisub/FFmpegSource2/ffms.h b/aegisub/FFmpegSource2/ffms.h index 93ed2390d..b85ca3131 100644 --- a/aegisub/FFmpegSource2/ffms.h +++ b/aegisub/FFmpegSource2/ffms.h @@ -22,7 +22,6 @@ #define FFMS_H #include -#include #ifdef __cplusplus # define EXTERN_C extern "C" @@ -49,6 +48,8 @@ class FrameInfoVector; typedef int (FFMS_CC *IndexCallback)(int State, int64_t Current, int64_t Total, void *Private); +enum PixelFormat; + enum FFMS_SeekMode { FFMS_SEEK_LINEAR_NO_RW = -1, FFMS_SEEK_LINEAR = 0, @@ -98,7 +99,7 @@ struct VideoProperties { int FPSDenominator; int FPSNumerator; int NumFrames; - PixelFormat VPixelFormat; + enum PixelFormat VPixelFormat; int SARNum; int SARDen; int CropTop; @@ -147,5 +148,5 @@ FFMS_API(int) FFMS_WriteTimecodes(FrameInfoVector *FIV, const char *TimecodeFile FFMS_API(FrameIndex *) FFMS_MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, bool IgnoreDecodeErrors, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize); FFMS_API(FrameIndex *) FFMS_ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize); FFMS_API(int) FFMS_WriteIndex(const char *IndexFile, FrameIndex *TrackIndices, char *ErrorMsg, unsigned MsgSize); - +FFMS_API(PixelFormat) FFMS_GetPixFmt(const char *Name); #endif diff --git a/aegisub/FFmpegSource2/ffms2.html b/aegisub/FFmpegSource2/ffms2.html index 8a1ceb373..24564b5e8 100644 --- a/aegisub/FFmpegSource2/ffms2.html +++ b/aegisub/FFmpegSource2/ffms2.html @@ -234,6 +234,7 @@ Note that --enable-w32threads is required for multithreaded decoding to work.

Changes

  • 2.00 beta 7
      +
    • Using ffms2 as a library no longer requires an installed pixfmt.h from libavutil, it is however still required to compile ffms2 and the avisynth plugin part
    • Fix a crash bug at the end of files with b-frames in beta 6 caused by uninitialized null packets
    • Includes TheFluff's wrapper function for 1.21 style syntax
    • Added a simple regression test application to the source
    • diff --git a/aegisub/FFmpegSource2/ffms2rt.cpp b/aegisub/FFmpegSource2/ffms2rt.cpp index a7b993b45..0ecef3b08 100644 --- a/aegisub/FFmpegSource2/ffms2rt.cpp +++ b/aegisub/FFmpegSource2/ffms2rt.cpp @@ -28,7 +28,7 @@ extern "C" { using namespace std; -//#define VERBOSE +#define VERBOSE static int FFMS_CC UpdateProgress(int State, int64_t Current, int64_t Total, void *Private) { @@ -59,7 +59,11 @@ int main(int argc, char *argv[]) { #ifndef VERBOSE FFMS_NoLog(); #endif - + + enum PixelFormat FMT_YV12A = FFMS_GetPixFmt("PIX_FMT_YUV420P)"); + enum PixelFormat FMT_YV12B = FFMS_GetPixFmt("PIX_FMT_YUVJ420P"); + enum PixelFormat FMT_YUY2 = FFMS_GetPixFmt("PIX_FMT_YUV422P"); + av_md5_init(ctx); FrameIndex *FI = FFMS_MakeIndex(argv[1], -1, 0, NULL, false, UpdateProgress, argv[1], ErrorMsg, sizeof(ErrorMsg)); if (!FI) { @@ -103,32 +107,28 @@ int main(int argc, char *argv[]) { Data[1] = AVF->Data[1]; Data[2] = AVF->Data[2]; - switch (VP->VPixelFormat) { - case PIX_FMT_YUV420P: - case PIX_FMT_YUVJ420P: - for (int j = 0; j < VP->Height / 2; j++) { - av_md5_update(ctx, Data[0], VP->Width); - Data[0] += AVF->Linesize[0]; - av_md5_update(ctx, Data[0], VP->Width); - Data[0] += AVF->Linesize[0]; - av_md5_update(ctx, Data[1], VP->Width / 2); - Data[1] += AVF->Linesize[1]; - av_md5_update(ctx, Data[2], VP->Width / 2); - Data[2] += AVF->Linesize[2]; - } - break; - case PIX_FMT_YUV422P: - for (int j = 0; j < VP->Height / 2; j++) { - av_md5_update(ctx, Data[0], VP->Width); - Data[0] += AVF->Linesize[0]; - av_md5_update(ctx, Data[0], VP->Width); - Data[0] += AVF->Linesize[0]; - av_md5_update(ctx, Data[1], VP->Width / 2); - Data[1] += AVF->Linesize[1]; - av_md5_update(ctx, Data[2], VP->Width / 2); - Data[2] += AVF->Linesize[2]; - } - break; + if (VP->VPixelFormat == FMT_YV12A || VP->VPixelFormat == FMT_YV12B) { + for (int j = 0; j < VP->Height / 2; j++) { + av_md5_update(ctx, Data[0], VP->Width); + Data[0] += AVF->Linesize[0]; + av_md5_update(ctx, Data[0], VP->Width); + Data[0] += AVF->Linesize[0]; + av_md5_update(ctx, Data[1], VP->Width / 2); + Data[1] += AVF->Linesize[1]; + av_md5_update(ctx, Data[2], VP->Width / 2); + Data[2] += AVF->Linesize[2]; + } + } else if (VP->VPixelFormat == FMT_YUY2) { + for (int j = 0; j < VP->Height / 2; j++) { + av_md5_update(ctx, Data[0], VP->Width); + Data[0] += AVF->Linesize[0]; + av_md5_update(ctx, Data[0], VP->Width); + Data[0] += AVF->Linesize[0]; + av_md5_update(ctx, Data[1], VP->Width / 2); + Data[1] += AVF->Linesize[1]; + av_md5_update(ctx, Data[2], VP->Width / 2); + Data[2] += AVF->Linesize[2]; + } } }