Skip to content

Commit

Permalink
Merge branch 'master' into ffmpeg-4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
AkarinVS committed May 12, 2022
2 parents ebe2ad2 + e6ea8d9 commit fb891d0
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 30 deletions.
10 changes: 7 additions & 3 deletions AviSynth/libavsmash_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ static void set_frame_properties
VideoInfo vi,
PVideoFrame& avs_frame,
uint32_t sample_number,
int top,
int bottom,
IScriptEnvironment* env
)
{
Expand All @@ -148,7 +150,7 @@ static void set_frame_properties
int64_t duration_den;
bool rgb = vi.IsRGB();
get_sample_duration(vdhp, vi, sample_number, &duration_num, &duration_den);
avs_set_frame_properties(av_frame, NULL, duration_num, duration_den, rgb, avs_frame, env);
avs_set_frame_properties(av_frame, NULL, duration_num, duration_den, rgb, avs_frame, top, bottom, env);
}

static void prepare_video_decoding
Expand Down Expand Up @@ -269,8 +271,10 @@ PVideoFrame __stdcall LSMASHVideoSource::GetFrame( int n, IScriptEnvironment *en
PVideoFrame as_frame;
if( make_frame( vohp, av_frame, as_frame, env ) < 0 )
env->ThrowError( "LSMASHVideoSource: failed to make a frame." );
if (has_at_least_v8)
set_frame_properties(vdhp, av_frame,vi, as_frame, sample_number, env);
if ( has_at_least_v8 )
set_frame_properties( vdhp, av_frame,vi, as_frame, sample_number,
( vohp->repeat_control ) ? vohp->frame_order_list[n].top : n,
( vohp->repeat_control ) ? vohp->frame_order_list[n].bottom : n, env );
return as_frame;
}

Expand Down
10 changes: 7 additions & 3 deletions AviSynth/lwlibav_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ static void set_frame_properties
AVStream* stream,
VideoInfo vi,
PVideoFrame& avs_frame,
int top,
int bottom,
IScriptEnvironment* env
)
{
/* Variable Frame Rate is not supported yet. */
int64_t duration_num = vi.fps_denominator;
int64_t duration_den = vi.fps_numerator;
bool rgb = vi.IsRGB();
avs_set_frame_properties(av_frame, stream, duration_num, duration_den, rgb, avs_frame, env);
avs_set_frame_properties(av_frame, stream, duration_num, duration_den, rgb, avs_frame, top, bottom, env);
}

static void prepare_video_decoding
Expand Down Expand Up @@ -202,8 +204,10 @@ PVideoFrame __stdcall LWLibavVideoSource::GetFrame( int n, IScriptEnvironment *e
PVideoFrame as_frame;
if( make_frame( vohp, av_frame, as_frame, env ) < 0 )
env->ThrowError( "LWLibavVideoSource: failed to make a frame." );
if (has_at_least_v8)
set_frame_properties(av_frame, vdhp->format->streams[vdhp->stream_index], vi, as_frame, env);
if ( has_at_least_v8 )
set_frame_properties( av_frame, vdhp->format->streams[vdhp->stream_index], vi, as_frame,
( vohp->repeat_control ) ? vohp->frame_order_list[n].top : n,
( vohp->repeat_control ) ? vohp->frame_order_list[n].bottom : n, env );
return as_frame;
}

Expand Down
4 changes: 4 additions & 0 deletions AviSynth/video_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ void avs_set_frame_properties
int64_t duration_den,
bool rgb,
PVideoFrame& avs_frame,
int top,
int bottom,
IScriptEnvironment* env

)
Expand Down Expand Up @@ -923,6 +925,8 @@ void avs_set_frame_properties
if (av_frame->interlaced_frame)
field_based = av_frame->top_field_first ? 2 : 1;
env->propSetInt(props, "_FieldBased", field_based, 0);
env->propSetInt(props, "_EncodedFrameTop", top, 0);
env->propSetInt(props, "_EncodedFrameBottom", bottom, 0);
/* Mastering display color volume */
int frame_has_primaries = 0, frame_has_luminance = 0;
const AVFrameSideData* mastering_display_side_data = av_frame_get_side_data(av_frame, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
Expand Down
2 changes: 2 additions & 0 deletions AviSynth/video_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,7 @@ void avs_set_frame_properties
int64_t duration_den,
bool rgb,
PVideoFrame& avs_frame,
int top,
int bottom,
IScriptEnvironment* env
);
8 changes: 6 additions & 2 deletions VapourSynth/libavsmash_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,15 @@ static void set_frame_properties
AVFrame *av_frame,
VSFrameRef *vs_frame,
uint32_t sample_number,
int top,
int bottom,
const VSAPI *vsapi
)
{
int64_t duration_num;
int64_t duration_den;
get_sample_duration( vdhp, vi, sample_number, &duration_num, &duration_den );
vs_set_frame_properties( n, av_frame, NULL, duration_num, duration_den, vs_frame, vsapi );
vs_set_frame_properties( n, av_frame, NULL, duration_num, duration_den, vs_frame, top, bottom, vsapi );
}

static int prepare_video_decoding
Expand Down Expand Up @@ -293,7 +295,9 @@ static const VSFrameRef *VS_CC vs_filter_get_frame( int n, int activation_reason
vsapi->propSetFrame( props, "_Alpha", vs_frame2, paAppend );
vsapi->freeFrame( vs_frame2 );
}
set_frame_properties( vdhp, n, vi, av_frame, vs_frame, sample_number, vsapi );
set_frame_properties( vdhp, n, vi, av_frame, vs_frame, sample_number,
( vohp->repeat_control ) ? vohp->frame_order_list[n].top : n,
( vohp->repeat_control ) ? vohp->frame_order_list[n].bottom : n, vsapi );
return vs_frame;
}

Expand Down
2 changes: 2 additions & 0 deletions VapourSynth/lsmashsource.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* However, when distributing its binary file, it will be under LGPL or GPL. */

#include "../common/cpp_compat.h"
#include "../common/lwindex_version.h"

#include <stdio.h>
#include <stdarg.h>
Expand Down Expand Up @@ -80,6 +81,7 @@ void VS_CC vs_version_create( const VSMap *in, VSMap *out, void *user_data, VSCo
vsapi->propSetData(out, "ffmpeg_version", LIBAVFORMAT_IDENT, -1, paAppend);
vsapi->propSetData(out, "ffmpeg_version", LIBAVUTIL_IDENT, -1, paAppend);
vsapi->propSetData(out, "ffmpeg_version", LIBSWSCALE_IDENT, -1, paAppend);
vsapi->propSetData(out, "lwindex_version", lwindex_version_header(), -1, paAppend);
}

VS_EXTERNAL_API(void) VapourSynthPluginInit( VSConfigPlugin config_func, VSRegisterFunction register_func, VSPlugin *plugin )
Expand Down
8 changes: 6 additions & 2 deletions VapourSynth/lwlibav_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,15 @@ static void set_frame_properties
AVFrame *av_frame,
AVStream *stream,
VSFrameRef *vs_frame,
int top,
int bottom,
const VSAPI *vsapi
)
{
/* Variable Frame Rate is not supported yet. */
int64_t duration_num = vi->fpsDen;
int64_t duration_den = vi->fpsNum;
vs_set_frame_properties( n, av_frame, stream, duration_num, duration_den, vs_frame, vsapi );
vs_set_frame_properties( n, av_frame, stream, duration_num, duration_den, vs_frame, top, bottom, vsapi );
}

static int prepare_video_decoding
Expand Down Expand Up @@ -280,7 +282,9 @@ static const VSFrameRef *VS_CC vs_filter_get_frame( int n, int activation_reason
vsapi->propSetFrame( props, "_Alpha", vs_frame2, paAppend );
vsapi->freeFrame( vs_frame2 );
}
set_frame_properties( n, vi, av_frame, vdhp->format->streams[vdhp->stream_index], vs_frame, vsapi );
set_frame_properties( n, vi, av_frame, vdhp->format->streams[vdhp->stream_index], vs_frame,
( vohp->repeat_control ) ? vohp->frame_order_list[n].top : n,
( vohp->repeat_control ) ? vohp->frame_order_list[n].bottom : n,vsapi );
return vs_frame;
}

Expand Down
4 changes: 4 additions & 0 deletions VapourSynth/video_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,8 @@ void vs_set_frame_properties
int64_t duration_num,
int64_t duration_den,
VSFrameRef *vs_frame,
int top,
int bottom,
const VSAPI *vsapi
)
{
Expand Down Expand Up @@ -1088,6 +1090,8 @@ void vs_set_frame_properties
if( av_frame->interlaced_frame )
field_based = av_frame->top_field_first ? 2 : 1;
vsapi->propSetInt( props, "_FieldBased", field_based, paReplace );
vsapi->propSetInt( props, "_EncodedFrameTop", top, paReplace );
vsapi->propSetInt( props, "_EncodedFrameBottom", bottom, paReplace );
/* Mastering display color volume */
int frame_has_primaries = 0, frame_has_luminance = 0;
const AVFrameSideData *mastering_display_side_data = av_frame_get_side_data( av_frame, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA );
Expand Down
2 changes: 2 additions & 0 deletions VapourSynth/video_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,7 @@ void vs_set_frame_properties
int64_t duration_num,
int64_t duration_den,
VSFrameRef *vs_frame,
int top,
int bottom,
const VSAPI *vsapi
);
29 changes: 19 additions & 10 deletions common/lwindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extern "C"
#include "lwlibav_audio_internal.h"
#include "progress.h"
#include "lwindex.h"
#include "lwindex_version.h"
#include "decode.h"
#include "ffmpeg.h"

Expand Down Expand Up @@ -2066,6 +2067,23 @@ static char *create_lwi_path
return buf;
}

const char *lwindex_version_header() {
static char buffer[128] = "";
if (buffer[0]) return buffer;
uint8_t lwindex_version[4] =
{
(LWINDEX_VERSION >> 24) & 0xff,
(LWINDEX_VERSION >> 16) & 0xff,
(LWINDEX_VERSION >> 8) & 0xff,
LWINDEX_VERSION & 0xff
};
sprintf( buffer, "<LSMASHWorksIndexVersion=%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 ">\n"
"<LibavReaderIndexFile=%d>\n",
lwindex_version[0], lwindex_version[1], lwindex_version[2], lwindex_version[3],
LWINDEX_INDEX_FILE_VERSION );
return buffer;
}

static int create_index
(
lwlibav_file_handler_t *lwhp,
Expand Down Expand Up @@ -2143,16 +2161,7 @@ static int create_index
if( index )
{
/* Write Index file header. */
uint8_t lwindex_version[4] =
{
(LWINDEX_VERSION >> 24) & 0xff,
(LWINDEX_VERSION >> 16) & 0xff,
(LWINDEX_VERSION >> 8) & 0xff,
LWINDEX_VERSION & 0xff
};
fprintf( index, "<LSMASHWorksIndexVersion=%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 ">\n",
lwindex_version[0], lwindex_version[1], lwindex_version[2], lwindex_version[3] );
fprintf( index, "<LibavReaderIndexFile=%d>\n", LWINDEX_INDEX_FILE_VERSION );
fprintf( index, "%s", lwindex_version_header() );
fprintf( index, "<InputFilePath>%s</InputFilePath>\n", lwhp->file_path );
#ifdef _WIN32
wchar_t *wname;
Expand Down
9 changes: 0 additions & 9 deletions common/lwindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@

/* This file is available under an ISC license. */

/* lwindex version
* Major.Minor.Micro.Build */
#define LWINDEX_VERSION ((0 << 24) | (0 << 16) | (3 << 8) | 1)

/* index file version
* This version is bumped when its structure changed so that the lwindex invokes
* reindexing opened file immediately. */
#define LWINDEX_INDEX_FILE_VERSION 16

typedef struct
{
const char *file_path;
Expand Down
17 changes: 17 additions & 0 deletions common/lwindex_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef LWINDEX_VERSION_H
#define LWINDEX_VERSION_H

#include <stdio.h>

/* lwindex version
* Major.Minor.Micro.Build */
#define LWINDEX_VERSION ((0 << 24) | (0 << 16) | (3 << 8) | 1)

/* index file version
* This version is bumped when its structure changed so that the lwindex invokes
* reindexing opened file immediately. */
#define LWINDEX_INDEX_FILE_VERSION 16

const char *lwindex_version_header();

#endif
3 changes: 2 additions & 1 deletion common/video_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ static struct SwsContext *update_scaler_configuration
av_opt_set_int( sws_ctx, "src_format", input_pixel_format, 0 );
av_opt_set_int( sws_ctx, "dst_format", output_pixel_format, 0 );
const AVPixFmtDescriptor *out_fmtdesc = av_pix_fmt_desc_get( output_pixel_format );
const int dst_range = (out_fmtdesc->flags & AV_PIX_FMT_FLAG_RGB) ? 1:0;
// RGB always in full-range, but YUV might also be full-range (e.g. JPEG) as well.
const int dst_range = yuv_range || ((out_fmtdesc->flags & AV_PIX_FMT_FLAG_RGB) ? 1:0);
av_opt_set_int( sws_ctx, "src_range", yuv_range, 0 );
av_opt_set_int( sws_ctx, "dst_range", dst_range, 0 );
const int *yuv2rgb_coeffs = sws_getCoefficients( colorspace );
Expand Down

0 comments on commit fb891d0

Please sign in to comment.