diff --git a/FFmpegSource/ffbase.cpp b/FFmpegSource/ffbase.cpp index 2e18a66b2..07e117ebe 100644 --- a/FFmpegSource/ffbase.cpp +++ b/FFmpegSource/ffbase.cpp @@ -100,8 +100,14 @@ bool FFBase::SaveTimecodesToFile(const char *ATimecodeFile, int64_t ScaleD, int6 if (!TimecodeFile) return false; + std::set Timecodes; for (int i = 0; i < VI.num_frames; i++) - fprintf(TimecodeFile, "%f\r\n", (FrameToDTS[i].DTS * ScaleD) / (double)ScaleN); + Timecodes.insert(FrameToDTS[i].DTS); + + fprintf(TimecodeFile, "# timecode format v2\r\n"); + + for (std::set::iterator Cur=Timecodes.begin(); Cur!=Timecodes.end(); Cur++) + fprintf(TimecodeFile, "%f\r\n", (*Cur * ScaleD) / (double)ScaleN); fclose(TimecodeFile); return true; diff --git a/FFmpegSource/ffmatroskasource.cpp b/FFmpegSource/ffmatroskasource.cpp index a1d5d40ca..536851474 100644 --- a/FFmpegSource/ffmatroskasource.cpp +++ b/FFmpegSource/ffmatroskasource.cpp @@ -113,7 +113,7 @@ FFMatroskaSource::FFMatroskaSource(const char *ASource, int AVideoTrack, int AAu Env->ThrowError("FFmpegSource: Could not open video codec"); // Fix for mpeg2 and other formats where decoding a frame is necessary to get information about the stream - if (VideoCodecContext->pix_fmt == PIX_FMT_NONE) { + if (VideoCodecContext->pix_fmt == PIX_FMT_NONE || VideoCodecContext->width == 0 || VideoCodecContext->height == 0) { mkv_SetTrackMask(MF, ~(1 << VideoTrack)); int64_t Dummy; DecodeNextFrame(DecodeFrame, &Dummy, Env); @@ -126,6 +126,9 @@ FFMatroskaSource::FFMatroskaSource(const char *ASource, int AVideoTrack, int AAu VI.fps_denominator = 1; VI.fps_numerator = 30; + if (VI.width <= 0 || VI.height <= 0) + Env->ThrowError("FFmpegSource: Codec returned zero size video"); + SetOutputFormat(VideoCodecContext->pix_fmt, Env); InitPP(VI.width, VI.height, APPString, AQuality, VideoCodecContext->pix_fmt, Env); diff --git a/FFmpegSource/ffmpegsource.avsi b/FFmpegSource/ffmpegsource.avsi new file mode 100644 index 000000000..59e5ea846 --- /dev/null +++ b/FFmpegSource/ffmpegsource.avsi @@ -0,0 +1 @@ +loadplugin("ffmpegsource.dll") diff --git a/FFmpegSource/ffmpegsource.cpp b/FFmpegSource/ffmpegsource.cpp index 76e06ecbb..0d7d581ad 100644 --- a/FFmpegSource/ffmpegsource.cpp +++ b/FFmpegSource/ffmpegsource.cpp @@ -84,12 +84,22 @@ FFmpegSource::FFmpegSource(const char *ASource, int AVideoTrack, int AAudioTrack if (avcodec_open(VideoCodecContext, VideoCodec) < 0) Env->ThrowError("FFmpegSource: Could not open video codec"); + // Fix for mpeg2 and other formats where decoding a frame is necessary to get information about the stream + if (SeekMode >= 0 && (VideoCodecContext->pix_fmt == PIX_FMT_NONE || VideoCodecContext->width == 0 || VideoCodecContext->height == 0)) { + int64_t Dummy; + DecodeNextFrame(DecodeFrame, &Dummy); + av_seek_frame(FormatContext, VideoTrack, 0, AVSEEK_FLAG_BACKWARD); + } + VI.image_type = VideoInfo::IT_TFF; VI.width = VideoCodecContext->width; VI.height = VideoCodecContext->height; VI.fps_denominator = FormatContext->streams[VideoTrack]->time_base.num; VI.fps_numerator = FormatContext->streams[VideoTrack]->time_base.den; + if (VI.width <= 0 || VI.height <= 0) + Env->ThrowError("FFmpegSource: Codec returned zero size video"); + // sanity check framerate if (VI.fps_denominator > VI.fps_numerator || VI.fps_denominator <= 0 || VI.fps_numerator <= 0) { VI.fps_denominator = 1; @@ -220,7 +230,7 @@ FFmpegSource::FFmpegSource(const char *ASource, int AVideoTrack, int AAudioTrack // Adjust framerate to match the duration of the first frame if (FrameToDTS.size() >= 2) { - int64_t DTSDiff = (double)(FrameToDTS[1].DTS - FrameToDTS[0].DTS); + int64_t DTSDiff = FFMAX(FrameToDTS[1].DTS - FrameToDTS[0].DTS, 1); VI.fps_denominator *= DTSDiff; } } diff --git a/FFmpegSource/ffmpegsource.h b/FFmpegSource/ffmpegsource.h index c1b0be41d..8c6a26200 100644 --- a/FFmpegSource/ffmpegsource.h +++ b/FFmpegSource/ffmpegsource.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include diff --git a/FFmpegSource/ffmpegsource.html b/FFmpegSource/ffmpegsource.html index 20971c0a0..71681c4ac 100644 --- a/FFmpegSource/ffmpegsource.html +++ b/FFmpegSource/ffmpegsource.html @@ -6,103 +6,9 @@ FFmpegSource Documentation

FFmpegSource Documentation

- -

Changes

-
    -
  • 1.12
      -
    • Now caches the last fully decoded frame to increase the reliability of seekmode=-1 and possibly reduce seeking in other modes
    • -
    • Video that needs to be converted to a suitable output format should now always have correct colors (was reversed in 1.11 and inconsistent in earlier versions)
    • -
    • Added seekmode=-1 which is mostly useful for opening image files very carefully
    • -
    • Now throws an error if the container is unseekable and seekmode=-1 isn't set
    • -
    • Updated FFmpeg to rev 10492 + camtasia swapped colors fix
    • -
  • - -
  • 1.11
      -
    • Now officially uses the MIT license
    • -
    • Much cleaner source
    • -
    • Can be compiled without support for compressing the audio cache with FLAC
    • -
    • Supports more audio formats in matroska
    • -
    • RGB24 output no longer has swapped colors if the video is converted to it for output (there still seems to be some bugs lurking when conversion is done with libswscale)
    • -
    • Fixed an access violation on close when no audio is opened (introduced in 1.10)
    • -
    • Updated FFmpeg to rev 10423
    • -
  • - -
  • 1.10
      -
    • The audio cache compression level is now ignored if the source isn't 16bit and the raw format is used instead
    • -
    • FLAC is now actually initialized properly so the cache actually works for files that aren't stereo (16bit limit still applies)
    • -
    • Now uses proper callbacks for FLAC so it works with larger than 2GB files
    • -
    • Doesn't (over)write the video cache with an empty one in certain cases when avformat is used for the source
    • -
  • - -
  • 1.9
      -
    • Added the possibility to compress the audio cache with FLAC (currently only works with 16bit audio)
    • -
    • Added another planar YUV 4:2:0 format to the supported output formats (fixes certain mov files)
    • -
    • Less memory is now allocated on the stack which makes av_find_stream_info() work for all files (fixes certain mov files)
    • -
    • Updated FFmpeg to rev 10186
    • -
  • - -
  • 1.8
      -
    • Updated FFmpeg to rev 10141
    • -
  • - -
  • 1.7
      -
    • Updated FFmpeg
    • -
    • Fixed error with mkv for codecs without codec private data and the first packet doesn't belong to them
    • -
  • - -
  • 1.6
      -
    • Fixed ac3 and other formats stored in mkv
    • -
    • Skip unnecessary seeking when index information already exists (gif file opening only 3/4 broken now)
    • -
    • Throws an error when the selected audio/video track has no frames/samples
    • -
  • - -
  • 1.5
      -
    • Fixed a bug that made avformat opened files only return audio if only the audio cache needed to be created
    • -
    • Rejects more corrupt cache files
    • -
    • Fixed crash when a 0 byte audio cache file is present
    • -
    • Improved framerate guessing for avformat which now takes takes the duration of the first frame into account
    • -
    • Fixed a bug introduced in 1.4 that would make the number of reported frames too high for files opened with avformat
    • -
    • Fixed mpeg2 and probably some other formats stored in mkv
    • -
    • Fixed issues with large mkv files and large audio cache files
    • -
    • FFmpeg is now compiled with liba52 and faad2
    • -
  • - -
  • 1.4
      -
    • Uses the average framerate for mkv files
    • -
    • Naming scheme of cache files changed to prevent confusion with the default names in files with multiple tracks of the same type
    • -
    • Use mmx optimizations in swscaler when possible
    • -
    • Now uses normal windows linebreaks in all files
    • -
    • Removed FFAudioSource
    • -
    • Merged FFVideoSource and FFAudioRefSource into FFmpegSource
    • -
    • Added postprocessing with libpostproc in FFmpegSource and separately in FFPP
    • -
  • - -
  • 1.3
      -
    • Compiled against ffmpeg rev9620
    • -
    • Added FFAudioRefSource
    • -
    • Added FFAudioSource (has big issues)
    • -
    • Renamed FFmpegSource to FFVideoSource
    • -
    • Adjusted seeking in the forward direction to only be done if the requested frame is more than 10 frames away to reduce unnecessary seeking
    • -
    • Now outputs the last frame properly when there are decoding delays
    • -
  • - -
  • 1.2
      -
    • Compiled against ffmpeg rev9451
    • -
    • Somewhat cleaner source code
    • -
    • Linear access in addition to a few other modes of seeking can now be forced
    • -
    • Can now save the index information to a file which makes subsequent file opening fast
    • -
    • No longer skips indexing for any format
    • -
  • - -
  • 1.1
      -
    • Skip indexing for avi
    • -
    • Prefix all error messages with the plugin name
    • -
    • Can write v2 timecodes to a file
    • -
    • Fixed reported framerate
    • -
  • - -
- +

+Loads video files without sucking +

Compatibility - Video

    @@ -120,6 +26,12 @@ FFmpegSource Documentation
  • Sample accurate in all containers
+

Loading the Plugin - Dll Hell

+

+In order to load FFmpegSource all included dlls except ffmpegsource.dll must be located in the path or in the current working directory. +It is also possible to autoload it if you put all dlls and the avsi file in avisynth's autoloading directory (usually C:\Program Files\AviSynth 2.5\plugins). +

+

Usage

FFmpegSource(string source, int vtrack = -1, int atrack = -2, string timecodes, bool vcache = true, string vcachefile, string acachefile, int accompression = -1, string pp, int ppquality = 6, int seekmode = 1)
@@ -235,7 +147,7 @@ tn:64:128:256

FFmpeg svn from http://ffmpeg.mplayerhq.hu/

-

FLAC (optional) from http://flac.sourceforge.net/

+

FLAC (optional) from http://flac.sourceforge.net/ (static library seems to be broken)

Required FFmpeg Configuration: ./configure --enable-shared --disable-static --enable-memalign-hack --enable-gpl --enable-swscaler

@@ -243,5 +155,111 @@ tn:64:128:256

Suggested Additional Options: --disable-encoders --disable-muxers --enable-small

+

Changes

+
    +
  • 1.13
      +
    • Now always sorts the output timecodes so native avc in mkv won't have out of order values
    • +
    • Fixed the missing '# timecode format v2' line in saved timecode files
    • +
    • Now properly handles video files where the output resolution isn't known until a frame has been decoded (seems to fix flv4)
    • +
    • Now throws an error if the video decoder returns zero size video
    • +
    • Added an avsi file for easy autoloading
    • +
    • Updated libFLAC to 1.2.1
    • +
    • Updated FFmpeg to rev 10671 + camtasia swapped colors fix
    • +
  • + +
  • 1.12
      +
    • Now caches the last fully decoded frame to increase the reliability of seekmode=-1 and possibly reduce seeking in other modes
    • +
    • Video that needs to be converted to a suitable output format should now always have correct colors (was reversed in 1.11 and inconsistent in earlier versions)
    • +
    • Added seekmode=-1 which is mostly useful for opening image files very carefully
    • +
    • Now throws an error if the container is unseekable and seekmode=-1 isn't set
    • +
    • Updated FFmpeg to rev 10492 + camtasia swapped colors fix
    • +
  • + +
  • 1.11
      +
    • Now officially uses the MIT license
    • +
    • Much cleaner source
    • +
    • Can be compiled without support for compressing the audio cache with FLAC
    • +
    • Supports more audio formats in matroska
    • +
    • RGB24 output no longer has swapped colors if the video is converted to it for output (there still seems to be some bugs lurking when conversion is done with libswscale)
    • +
    • Fixed an access violation on close when no audio is opened (introduced in 1.10)
    • +
    • Updated FFmpeg to rev 10423
    • +
  • + +
  • 1.10
      +
    • The audio cache compression level is now ignored if the source isn't 16bit and the raw format is used instead
    • +
    • FLAC is now actually initialized properly so the cache actually works for files that aren't stereo (16bit limit still applies)
    • +
    • Now uses proper callbacks for FLAC so it works with larger than 2GB files
    • +
    • Doesn't (over)write the video cache with an empty one in certain cases when avformat is used for the source
    • +
  • + +
  • 1.9
      +
    • Added the possibility to compress the audio cache with FLAC (currently only works with 16bit audio)
    • +
    • Added another planar YUV 4:2:0 format to the supported output formats (fixes certain mov files)
    • +
    • Less memory is now allocated on the stack which makes av_find_stream_info() work for all files (fixes certain mov files)
    • +
    • Updated FFmpeg to rev 10186
    • +
  • + +
  • 1.8
      +
    • Updated FFmpeg to rev 10141
    • +
  • + +
  • 1.7
      +
    • Updated FFmpeg
    • +
    • Fixed error with mkv for codecs without codec private data and the first packet doesn't belong to them
    • +
  • + +
  • 1.6
      +
    • Fixed ac3 and other formats stored in mkv
    • +
    • Skip unnecessary seeking when index information already exists (gif file opening only 3/4 broken now)
    • +
    • Throws an error when the selected audio/video track has no frames/samples
    • +
  • + +
  • 1.5
      +
    • Fixed a bug that made avformat opened files only return audio if only the audio cache needed to be created
    • +
    • Rejects more corrupt cache files
    • +
    • Fixed crash when a 0 byte audio cache file is present
    • +
    • Improved framerate guessing for avformat which now takes takes the duration of the first frame into account
    • +
    • Fixed a bug introduced in 1.4 that would make the number of reported frames too high for files opened with avformat
    • +
    • Fixed mpeg2 and probably some other formats stored in mkv
    • +
    • Fixed issues with large mkv files and large audio cache files
    • +
    • FFmpeg is now compiled with liba52 and faad2
    • +
  • + +
  • 1.4
      +
    • Uses the average framerate for mkv files
    • +
    • Naming scheme of cache files changed to prevent confusion with the default names in files with multiple tracks of the same type
    • +
    • Use mmx optimizations in swscaler when possible
    • +
    • Now uses normal windows linebreaks in all files
    • +
    • Removed FFAudioSource
    • +
    • Merged FFVideoSource and FFAudioRefSource into FFmpegSource
    • +
    • Added postprocessing with libpostproc in FFmpegSource and separately in FFPP
    • +
  • + +
  • 1.3
      +
    • Compiled against ffmpeg rev9620
    • +
    • Added FFAudioRefSource
    • +
    • Added FFAudioSource (has big issues)
    • +
    • Renamed FFmpegSource to FFVideoSource
    • +
    • Adjusted seeking in the forward direction to only be done if the requested frame is more than 10 frames away to reduce unnecessary seeking
    • +
    • Now outputs the last frame properly when there are decoding delays
    • +
  • + +
  • 1.2
      +
    • Compiled against ffmpeg rev9451
    • +
    • Somewhat cleaner source code
    • +
    • Linear access in addition to a few other modes of seeking can now be forced
    • +
    • Can now save the index information to a file which makes subsequent file opening fast
    • +
    • No longer skips indexing for any format
    • +
  • + +
  • 1.1
      +
    • Skip indexing for avi
    • +
    • Prefix all error messages with the plugin name
    • +
    • Can write v2 timecodes to a file
    • +
    • Fixed reported framerate
    • +
  • + +
+