Git Product home page Git Product logo

d2vsource's Introduction

D2V Source for VapourSynth (Example)
------------------------------------

As the title says, this is a D2V parser and decoder for VapourSynth.
There's not much else to say, so let's get right to an example:

    import vapoursynth as vs

    core = vs.get_core()

    core.std.LoadPlugin(path=r'C:\path\to\d2vsource.dll')

    ret = core.d2v.Source(input=r'C:\path\to\my.d2v')

    ret.set_output()

Parameters:
    input   - Full path to input D2V file.
    nocrop  - Always use direct-rendered buffer, which may need cropping.
              Provides a speedup when you know you need to crop your image
              anyway, by avoiding extra memcpy calls.
    rff     - Invoke ApplyRFF (True by default)
    threads - Number of threads FFmpeg should use. Default is 0 (auto).


About RFF Flags
---------------

Unlike DGDecode, it's up to the user to apply RFF flags as they see fit,
by passing rff=True to the source function, or by passing rff=False and
using core.d2v.ApplyRFF(clip, d2v=r'C:\path\to\my.d2v') after calling
the source function. Unless you know your source is 100% FILM, you
probably want to apply these. DGDecode's traditional "Force FILM" mode
isn't really present in this plugin, but if your source or part of it
is 100% FILM, which is the only time you should be Force FILMing anyway,
you can simply set Force FILM in DGIndex, which will set the framerate
properly in the D2V file, and then not apply RFF flags. It's also
feasible to trim away any non-FILM frames and still Force FILM.


Parameters:
    clip - Input clip.
    d2v  - D2V file for parsing RFF flags. This will be optional
           in the future, once VapourSynth gets global metadata
           support.


Known Limitations & Bugs
------------------------

* Only works with D2V files created by DGIndex (version flag 16) or D2VWitch
  (https://github.com/dubhater/D2VWitch).
* Not all the IDCT algorithms in DGDecode are in libavcodec, so I've tried to
  map them as best I could. See idct_algo_conv in d2v.hpp for more info.
* Does not support user specified cropping. Would be easy to add, but I disagree
  with the premise. Use VapourSynth's cropping.
* Needs the full path to the D2V file.
* Probably more I'm forgetting!


How to Build
------------

At some point I will add a proper build system.

On Windows (Visual Studio):

    Install FFmpeg using vcpkg and then use the included Visual Studio solution.

    Please note that MinGW-built FFmpeg will be faster than one build with Visual
    Studio, due to its use of inline assembly. Also note that only MinGW-w64 is
    supported.

On Linux, Mac OS X, or MinGW:

    ./autogen.sh
    ./configure
    make
    make install

d2vsource's People

Contributors

4re avatar chikuzen avatar darealshinji avatar dubhater avatar dwbuiten avatar jsaowji avatar lighterowl avatar maki-rxrz avatar myrsloik avatar setsugennoao avatar sl1pkn07 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

d2vsource's Issues

checking for libav minimum version

Hi! Can you add a check to configure.ac to check if the available libav* libraries are recent enough? Right now it only checks for existence.

PC scale color range doesn't seem to work as expected

The Problem

d2v_source YUVRGB_Scale=1 (PC) with ffmpeg -color_range pc (PC) returns a limited/TV color range output, not the expected full/PC color range.

You may be thinking, "Oh, maybe the source is just limited/TV range then?", if that's the case, then choosing the value for YUVRGB_Scale and -color_range in FFMPEG doesn't seem to matter and it just ignores the manually specified value, otherwise it should have given me an FFMPEG output where the blacks and whites are washed out, it shouldn't look "normal" if the source isn't PC color range.

image
Left: YUVRGB_Scale=1 ffmpeg -color_range pc | Right: YUVRGB_Scale=1 ffmpeg -color_range default (default is TV?)

Left has saturated blacks and saturated whites. Right has correct colors outputting at presumably PC range, yet ffmpeg used default color_range switch which is presumably tv and the D2V used YUVRGB_Scale=1 (PC). What?

Edit: It's been discovered that it essentially needs the -color_range of the opposite that YUVRGB_Scale is, because d2vsource sets _ColorRange to be the opposite of what YUVRGB_Scale is. See #41 for more information and why it may or may not have initially been intentional.

Here are the results of the combinations possible:

YUVRGB_Scale ffmpeg -color_range Correct color?
0 (TV) default (TV?) true
0 (TV) pc false
1 (PC) default (TV?) true
1 (PC) pc false

Here's a reminder that according to the d2v file and DGIndex manual, YUVRGB_Scale's options are 0 for TV and 1 for PC.

VapourSynth-Editor's Preview Window also only had the correct colors for YUVRGB_Scale=1.

None of the options where I matched YUVRGB_Scale and -color_range did the color output work correctly.

Make (compilation) error at applyrff4.cpp

When trying to compile for Fedora Linux 38, the compiler fails at src/vs4/applyrff4.cpp, with the following output after executing "make":

  CXX      src/core/compat.lo
  CXX      src/core/d2v.lo
  CXX      src/core/decode.lo
  CXX      src/vs/applyrff.lo
  CXX      src/vs/d2vsource.lo
  CXX      src/vs/directrender.lo
  CXX      src/vs/vapoursynth.lo
  CXX      src/vs4/applyrff4.lo
../src/vs4/applyrff4.cpp: In function 'VSNode* vs4::rffCreate(VSNode*, const char*, VSCore*, const VSAPI*)':
../src/vs4/applyrff4.cpp:143:25: error: 'const VSAPI' {aka 'const struct VSAPI'} has no member named 'AddNodeRef'; did you mean 'addNodeRef'?
  143 |     data->node = vsapi->AddNodeRef(clip);
      |                         ^~~~~~~~~~
      |                         addNodeRef
../src/vs4/applyrff4.cpp:205:45: error: cannot convert 'VSNode*' to 'const char*' in argument passing
  205 |     VSNode *out = vsapi->createVideoFilter2(out, "applyrff", &data->vi, rffGetFrame, rffFree, fmParallel, deps, 1, data.get(), core);
      |                                             ^~~
      |                                             |
      |                                             VSNode*
../src/vs4/applyrff4.cpp: At global scope:
../src/vs4/applyrff4.cpp:122:19: warning: 'void vs4::rffFree(void*, VSCore*, const VSAPI*)' defined but not used [-Wunused-function]
  122 | static void VS_CC rffFree(void *instanceData, VSCore *core, const VSAPI *vsapi)
      |                   ^~~~~~~
../src/vs4/applyrff4.cpp:37:29: warning: 'const VSFrame* vs4::rffGetFrame(int, int, void*, void**, VSFrameContext*, VSCore*, const VSAPI*)' defined but not used [-Wunused-function]
   37 | static const VSFrame *VS_CC rffGetFrame(int n, int activationReason, void *instanceData, void **frameData,
      |                             ^~~~~~~~~~~
make: *** [Makefile:586: src/vs4/applyrff4.lo] Error 1

Bug report about open GOP.

I found the few bug about open GOP.
Please check the following bug report and sample code of fix.

[1] The case where the 2nd GOP is Open GOP.

core/decode.cpp(280)
if (!(g.info & GOP_FLAG_CLOSED) && (f.gop - 1 > 0)) {

This code refers to the frame at a position different from that specified at the time of random access to 2nd GOP.
This problem is solved by the following changes.

if (!(g.info & GOP_FLAG_CLOSED) && (f.gop > 0)) {

[2] The case where the 1st GOP is open GOP.

When reading from the first frame at the sequential access, there is a difference in the order of the frames in the DGDecode and d2vsource.

[example] 1st GOP lentgh:15-frames
GOP frames: B B I B B P B B P B B P B B P
DGDecode : I I I B B P B B P B B P B B P
d2vsource : I B B P B B P B B P B B P

When reading the 1st GOP, the first B-Frames are excluded in d2vsource.

DGDecode is correct the B-Frames that require of the previous GOP by first I-Frame.
A similar process is required in d2vsource.

[sample code]
http://pastebin.com/uX6fHJwe

I think this is not the best code.
Please consider the code of a better fix.

Endless loop with ffmpeg 5.0 and vapoursynth R57-2

Opening any d2v file (generated with either dgindex or d2vwitch) causes vspipe/vsedit to go into an endless loop. Just calling d2v.Source is enough to trigger this :

import vapoursynth as vs
src = vs.core.d2v.Source('/tmp/foobar/VIDEO_TS/VTS_01_1.d2v')

Breaking a running vspipe under gdb causes a stop in the exact same location :

Thread 1 (Thread 0x7ffff767e5c0 (LWP 11527) "vspipe"):
#0  0x00007ffff7c301ec in read () at /usr/lib/libc.so.6
#1  0x00007ffff7bb32d8 in __GI__IO_file_xsgetn () at /usr/lib/libc.so.6
#2  0x00007ffff7ba82f9 in fread () at /usr/lib/libc.so.6
#3  0x00007fffe2d92ab6 in fread (__stream=<optimized out>, __n=32768, __size=1, __ptr=0x555555863180) at /usr/include/bits/stdio2.h:293
#4  read_packet(void*, uint8_t*, int) (opaque=0x5555557de420, buf=0x555555863180 "6\215\032\064a\206ѣF\214\060\332\064hц\033F\215\032\060\303hѣF\030m\032\064h\303\r\243F\215\030a\264hѣ\f6\215\032\064a\206ѣF\214\060\300", size=32768) at ../d2vsource/src/core/decode.cpp:113
#5  0x00007ffff236a879 in avio_r8 () at /usr/lib/libavformat.so.59
#6  0x00007ffff242bcf6 in  () at /usr/lib/libavformat.so.59
#7  0x00007ffff242c88c in  () at /usr/lib/libavformat.so.59
#8  0x00007ffff238fbe6 in  () at /usr/lib/libavformat.so.59
#9  0x00007ffff2392cdb in avformat_find_stream_info () at /usr/lib/libavformat.so.59
#10 0x00007fffe2d9347d in decodeframe(int, d2vcontext*, decodecontext*, AVFrame*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) (frame_num=frame_num@entry=0, ctx=0x5555557de070, dctx=0x5555557de420, out=<optimized out>, err="") at ../d2vsource/src/core/decode.cpp:406

Running d2vsource from newffmpeg branch.

building on MacOS X 10.11.6

trying to build the filter on Mac OS X I end up without a dylib file

Selurs-Mac-mini:d2vsource selur$ ./autogen.sh
autoreconf: Entering directory .' autoreconf: configure.ac: not using Gettext autoreconf: running: aclocal --force autoreconf: configure.ac: tracing autoreconf: running: glibtoolize --copy --force glibtoolize: putting auxiliary files in '.'. glibtoolize: copying file './ltmain.sh' glibtoolize: Consider adding 'AC_CONFIG_MACRO_DIRS([m4])' to configure.ac, glibtoolize: and rerunning glibtoolize and aclocal. glibtoolize: Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am. autoreconf: running: /usr/local/Cellar/autoconf/2.69/bin/autoconf --force autoreconf: configure.ac: not using Autoheader autoreconf: running: automake --add-missing --copy --force-missing configure.ac:8: installing './compile' configure.ac:8: installing './config.guess' configure.ac:8: installing './config.sub' configure.ac:5: installing './install-sh' configure.ac:5: installing './missing' Makefile.am: installing './depcomp' autoreconf: Leaving directory.'
Selurs-Mac-mini:d2vsource selur$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking build system type... x86_64-apple-darwin15.6.0
checking host system type... x86_64-apple-darwin15.6.0
checking how to print strings... printf
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 196608
checking how to convert x86_64-apple-darwin15.6.0 file names to x86_64-apple-darwin15.6.0 format... func_convert_file_noop
checking how to convert x86_64-apple-darwin15.6.0 file names to toolchain format... func_convert_file_noop
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld option to reload object files... -r
checking for objdump... no
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @file support... no
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for lipo... lipo
checking for otool... otool
checking for otool64... no
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for -force_load linker flag... yes
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... yes
checking for gcc option to produce PIC... -fno-common -DPIC
checking if gcc PIC flag -fno-common -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin15.6.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
checking how to run the C++ preprocessor... g++ -E
checking for ld used by g++... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
checking whether the g++ linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
checking for g++ option to produce PIC... -fno-common -DPIC
checking if g++ PIC flag -fno-common -DPIC works... yes
checking if g++ static flag -static works... no
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin15.6.0 dyld
checking how to hardcode library paths into programs... immediate
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
checking for _LARGEFILE_SOURCE value needed for large files... no
checking for pkg-config... /usr/local/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for libavcodec... yes
checking for libavformat... yes
checking for libavutil... yes
checking for VapourSynth... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
config.status: executing libtool commands
Selurs-Mac-mini:d2vsource selur$ make
CXX src/core/compat.lo
CXX src/core/d2v.lo
CXX src/core/decode.lo
src/core/decode.cpp:450:45: warning: 'codec' is deprecated [-Wdeprecated-declarations]
if (dctx->fctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
^
/usr/local/Cellar/ffmpeg/3.1.3/include/libavformat/avformat.h:880:21: note: 'codec' has been explicitly marked deprecated here
AVCodecContext *codec;
^
src/core/decode.cpp:491:13: warning: 'avcodec_decode_video2' is deprecated [-Wdeprecated-declarations]
avcodec_decode_video2(dctx->avctx, out, &av_ret, &dctx->inpkt);
^
/usr/local/Cellar/ffmpeg/3.1.3/include/libavcodec/avcodec.h:4753:5: note: 'avcodec_decode_video2' has been explicitly marked deprecated here
int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
^
/usr/local/Cellar/ffmpeg/3.1.3/include/libavcodec/avcodec.h:1557:16: warning: 'convergence_duration' is deprecated [-Wdeprecated-declarations]
typedef struct AVPacket {
^
/usr/local/Cellar/ffmpeg/3.1.3/include/libavcodec/avcodec.h:1609:13: note: 'convergence_duration' has been explicitly marked deprecated here
int64_t convergence_duration;
^
src/core/decode.cpp:510:25: warning: 'avcodec_decode_video2' is deprecated [-Wdeprecated-declarations]
int r = avcodec_decode_video2(dctx->avctx, out, &av_ret, &dctx->inpkt);
^
/usr/local/Cellar/ffmpeg/3.1.3/include/libavcodec/avcodec.h:4753:5: note: 'avcodec_decode_video2' has been explicitly marked deprecated here
int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
^
/usr/local/Cellar/ffmpeg/3.1.3/include/libavcodec/avcodec.h:1557:16: warning: 'convergence_duration' is deprecated [-Wdeprecated-declarations]
typedef struct AVPacket {
^
/usr/local/Cellar/ffmpeg/3.1.3/include/libavcodec/avcodec.h:1609:13: note: 'convergence_duration' has been explicitly marked deprecated here
int64_t convergence_duration;
^
/usr/local/Cellar/ffmpeg/3.1.3/include/libavcodec/avcodec.h:1557:16: warning: 'convergence_duration' is deprecated [-Wdeprecated-declarations]
typedef struct AVPacket {
^
/usr/local/Cellar/ffmpeg/3.1.3/include/libavcodec/avcodec.h:1609:13: note: 'convergence_duration' has been explicitly marked deprecated here
int64_t convergence_duration;
^
6 warnings generated.
CXX src/vs/applyrff.lo
CXX src/vs/d2vsource.lo
CXX src/vs/directrender.lo
CXX src/vs/vapoursynth.lo
CXXLD libd2vsource.la

am I missing something or is this a bug?

fail build with ffmpeg 4.0

make: Entering directory '/tmp/makepkg/vapoursynth-plugin-d2vsource-git/src/build'
  CXX      src/core/compat.lo
  CXX      src/core/d2v.lo
In file included from ../d2vsource/src/core/d2v.cpp:36:
../d2vsource/src/core/d2v.hpp:71:5: error: 'FF_IDCT_XVIDMMX' was not declared in this scope
     FF_IDCT_XVIDMMX,
     ^~~~~~~~~~~~~~~
../d2vsource/src/core/d2v.hpp:71:5: note: suggested alternative: 'FF_IDCT_XVID'
     FF_IDCT_XVIDMMX,
     ^~~~~~~~~~~~~~~
     FF_IDCT_XVID
../d2vsource/src/core/d2v.cpp: In function 'd2vcontext* d2vparse(const char*, std::__cxx11::string&)':
../d2vsource/src/core/d2v.cpp:96:32: warning: 'void* memset(void*, int, size_t)' clearing an object of type 'd2vcontext' {aka 'struct d2vcontext'} with no trivial copy-assignment; use assignment or value-initialization instead [-Wclass-memaccess]
     memset(ret, 0, sizeof(*ret));
                                ^
In file included from ../d2vsource/src/core/d2v.cpp:36:
../d2vsource/src/core/d2v.hpp:82:16: note: 'd2vcontext' {aka 'struct d2vcontext'} declared here
 typedef struct d2vcontext {
                ^~~~~~~~~~
make: *** [Makefile:539: src/core/d2v.lo] Error 1
make: Leaving directory '/tmp/makepkg/vapoursynth-plugin-d2vsource-git/src/build'

OSX Compile Issue

The way push_back is used in applyrff (between lines 193 to 211) seem to cause issues with compiling on OSX.

src/vs/applyrff.cpp:192:36: error: expected expression
data->fields.push_back({ i, Progressive });
^
src/vs/applyrff.cpp:193:36: error: expected expression
data->fields.push_back({ i, Progressive });
^
src/vs/applyrff.cpp:196:40: error: expected expression
data->fields.push_back({ i, Progressive });
^
src/vs/applyrff.cpp:197:40: error: expected expression
data->fields.push_back({ i, Progressive });
^
src/vs/applyrff.cpp:200:44: error: expected expression
data->fields.push_back({ i, Progressive });
^
src/vs/applyrff.cpp:201:44: error: expected expression
data->fields.push_back({ i, Progressive });
^
src/vs/applyrff.cpp:207:36: error: expected expression
data->fields.push_back({ i, tff ? Top : Bottom });
^
src/vs/applyrff.cpp:208:36: error: expected expression
data->fields.push_back({ i, tff ? Bottom : Top });
^
src/vs/applyrff.cpp:211:40: error: expected expression
data->fields.push_back({ i, tff ? Top : Bottom });
^

Fail to build with ffmpeg 5

Debian unstable amd64 ffmpeg 5.0

src/core/decode.cpp: In function 'decodecontext* decodeinit(d2vcontext*, int, std::string&)':
src/core/decode.cpp:168:11: warning: 'void* memset(void*, int, size_t)' clearing an object of type 'decodecontext' {aka 'struct decodecontext'} with no trivial copy-assignment; use assignment or value-initialization instead [-Wclass-memaccess]
  168 |     memset(ret, 0, sizeof(*ret));
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from src/core/decode.cpp:35:
src/core/decode.hpp:33:16: note: 'decodecontext' {aka 'struct decodecontext'} declared here
   33 | typedef struct decodecontext {
      |                ^~~~~~~~~~~~~
src/core/decode.cpp:223:44: error: invalid conversion from 'const AVCodec*' to 'AVCodec*' [-fpermissive]
  223 |         ret->incodec = avcodec_find_decoder(AV_CODEC_ID_MPEG1VIDEO);
      |                        ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
      |                                            |
      |                                            const AVCodec*
src/core/decode.cpp:225:44: error: invalid conversion from 'const AVCodec*' to 'AVCodec*' [-fpermissive]
  225 |         ret->incodec = avcodec_find_decoder(AV_CODEC_ID_MPEG2VIDEO);
      |                        ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
      |                                            |
      |                                            const AVCodec*
src/core/decode.cpp:245:17: error: 'AVCodecContext' {aka 'struct AVCodecContext'} has no member named 'refcounted_frames'
  245 |     ret->avctx->refcounted_frames = 1;
      |                 ^~~~~~~~~~~~~~~~~
src/core/decode.cpp: In function 'int decodeframe(int, d2vcontext*, decodecontext*, AVFrame*, std::string&)':
src/core/decode.cpp:429:23: warning: 'void av_init_packet(AVPacket*)' is deprecated [-Wdeprecated-declarations]
  429 |         av_init_packet(&dctx->inpkt);
      |         ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/libavformat/avformat.h:316,
                 from src/core/decode.cpp:28:
/usr/include/x86_64-linux-gnu/libavcodec/packet.h:506:6: note: declared here
  506 | void av_init_packet(AVPacket *pkt);
      |      ^~~~~~~~~~~~~~
src/core/decode.cpp:484:13: error: 'avcodec_decode_video2' was not declared in this scope; did you mean 'avcodec_decode_subtitle2'?
  484 |             avcodec_decode_video2(dctx->avctx, out, &av_ret, &dctx->inpkt);
      |             ^~~~~~~~~~~~~~~~~~~~~
      |             avcodec_decode_subtitle2
src/core/decode.cpp:503:25: error: 'avcodec_decode_video2' was not declared in this scope; did you mean 'avcodec_decode_subtitle2'?
  503 |                 int r = avcodec_decode_video2(dctx->avctx, out, &av_ret, &dctx->inpkt);
      |                         ^~~~~~~~~~~~~~~~~~~~~
      |                         avcodec_decode_subtitle2
make: *** [Makefile:557: src/core/decode.lo] Error 1

Un'make'able

vaposy@encoder:~/src/d2vsource$ CFLAGS="-I$HOME/include" LDFLAGS="-L$HOME/lib" ./configure \
>   --install="$HOME/lib"
CXXFLAGS/LDFLAGS checking...
checking for vapoursynth headers...
checking for libavutil...
checking for libavformat...
checking for libavcodec...

settings...
CXX          = g++
LD           = g++
STRIP        = strip
CXXFLAGS     = -Os -ffast-math -Wall -D__STDC_CONSTANT_MACROS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I. -I./vs -I./core  -fPIC -I/home/vaposy/include   -I/home/vaposy/include/vapoursynth -I/home/vaposy/include
LDFLAGS      = -shared -Wl,-Bsymbolic -fPIC
LIBS         = -L/home/vaposy/lib -lavformat -lavcodec -lavutil
LIBNAME      = libd2vsource.so
install path = /home/vaposy/lib
configure finished.
vaposy@encoder:~/src/d2vsource$ make -j$(nproc)
g++ -Os -ffast-math -Wall -D__STDC_CONSTANT_MACROS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I. -I./vs -I./core  -fPIC -I/home/vaposy/include   -I/home/vaposy/include/vapoursynth -I/home/vaposy/include   -c vs/applyrff.cpp -o vs/applyrff.o
g++ -Os -ffast-math -Wall -D__STDC_CONSTANT_MACROS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I. -I./vs -I./core  -fPIC -I/home/vaposy/include   -I/home/vaposy/include/vapoursynth -I/home/vaposy/include   -c vs/d2vsource.cpp -o vs/d2vsource.o
g++ -Os -ffast-math -Wall -D__STDC_CONSTANT_MACROS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I. -I./vs -I./core  -fPIC -I/home/vaposy/include   -I/home/vaposy/include/vapoursynth -I/home/vaposy/include   -c vs/directrender.cpp -o vs/directrender.o
g++ -Os -ffast-math -Wall -D__STDC_CONSTANT_MACROS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I. -I./vs -I./core  -fPIC -I/home/vaposy/include   -I/home/vaposy/include/vapoursynth -I/home/vaposy/include   -c vs/vapoursynth.cpp -o vs/vapoursynth.o
vs/directrender.cpp: In function ‘int VSGetBuffer(AVCodecContext*, AVFrame*, int)’:
vs/directrender.cpp:44:14: error: ‘PIX_FMT_YUV420P’ was not declared in this scope
         case PIX_FMT_YUV420P:
              ^
vs/directrender.cpp:47:14: error: ‘PIX_FMT_YUV422P’ was not declared in this scope
         case PIX_FMT_YUV422P:
              ^
make: *** [vs/directrender.o] Error 1
make: *** Waiting for unfinished jobs....
vaposy@encoder:~/src/d2vsource$

Requesting the last frame breaks d2vsource

Python 3.3.5 (default, Mar 10 2014, 03:21:31) 
[GCC 4.8.2 20140206 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import vapoursynth as vs
>>> c = vs.get_core()
>>> clip = c.d2v.Source("vol 01.d2v")
>>> clip.get_frame(clip.num_frames - 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "vapoursynth.pyx", line 607, in vapoursynth.VideoNode.get_frame (build/temp.linux-x86_64-3.3/pyrex/vapoursynth.c:10435)
vapoursynth.Error: Seek pattern broke d2vsource! Please send a sample.
>>> 

I think any DVD will do. The d2v files were all made by dgindex. They all have multiple vobs. Dgdecode reports the same frame counts.

d2vsource version is the latest from git. ffmpeg version is 2.1.4.

The segfault

https://aur.archlinux.org/packages/vapoursynth-editor-git/#comment-830646

sl1pkn07 commented on 2021-10-10 22:58

i can confirm the segfault, but is not problem by vsedit

└───╼ python
Python 3.9.7 (default, Aug 31 2021, 13:28:12)
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import vapoursynth as vs
core = vs.core
clip = core.d2v.Source('Amaranth.vob.d2v')
Traceback (most recent call last):
File "", line 1, in
File "vapoursynth.pyx", line 2501, in vapoursynth.Function.call
vapoursynth.Error: D2V cannot be opened.
clip = core.d2v.Source('/home/sl1pkn07/aplicaciones/foosynth-test/Amaranth.vob.d2v')
Violación de segmento (`core' generado)

so is a problem with d2vsource

Source loading as BFF when it's TFF

Sample: https://mega.nz/file/t9gjxTLY#ILclLeRtd5_NLoJZyqL1e5yjs_TpQMsO9Ym9_mAD0wc

DGIndex, MediaInfo, and MPV all recognize it as TFF,
DGIndex
MediaInfo

However, after loading it with core.d2v.Source() in VapourSynth, it loads as BFF,
VapourSynth

VapourSynth Script:

clip = core.d2v.Source("mmp_intro_sample.d2v")
clip = core.text.ClipInfo(clip)

--

This is causing Judder when bob deinterlaced as every 2 fields are out of order. It also confuses QTGMC and causes sort of "white luma ghosting" (no color, no outlines).

Judder showcase: https://mega.nz/file/VpgiSTJZ#dDqLpsDibPElEZv7EYn46Y9pGebzsYPiyVvFxxW17FI

The fix for me is to just run SetFieldBased to TFF. However, if a source is not 100.00% interlaced, doing this as a fix would be problematic.
Fix showcase: https://mega.nz/file/Mkw2zC5Y#N6wrjhNbfMAl9RFEkq1-B0dV4nBfCMCiJyUN9KjAg_k

Infinite loop due to undecodeable frame

It happens here:

while(!av_ret) {

Both DGIndex and D2V Witch detect a certain frame in the stream, but ffmpeg doesn't return a frame for the packet that contains it, just silently swallows the packet. It's a P frame at the end of the second to last GOP. DGDecode appears to decode it, so maybe it's a bug in ffmpeg.

To reproduce the infinite loop, take any working d2v file and add a frame at the end. It has the same effect as ffmpeg not decoding one of the frames. I'm not supposed to post my sample anywhere public.

I'm not sure how this problem should be handled.

Bug: Duplicate and out-of-sync frames if first GOP starts with B pictures

Assume the very first GOP has the following structure (in display order): BBIBBPBBP... and the GOP is not marked as closed (D2VWitch does this). Also assume that pictures are requested linearly, i.e., 0, 1, 2, ... Then when src/core/decode.cpp:decodeframe() is asked for picture 0, it will return picture 0 — fine. If now asked for picture 1, however, it will return frame 0 again: decodeframe() finds that the first I picture follows the requested picture, decides it has to start the decoding process again (which is superfluous, but not wrong), and set the picture offset to 0 (cf. “offset = n > f.offset ? 0 : f.offset - n” on line 313). When asked for picture 2 (i.e., the I picture), it again sets the offset to 0 (same source line) and will deliver picture 0 again, and after that it will deliver picture 1 when asked for 3, 2 for 4, etc.

This “only” results in duplicate pictures, but it also breaks frame-accurate access, because if frames are requested linearly, say, 0, 1, 2, ..., 100, spanning several GOPs, you will get pictures 0, 0, 0, 1, 2, ..., 98, but if you request picture 100 by jumping directly to it, you do get the correct picture, i.e., 100.

I have attached a patch but because I could not get my head around the current code, it is basically a complete re-write of decodeframe(). Feel free to laugh your behind off and dismiss it out of hand.

0001-BUG-If-the-very-first-GOP-is-a-sequence-of-say-BBIBB.patch.txt

PS: ffms2 seems to have the same problem.

"Invalid location" for valid Location offsets

"Invalid location in D2V header" can be triggered for valid Location offsets in certain situations.

Example:
Location=4,68350,6,34ff4

This is valid (start file < end file, so naturally start offset < end offset) and works in AviSynth with Mpeg2Source.

It triggers the following check in core/d2v.cpp:

if (ret->loc.startfile < 0 || ret->loc.startoffset < 0 || ret->loc.endfile < ret->loc.startfile || ret->loc.endoffset < ret->loc.startoffset) { err = "Invalid location in D2V header."; goto fail; }

The start/end files are not considered for ret->loc.endoffset < ret->loc.startoffset, so it throws an error in this case, because 34ff4 < 68350, even though 34ff4 is the offset for file 6.

No codec provided to avcodec_open2()

Hello, I am testing Vapoursynth and d2vsource but having some problems. I have tested and I am pretty sure something is wrong with my script or compiled d2vsource

Programs:

Linux 4.18.0-0 (Debian 9)
Python 3.6
VS Core R45 built from latest git
Cython3 version 0.28.4
d2vsource built from latest git, built against ffmpeg below
x264 0.157.2935 545de2f
ffmpeg version N-47470-gfc94e9704e-static

Script:

import vapoursynth as vs
import functools
core = vs.get_core()

video = core.d2v.Source('source.ts.d2v')
video = core.std.Trim(video, 0, 1000)

video.set_output()

I made softlink to /usr/local/lib/libd2vsource.so inside /usr/local/lib/vapoursynth, and then I get this problem:

$ vspipe --y4m testing.vpy - | x264 --demuxer y4m - --output vs_test.mkv

[NULL @ 0x00000000] No codec provided to avcodec_open2()
Script evaluation failed:
Python exception: Cannot open decoder.

Traceback (most recent call last):
  File "src/cython/vapoursynth.pyx", line 1927, in vapoursynth.vpy_evaluateScript
  File "src/cython/vapoursynth.pyx", line 1928, in vapoursynth.vpy_evaluateScript
  File "testing.vpy", line 6, in <module>
    video = core.d2v.Source('source.ts.d2v')
  File "src/cython/vapoursynth.pyx", line 1833, in vapoursynth.Function.__call__
vapoursynth.Error: Cannot open decoder.

The same issue above happens even just checking the script with vspipe --info. I also tried remaking the .d2v with D2VWitch and they are identical files.

Source file is MPEG2 in .ts format. I wonder, what is it I am doing incorrect, or what might be broken?
Greetings and thanks for guidance!

Output is faded compared to ffms2

I've only tested this with one video so far, but I noticed that the colors I got with d2vsource are noticeably duller than ffms2. Is there a reason for that? VapourSynth Editor reports that the format is YUV422P8 for both of them.

c.d2v.Source(input=r'video.d2v')
example-d2vsource

c.ffms2.Source(source="video.ts")
example-ffms2

Field Operation's aren't working correctly

image
MPEG-2 @ 24000/1001 Progressive (2:3 Pulldown)
* edit: It's actually MPEG-2 @ 30000/1001 (Hard-Telecine that used 2:3 Pulldown) Progressive with some sections being Interlaced, this specific screenshot is of an unnecessary frame caused by Hard-Telecine
This screenshot is from Family Guy Volume 1 Disc 1 Episode 1.

As you can see, it is showing interlacing very very frequently.
It's like this for both "Honor Pulldown Flags" and "Ignore Pulldown Flags" Field Operations.
It's frame count, duration and fps all seems accurate, yet when I play it, it seems super choppy and slower than it should be.

If I set rff=False on either Field Operation, no interlacing occurs, but its out of sync, the duration drops from 22:30~ to 18:29, yet somehow feels accurate in terms of motion speed and such. If I use AssumeFPS to set it to 24000/1001 (original FPS) it results in 23:06 duration and feels super slow and choppy.

  1. rff=False = no interlacing e.t.c, but the FPS is still 30000/1001
  2. core.std.AssumeFPS to whatever the framerate was meant to be (in my case 24000/1001 as it used 2:3 Pulldown)
  3. Preview in vs-edit and it feels slow for some really odd reason, it feels like you stretched the footage or something, but...
  4. If you create an encode and mux the audio in to make sure everything lines up, everything feels fine and syncs up, it's an odd issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.