Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[prefs] Indexing to file preferences #525

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions avidemux/common/ADM_commonUI/DIA_prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ uint32_t refreshCapValue=100;
bool askPortAvisynth=false;
uint32_t defaultPortAvisynth = 9999;

uint32_t indexingTSPSfiles=2;
uint32_t indexingMKVfiles=1;
uint32_t indexingMP4files=1;

uint32_t toneMappingHDR = 1;
uint32_t outOfGamutHDR = 0;
float targetLumHDR = DEFAULT_TARGET_LUMINANCE_HDR;
Expand Down Expand Up @@ -186,6 +190,20 @@ std::string currentSdlDriver=getSdlDriverName();
defaultPortAvisynth=9999;
}
ADM_info("Avisynth port: %d\n",defaultPortAvisynth);

//Indexing
if(!prefs->get(INDEXING_TS_PS_INDEXING, &indexingTSPSfiles))
{
indexingTSPSfiles = 2;
}
if(!prefs->get(INDEXING_MKV_INDEXING, &indexingMKVfiles))
{
indexingMKVfiles = 1;
}
if(!prefs->get(INDEXING_MP4_INDEXING, &indexingMP4files))
{
indexingMP4files = 1;
}

// HDR
if (!prefs->get(HDR_TONEMAPPING,&toneMappingHDR)) toneMappingHDR=1;
Expand Down Expand Up @@ -433,6 +451,21 @@ std::string currentSdlDriver=getSdlDriverName();
diaElemUInteger uintDefaultPortAvisynth(&defaultPortAvisynth,QT_TRANSLATE_NOOP("adm","Default port to use"),1024,65535);
frameAvisynth.swallow(&togAskAvisynthPort);
frameAvisynth.swallow(&uintDefaultPortAvisynth);

// Indexing
diaElemFrame frameIndexing(QT_TRANSLATE_NOOP("adm","Indexing to file"));
diaMenuEntry indexingEntries[] = {
{0, QT_TRANSLATE_NOOP("adm","Disabled"), NULL },
{1, QT_TRANSLATE_NOOP("adm","Read only"), NULL },
{2, QT_TRANSLATE_NOOP("adm","Enabled"), NULL }
};
diaElemMenu menuIndexingTsPs(&indexingTSPSfiles, QT_TRANSLATE_NOOP("adm","TS and PS files:"), NB_ITEMS(indexingEntries), indexingEntries);
diaElemMenu menuIndexingMKV(&indexingMKVfiles, QT_TRANSLATE_NOOP("adm","MKV files:"), NB_ITEMS(indexingEntries), indexingEntries);
diaElemMenu menuIndexingMP4(&indexingMP4files, QT_TRANSLATE_NOOP("adm","MP4 files:"), NB_ITEMS(indexingEntries), indexingEntries);

frameIndexing.swallow(&menuIndexingTsPs);
frameIndexing.swallow(&menuIndexingMKV);
frameIndexing.swallow(&menuIndexingMP4);

// Editor cache
diaElemFrame frameCache(QT_TRANSLATE_NOOP("adm","Caching of decoded pictures"));
Expand Down Expand Up @@ -571,7 +604,7 @@ std::string currentSdlDriver=getSdlDriverName();
/* Automation */

/* Import */
diaElem *diaImport[]={&frameMultiLoad, &framePics, &frameAvisynth};
diaElem *diaImport[]={&frameMultiLoad, &framePics, &frameAvisynth, &frameIndexing};
diaElemTabs tabImport(QT_TRANSLATE_NOOP("adm","Import"),NB_ELEM(diaImport),diaImport);

/* Output */
Expand Down Expand Up @@ -906,7 +939,12 @@ std::string currentSdlDriver=getSdlDriverName();
// Avisynth
prefs->set(AVISYNTH_AVISYNTH_DEFAULTPORT,defaultPortAvisynth);
prefs->set(AVISYNTH_AVISYNTH_ALWAYS_ASK, askPortAvisynth);


// Indexing
prefs->set(INDEXING_TS_PS_INDEXING, indexingTSPSfiles);
prefs->set(INDEXING_MKV_INDEXING, indexingMKVfiles);
prefs->set(INDEXING_MP4_INDEXING, indexingMP4files);

// HDR
prefs->set(HDR_TONEMAPPING, toneMappingHDR);
targetLumHDR = dTargetLumHDR;
Expand Down
16 changes: 16 additions & 0 deletions avidemux_core/ADM_coreDemuxerMpeg/src/ADM_indexFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ADM_default.h"
#include "ADM_indexFile.h"
#include "ctype.h"
#include "prefs.h"
/**

*/
Expand Down Expand Up @@ -120,6 +121,21 @@ dmxToken *indexFile::searchToken(const char *name)

bool indexFile::open(const char *name)
{
uint32_t indexingPref = 2;
if (!prefs->get(INDEXING_TS_PS_INDEXING, &indexingPref)) indexingPref = 2;
if (NULL != getenv("ADM_FORCE_INDEX_TO_FILE") && !strncmp(getenv("ADM_FORCE_INDEX_TO_FILE"), "1", 1))
indexingPref = 2;

if (indexingPref==0)
{
mFile = mfopen(name,"rt");
if(!mFile)
{
return false;
}
return true;
}

file=ADM_fopen(name,"rt");
if(!file)
{
Expand Down
3 changes: 3 additions & 0 deletions avidemux_core/ADM_coreUtils/include/prefs2_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ DEFAULT_DELETE_FIRST_PASS_LOG_FILES, //bool
AVISYNTH_AVISYNTH_ALWAYS_ASK, //bool
AVISYNTH_AVISYNTH_DEFAULTPORT, //uint32_t
AVISYNTH_AVISYNTH_LOCALPORT, //uint32_t
INDEXING_TS_PS_INDEXING, //uint32_t
INDEXING_MKV_INDEXING, //uint32_t
INDEXING_MP4_INDEXING, //uint32_t
RESET_ENCODER_ON_VIDEO_LOAD, //bool
PICTURES_LOAD_IN_REVERSE_ORDER, //bool
PICTURES_FPS_TYPE, //uint32_t
Expand Down
6 changes: 6 additions & 0 deletions avidemux_core/ADM_coreUtils/src/prefs2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ uint32_t:avisynth_defaultport, 9999, 1024, 65535
uint32_t:avisynth_localport, 0, 1024, 65535
}
#
indexing{
uint32_t:ts_ps_indexing, 2, 0, 2
uint32_t:mkv_indexing, 1, 0, 2
uint32_t:mp4_indexing, 1, 0, 2
}
#
bool:reset_encoder_on_video_load, 0, 0, 1
#
pictures{
Expand Down
5 changes: 5 additions & 0 deletions avidemux_core/ADM_coreUtils/src/prefs2.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ struct {
uint32_t avisynth_defaultport;
uint32_t avisynth_localport;
}avisynth;
struct {
uint32_t ts_ps_indexing;
uint32_t mkv_indexing;
uint32_t mp4_indexing;
}indexing;
bool reset_encoder_on_video_load;
struct {
bool load_in_reverse_order;
Expand Down
3 changes: 3 additions & 0 deletions avidemux_core/ADM_coreUtils/src/prefs2_desc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ extern const ADM_paramList my_prefs_struct_param[]={
{"avisynth.avisynth_always_ask",offsetof(my_prefs_struct,avisynth.avisynth_always_ask),"bool",ADM_param_bool},
{"avisynth.avisynth_defaultport",offsetof(my_prefs_struct,avisynth.avisynth_defaultport),"uint32_t",ADM_param_uint32_t},
{"avisynth.avisynth_localport",offsetof(my_prefs_struct,avisynth.avisynth_localport),"uint32_t",ADM_param_uint32_t},
{"indexing.ts_ps_indexing",offsetof(my_prefs_struct,indexing.ts_ps_indexing),"uint32_t",ADM_param_uint32_t},
{"indexing.mkv_indexing",offsetof(my_prefs_struct,indexing.mkv_indexing),"uint32_t",ADM_param_uint32_t},
{"indexing.mp4_indexing",offsetof(my_prefs_struct,indexing.mp4_indexing),"uint32_t",ADM_param_uint32_t},
{"reset_encoder_on_video_load",offsetof(my_prefs_struct,reset_encoder_on_video_load),"bool",ADM_param_bool},
{"pictures.load_in_reverse_order",offsetof(my_prefs_struct,pictures.load_in_reverse_order),"bool",ADM_param_bool},
{"pictures.fps_type",offsetof(my_prefs_struct,pictures.fps_type),"uint32_t",ADM_param_uint32_t},
Expand Down
5 changes: 5 additions & 0 deletions avidemux_core/ADM_coreUtils/src/prefs2_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ json.addBool("avisynth_always_ask",key->avisynth.avisynth_always_ask);
json.addUint32("avisynth_defaultport",key->avisynth.avisynth_defaultport);
json.addUint32("avisynth_localport",key->avisynth.avisynth_localport);
json.endNode();
json.addNode("indexing");
json.addUint32("ts_ps_indexing",key->indexing.ts_ps_indexing);
json.addUint32("mkv_indexing",key->indexing.mkv_indexing);
json.addUint32("mp4_indexing",key->indexing.mp4_indexing);
json.endNode();
json.addBool("reset_encoder_on_video_load",key->reset_encoder_on_video_load);
json.addNode("pictures");
json.addBool("load_in_reverse_order",key->pictures.load_in_reverse_order);
Expand Down
3 changes: 3 additions & 0 deletions avidemux_core/ADM_coreUtils/src/prefs2_pref.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ static optionDesc myOptions[]={
{ AVISYNTH_AVISYNTH_ALWAYS_ASK,"avisynth.avisynth_always_ask" ,ADM_param_bool ,"0", 0, 1},
{ AVISYNTH_AVISYNTH_DEFAULTPORT,"avisynth.avisynth_defaultport" ,ADM_param_uint32_t ,"9999", 1024, 65535},
{ AVISYNTH_AVISYNTH_LOCALPORT,"avisynth.avisynth_localport" ,ADM_param_uint32_t ,"0", 1024, 65535},
{ INDEXING_TS_PS_INDEXING,"indexing.ts_ps_indexing" ,ADM_param_uint32_t ,"2", 0, 2},
{ INDEXING_MKV_INDEXING,"indexing.mkv_indexing" ,ADM_param_uint32_t ,"1", 0, 2},
{ INDEXING_MP4_INDEXING,"indexing.mp4_indexing" ,ADM_param_uint32_t ,"1", 0, 2},
{ RESET_ENCODER_ON_VIDEO_LOAD,"reset_encoder_on_video_load" ,ADM_param_bool ,"0", 0, 1},
{ PICTURES_LOAD_IN_REVERSE_ORDER,"pictures.load_in_reverse_order" ,ADM_param_bool ,"0", 0, 1},
{ PICTURES_FPS_TYPE,"pictures.fps_type" ,ADM_param_uint32_t ,"1", 0, 6},
Expand Down
14 changes: 9 additions & 5 deletions avidemux_plugins/ADM_demuxers/Matroska/ADM_mkvIndexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "ADM_videoInfoExtractor.h"
#include "ADM_vidMisc.h"
#include "ADM_metaToFile.h"
#include "prefs.h"

#define VIDEO _tracks[0]

#if 0
Expand Down Expand Up @@ -762,13 +764,15 @@ uint8_t mkvHeader::indexClusters(ADM_ebml_file *parser)
const char *ss;
uint64_t pos;
uint8_t res=1;
bool indexOnDisk = true;
bool indexAllowOverwrite = false;

if (NULL != getenv("ADM_NOINDEX_MKV") && !strncmp(getenv("ADM_NOINDEX_MKV"), "1", 1))
indexOnDisk = false;
uint32_t indexingPref = 1;
if (!prefs->get(INDEXING_MKV_INDEXING, &indexingPref)) indexingPref = 1;
if (NULL != getenv("ADM_FORCE_INDEX_TO_FILE") && !strncmp(getenv("ADM_FORCE_INDEX_TO_FILE"), "1", 1))
indexingPref = 2;


if (indexOnDisk)
if (indexingPref > 0)
{
if (NULL != getenv("ADM_MKV_INDEX_ALLOW_OVERWRITE") && !strncmp(getenv("ADM_MKV_INDEX_ALLOW_OVERWRITE"), "1", 1))
indexAllowOverwrite = true;
Expand Down Expand Up @@ -853,7 +857,7 @@ uint8_t mkvHeader::indexClusters(ADM_ebml_file *parser)
_work = NULL;
//ADM_info("[MKV] Found %u clusters\n",(int)_clusters.size());

if (indexOnDisk)
if (indexingPref==2)
{
if ((res == ADM_OK) && (!!VIDEO.index.size()))
{
Expand Down
20 changes: 11 additions & 9 deletions avidemux_plugins/ADM_demuxers/Mp4/ADM_mp4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ version 2 media descriptor :
#include "ADM_mp3info.h"
#include "ADM_dcainfo.h"
#include "ADM_audioXiphUtils.h"
#include "prefs.h"

#if 1
#define aprintf(...) {}
Expand Down Expand Up @@ -382,13 +383,14 @@ uint8_t MP4Header::open(const char *name)

_idxName = name;
_idxName += ".idxb";
bool indexOnDisk = true;
bool indexAllowOverwrite = false;

if (NULL != getenv("ADM_NOINDEX_MP4") && !strncmp(getenv("ADM_NOINDEX_MP4"), "1", 1))
indexOnDisk = false;

if (indexOnDisk)
uint32_t indexingPref = 1;
if (!prefs->get(INDEXING_MP4_INDEXING, &indexingPref)) indexingPref = 1;
if (NULL != getenv("ADM_FORCE_INDEX_TO_FILE") && !strncmp(getenv("ADM_FORCE_INDEX_TO_FILE"), "1", 1))
indexingPref = 2;

if (indexingPref>0)
{
if (NULL != getenv("ADM_MP4_INDEX_ALLOW_OVERWRITE") && !strncmp(getenv("ADM_MP4_INDEX_ALLOW_OVERWRITE"), "1", 1))
indexAllowOverwrite = true;
Expand Down Expand Up @@ -524,7 +526,7 @@ uint8_t MP4Header::open(const char *name)
if(extractSPSInfo_mp4Header(VDEO.extraData,VDEO.extraDataSize,&info))
{
bool indexLoadedFromDisk = false;
if (indexOnDisk)
if (indexingPref>0)
{
if (loadIndex(_idxName, fileSize))
{
Expand Down Expand Up @@ -648,7 +650,7 @@ uint8_t MP4Header::open(const char *name)
ADM_info("Field encoded H.264 stream detected, # fields: %u\n",fields);
else
ADM_info("Probably a frame encoded H.264 stream.\n");
if (indexOnDisk && !cancelled)
if ((indexingPref==2) && !cancelled)
{
saveIndex(_idxName, fileSize, indexAllowOverwrite);
}
Expand All @@ -660,7 +662,7 @@ uint8_t MP4Header::open(const char *name)
if(extractSPSInfoH265(VDEO.extraData,VDEO.extraDataSize,&info))
{
bool indexLoadedFromDisk = false;
if (indexOnDisk)
if (indexingPref>0)
{
if (loadIndex(_idxName, fileSize))
{
Expand Down Expand Up @@ -732,7 +734,7 @@ uint8_t MP4Header::open(const char *name)
work=NULL;
delete [] bfer;
bfer=NULL;
if (indexOnDisk && !cancelled)
if ((indexingPref==2) && !cancelled)
{
saveIndex(_idxName, fileSize, indexAllowOverwrite);
}
Expand Down
7 changes: 6 additions & 1 deletion avidemux_plugins/ADM_demuxers/MpegPS/ADM_ps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "DIA_coreToolkit.h"
#include "ADM_indexFile.h"
#include "ADM_ps.h"
#include "prefs.h"

#include <math.h>
#define MY_CLASS psHeader
Expand All @@ -36,10 +37,14 @@ uint8_t psHeader::open(const char *name)
{
char *idxName=(char *)malloc(strlen(name)+6);
uint8_t r=1;
uint32_t indexingPref = 2;
if (!prefs->get(INDEXING_TS_PS_INDEXING, &indexingPref)) indexingPref = 2;
if (NULL != getenv("ADM_FORCE_INDEX_TO_FILE") && !strncmp(getenv("ADM_FORCE_INDEX_TO_FILE"), "1", 1))
indexingPref = 2;

sprintf(idxName,"%s.idx2",name);
ListOfIndexFiles.push_back(idxName);
if(!ADM_fileExist(idxName))
if(!ADM_fileExist(idxName) || (indexingPref==0))
r=psIndexer(name);
if(r!=ADM_OK)
{
Expand Down
28 changes: 24 additions & 4 deletions avidemux_plugins/ADM_demuxers/MpegPS/ADM_psIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ADM_vidMisc.h"
#include "DIA_coreToolkit.h"
#include "ADM_coreUtils.h"
#include "prefs.h"

static const char Type[5]={'X','I','P','B','P'}; // Frame type
static const char Structure[6]={'X','T','B','F','C','S'}; // Invalid, Top, Bottom, Frame, Frame+TFF, Frame+BFF
Expand Down Expand Up @@ -197,14 +198,33 @@ uint8_t PsIndexer::run(const char *file)
char *indexName=(char *)malloc(strlen(file)+6);
sprintf(indexName,"%s.idx2",file);

index=qfopen(indexName,"wt",true);
if(!index)
uint32_t indexingPref = 2;
if (!prefs->get(INDEXING_TS_PS_INDEXING, &indexingPref)) indexingPref = 2;
if (NULL != getenv("ADM_FORCE_INDEX_TO_FILE") && !strncmp(getenv("ADM_FORCE_INDEX_TO_FILE"), "1", 1))
indexingPref = 2;

if (indexingPref == 2)
{
index=qfopen(indexName,"wt",true);
if(!index)
{
printf("[PsIndex] Cannot create %s\n",indexName);
mFile = mfopen(indexName,"wt");
if (!mFile)
{
printf("[PsIndex] Cannot create memFile either\n");
free(indexName);
return 0;
}
}
}
else
{
printf("[PsIndex] Cannot create %s\n",indexName);
index = NULL;
mFile = mfopen(indexName,"wt");
if (!mFile)
{
printf("[PsIndex] Cannot create memFile either\n");
printf("[PsIndex] Cannot create memFile\n");
free(indexName);
return 0;
}
Expand Down
9 changes: 7 additions & 2 deletions avidemux_plugins/ADM_demuxers/MpegTS/ADM_ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "ADM_indexFile.h"
#include "ADM_ts.h"
#include "ADM_videoInfoExtractor.h"
#include "prefs.h"

#define MY_CLASS tsHeader
#include "ADM_coreDemuxerMpegTemplate.cpp.h"
Expand All @@ -36,10 +37,14 @@ uint8_t tsHeader::open(const char *name)
{
char *idxName=(char *)malloc(strlen(name)+6);
uint8_t r=1;

uint32_t indexingPref = 2;
if (!prefs->get(INDEXING_TS_PS_INDEXING, &indexingPref)) indexingPref = 2;
if (NULL != getenv("ADM_FORCE_INDEX_TO_FILE") && !strncmp(getenv("ADM_FORCE_INDEX_TO_FILE"), "1", 1))
indexingPref = 2;

sprintf(idxName,"%s.idx2",name);
ListOfIndexFiles.push_back(idxName);
if(!ADM_fileExist(idxName))
if(!ADM_fileExist(idxName) || (indexingPref==0))
r=tsIndexer(name);
if(r!=ADM_OK)
{
Expand Down
Loading