Add preference setting to reset encoder on video load

Started by eumagga0x2a, October 12, 2016, 10:05:47 PM

Previous topic - Next topic

eumagga0x2a

The following patch adds a preference to discard changes to encoder and output container config when loading a video (default: preserve). It is based on http://avidemux.org/smif/index.php/topic,16935.msg77501.html#msg77501.

diff --git a/avidemux/common/ADM_commonUI/DIA_prefs.cpp b/avidemux/common/ADM_commonUI/DIA_prefs.cpp
index fd8503c..24ecdb1 100644
--- a/avidemux/common/ADM_commonUI/DIA_prefs.cpp
+++ b/avidemux/common/ADM_commonUI/DIA_prefs.cpp
@@ -62,6 +62,7 @@ uint32_t msglevel=2;

uint32_t mixer=0;
bool     doAutoUpdate=false;
+bool     loadDefault=false;
char     *alsaDevice=NULL;

bool     balternate_mp3_tag=true;
@@ -160,6 +161,8 @@ std::string currentSdlDriver=getSdlDriverName();

         prefs->get(UPDATE_ENABLED,&doAutoUpdate);

+        prefs->get(RESET_ENCODER_ON_VIDEO_LOAD,&loadDefault);
+
         // Multithreads
         prefs->get(FEATURES_THREADING_LAVC, &lavcThreads);

@@ -235,6 +238,7 @@ std::string currentSdlDriver=getSdlDriverName();
         diaElemToggle useSysTray(&useTray,QT_TRANSLATE_NOOP("adm","_Use systray while encoding"));
         diaElemToggle allowAnyMpeg(&mpeg_no_limit,QT_TRANSLATE_NOOP("adm","_Accept non-standard audio frequency for DVD"));
         diaElemToggle openDml(&use_odml,QT_TRANSLATE_NOOP("adm","Create _OpenDML files"));
+        diaElemToggle resetEncoder(&loadDefault,QT_TRANSLATE_NOOP("adm","_Revert to saved default output settings on video load"));
         diaElemToggle checkForUpdate(&doAutoUpdate,QT_TRANSLATE_NOOP("adm","_Check for new release"));


@@ -433,8 +437,8 @@ std::string currentSdlDriver=getSdlDriverName();


         /* User Interface */
-        diaElem *diaUser[]={&useSysTray,&menuMessage,&menuLanguage,&checkForUpdate};
-        diaElemTabs tabUser(QT_TRANSLATE_NOOP("adm","User Interface"),4,diaUser);
+        diaElem *diaUser[]={&useSysTray,&menuMessage,&menuLanguage,&resetEncoder,&checkForUpdate};
+        diaElemTabs tabUser(QT_TRANSLATE_NOOP("adm","User Interface"),5,diaUser);

          /* Automation */

@@ -592,6 +596,8 @@ std::string currentSdlDriver=getSdlDriverName();
             prefs->set(MESSAGE_LEVEL,msglevel);
             // Use tray while encoding
             prefs->set(FEATURES_USE_SYSTRAY,useTray);
+            // Discard changes to output config on video load
+            prefs->set(RESET_ENCODER_ON_VIDEO_LOAD, loadDefault);

             // VDPAU
             prefs->set(FEATURES_VDPAU,bvdpau);
diff --git a/avidemux/common/gui_main.cpp b/avidemux/common/gui_main.cpp
index a96d935..38a0a0b 100644
--- a/avidemux/common/gui_main.cpp
+++ b/avidemux/common/gui_main.cpp
@@ -682,7 +682,11 @@ int A_openVideo (const char *name)
         res = video_body->addFile(longname);

     //  DIA_StopBusy ();
-    UI_reset();
+    bool loadDefault;
+    if(!prefs->get(RESET_ENCODER_ON_VIDEO_LOAD, &loadDefault)) loadDefault=false;
+    // if true, discard changes in output config on video load
+    if(loadDefault)
+        A_loadDefaultSettings();
     // forget last project file
     video_body->setProjectName("");

diff --git a/avidemux_core/ADM_coreUtils/include/prefs2_list.h b/avidemux_core/ADM_coreUtils/include/prefs2_list.h
index 09819cd..9724e81 100644
--- a/avidemux_core/ADM_coreUtils/include/prefs2_list.h
+++ b/avidemux_core/ADM_coreUtils/include/prefs2_list.h
@@ -47,3 +47,4 @@ MPEGSPLIT_AUTOSPLIT, //uint32_t
AVISYNTH_AVISYNTH_ALWAYS_ASK, //bool
AVISYNTH_AVISYNTH_DEFAULTPORT, //uint32_t
AVISYNTH_AVISYNTH_LOCALPORT, //uint32_t
+RESET_ENCODER_ON_VIDEO_LOAD, //bool
diff --git a/avidemux_core/ADM_coreUtils/src/prefs2.conf b/avidemux_core/ADM_coreUtils/src/prefs2.conf
index 7cd2dcc..bfd3cc9 100644
--- a/avidemux_core/ADM_coreUtils/src/prefs2.conf
+++ b/avidemux_core/ADM_coreUtils/src/prefs2.conf
@@ -90,5 +90,7 @@ uint32_t:avisynth_defaultport,         9999,      1024, 65535
uint32_t:avisynth_localport,         0,         1024, 65535
}
#
+bool:reset_encoder_on_video_load,       0,      0,      1
+#
}
#
diff --git a/avidemux_core/ADM_coreUtils/src/prefs2.h b/avidemux_core/ADM_coreUtils/src/prefs2.h
index 3fc6003..a6d484a 100644
--- a/avidemux_core/ADM_coreUtils/src/prefs2.h
+++ b/avidemux_core/ADM_coreUtils/src/prefs2.h
@@ -69,4 +69,5 @@ struct  {
uint32_t avisynth_defaultport;
uint32_t avisynth_localport;
}avisynth;
+bool reset_encoder_on_video_load;
}my_prefs_struct;
diff --git a/avidemux_core/ADM_coreUtils/src/prefs2_desc.cpp b/avidemux_core/ADM_coreUtils/src/prefs2_desc.cpp
index 29f9af8..c0b11ec 100644
--- a/avidemux_core/ADM_coreUtils/src/prefs2_desc.cpp
+++ b/avidemux_core/ADM_coreUtils/src/prefs2_desc.cpp
@@ -49,5 +49,6 @@ 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},
+ {"reset_encoder_on_video_load",offsetof(my_prefs_struct,reset_encoder_on_video_load),"bool",ADM_param_bool},
{NULL,0,NULL}
};
diff --git a/avidemux_core/ADM_coreUtils/src/prefs2_json.cpp b/avidemux_core/ADM_coreUtils/src/prefs2_json.cpp
index e9ca038..19a1ce2 100644
--- a/avidemux_core/ADM_coreUtils/src/prefs2_json.cpp
+++ b/avidemux_core/ADM_coreUtils/src/prefs2_json.cpp
@@ -72,6 +72,7 @@ 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.addBool("reset_encoder_on_video_load",key->reset_encoder_on_video_load);
return json.dumpToFile(file);
};
bool  my_prefs_struct_jdeserialize(const char *file, const ADM_paramList *tmpl,my_prefs_struct *key){
diff --git a/avidemux_core/ADM_coreUtils/src/prefs2_pref.h b/avidemux_core/ADM_coreUtils/src/prefs2_pref.h
index 01b542c..f785914 100644
--- a/avidemux_core/ADM_coreUtils/src/prefs2_pref.h
+++ b/avidemux_core/ADM_coreUtils/src/prefs2_pref.h
@@ -60,5 +60,6 @@ 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},
+{ RESET_ENCODER_ON_VIDEO_LOAD,"reset_encoder_on_video_load"           ,ADM_param_bool    ,"0", 0, 1},
};


I think it belongs to the "user interface" tab of the preferences because it is related to a frequently performed interaction between the user and the GUI. I am very unsure about the choice of names and the wording of the label though.

The patch has been tested and WFM.

mean

Committed, thanks
I've made a small hack on the marker thing when appending

It's not pretty, but the idea is that if the markers where untouched, they are extended to the whole video after loading
If they were modified, they are left untouched

(and yes, i'm hijacking a totally unrelated thread)

eumagga0x2a

Thank you very much for the witty solution with markers (and for taking the patch with the new preference, of course)! Now we reap benefit from the total duration mostly extending beyond the last frame of the video ââ,¬â€œ setting the marker B to the last frame would protect it from being shifted to the end after appending, but users who don't touch markers at all won't face a new, unexpected behaviour.

eumagga0x2a

Unfortunately, I overlooked that the detection if the marker A or B has been shifted
+    if(theEnd!=markerB && (markerA!=pts && !markerA))

is wrong both in the original patch and in the follow-up: the test will succeed only if the marker A is zero and not equal the pts of the first frame and the marker B is not at its default value. But the test should succeed if the marker A is not zero and not equal the pts of the first frame or the marker B is not at its default value.

diff --git a/avidemux/common/gui_main.cpp b/avidemux/common/gui_main.cpp
index 7fba59d..28f4c1c 100644
--- a/avidemux/common/gui_main.cpp
+++ b/avidemux/common/gui_main.cpp
@@ -834,7 +834,7 @@ int A_appendVideo (const char *name)
     ADM_info("Start is %s, marker A is %s\n",ADM_us2plain(pts),ADM_us2plain(markerA));
     ADM_info("End is %s, marker B is %s\n",ADM_us2plain(theEnd),ADM_us2plain(markerB));
     
-    if(theEnd!=markerB && (markerA!=pts && !markerA))
+    if(theEnd!=markerB || (markerA!=pts && markerA))
     {
         markerChanged=true;
     }


fixes the detection for me.

mean

indeed, flawed logic
I've changed it slightly differently for clarity sake

eumagga0x2a

Thanks!

(I should have at least swapped the test for a non-zero markerA and markerA not equal the PTS of the first frame in the suggested patch anyway.)