[vlc-devel] Hot keys to log timestamp parts of video

John Hammer dev54335 at gmail.com
Sun Mar 13 01:16:41 UTC 2022


I could get the path with the api **input_item_GetURI**. Thanks Steve for
all the help. Below is the patch that logs timestamps to the file. Pressing
key "1" logs start timestamp and key "2" logs end timestamp. Hope this
helps someone.

diff --git a/modules/gui/qt/main_interface.cpp
b/modules/gui/qt/main_interface.cpp
index a57506533d..af7dea37ec 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -309,6 +309,7 @@ MainInterface::~MainInterface()
     var_DelCallback( p_intf->obj.libvlc, "intf-popupmenu", PopupMenuCB,
p_intf );

     p_intf->p_sys->p_mi = NULL;
+    qDebug() << "destructor";
 }

 void MainInterface::computeMinimumSize()
@@ -1612,18 +1613,55 @@ void MainInterface::dragLeaveEvent(QDragLeaveEvent
*event)
  ************************************************************************/
 void MainInterface::keyPressEvent( QKeyEvent *e )
 {
-    handleKeyPress( e );
+  // vlc/modules/gui/qt/input_manager.cpp function
InputManager::UpdatePosition()
+  MainInputManager* mim = MainInputManager::getInstance( p_intf );
+  input_thread_t *p_input = mim->getInput();
+  if (p_input) {
+    if (!timeStampFile.isOpen()) {
+      // get file name
+      input_item_t *p_item = input_GetItem( p_input );
+      QFileInfo fileInfo(QUrl(input_item_GetURI(p_item)).toLocalFile());
+      QString filePath(fileInfo.absolutePath() + "/timestamp_" +
fileInfo.baseName() + ".txt");
+      qDebug() << "filePath: " << filePath;
+      timeStampFile.setFileName(filePath);//"/tmp/vlc_timestamp.txt");
+      if (!timeStampFile.open(QIODevice::Append | QIODevice::WriteOnly |
QIODevice::Text)) {
+ qDebug() << "unable to open file";
+      }
+    }

-    /* easter eggs sequence handling */
-    if ( e->key() == kc[ i_kc_offset ] )
-        i_kc_offset++;
-    else
-        i_kc_offset = 0;
+    //
+
+    QTextStream out(&timeStampFile);
+    QTime elapsed = QTime::fromMSecsSinceStartOfDay(var_GetInteger(p_input
, "time") / 1000);
+    QString t = elapsed.toString("hh:mm:ss");
+    switch (e->key()) {
+    case Qt::Key_End:
+    case Qt::Key_1:
+      qDebug() << "start" << t ;
+      out << "start " << t << "\n";
+      return;
+      break;
+    case Qt::Key_PageDown:
+    case Qt::Key_2:
+      qDebug() << "end" << t;
+      out << "end   " << t << "\n";
+      return;
+      break;
+    }
+  }
+
+  handleKeyPress( e );
+
+  /* easter eggs sequence handling */
+  if ( e->key() == kc[ i_kc_offset ] )
+    i_kc_offset++;
+  else
+    i_kc_offset = 0;

-    if ( i_kc_offset == (sizeof( kc ) / sizeof( Qt::Key )) )
+  if ( i_kc_offset == (sizeof( kc ) / sizeof( Qt::Key )) )
     {
-        i_kc_offset = 0;
-        emit kc_pressed();
+      i_kc_offset = 0;
+      emit kc_pressed();
     }
 }

diff --git a/modules/gui/qt/main_interface.hpp
b/modules/gui/qt/main_interface.hpp
index 5f60d2f307..8f62ff8cae 100644
--- a/modules/gui/qt/main_interface.hpp
+++ b/modules/gui/qt/main_interface.hpp
@@ -98,6 +98,9 @@ public:
     bool isInterfaceAlwaysOnTop() { return b_interfaceOnTop; }
     StandardPLPanel* getPlaylistView();

+private:
+  QFile timeStampFile;
+
 protected:
     void dropEventPlay( QDropEvent* event, bool b_play ) {
dropEventPlay(event, b_play, true); }
     void dropEventPlay( QDropEvent *, bool, bool );
diff --git a/modules/gui/qt/qt.hpp b/modules/gui/qt/qt.hpp
index e59583ab71..dde0254ef0 100644
--- a/modules/gui/qt/qt.hpp
+++ b/modules/gui/qt/qt.hpp
@@ -34,7 +34,7 @@
 #include <vlc_playlist.h>  /* playlist_t */

 #include <qconfig.h>
-
+#include <QDebug>
 #ifdef QT_STATIC
 #define QT_STATICPLUGIN
 #endif

Thanks,
John



On Wed, Mar 9, 2022 at 12:20 PM Steve Lhomme <robux4 at ycbcr.xyz> wrote:

>
>
> On 2022-03-08 21:12, John Hammer wrote:
> >  > It ends up doing
> >  > emit positionUpdated( f_pos, i_time, i_length / CLOCK_FREQ );
> >
> > Thank you Steve for pointing this out. Looking at the function that
> > emits this I found the following line that returns the current time
> > position.
> >
> > **var_GetInteger(p_input , "time");** // This line retrieves the time at
> > current position in microseconds
> >
> >   I called this in the **MainInterface::keyPressEvent(...)** callback to
> > retrieve the current time which works !!!
> >
> > Now I want to log this to a file at the same location as the current
> > playing file. How to retrieve the file path and file name of the current
> > playing file?
>
> When a new file/stream is loaded there's a ItemChanged emited with an
> input_item_t. With that item you can get plenty of information like
> calling input_item_GetNowPlayingFb().
>
> > Thanks,
> > John
> >
> >
> >
> > On Tue, Mar 8, 2022 at 2:13 PM Steve Lhomme <robux4 at ycbcr.xyz
> > <mailto:robux4 at ycbcr.xyz>> wrote:
> >
> >     On 2022-03-07 21:19, John Hammer wrote:
> >      >  > You mean visually?
> >      >
> >      > Yes. Basically while watching the video pressing the key manually
> >     should
> >      > log timestamps to a file. There will be 2 keys one for start
> >     timestamp
> >      > and one for end timestamp. The goal is to log the timestamps of
> >      > interesting parts of the video for external processing.
> >      >
> >      >  > There are time events reported by the core that you can hook
> >     into to
> >      > know where you are.
> >      >
> >      > I could modify the Qt GUI module and could listen to the key
> >     presses.
> >      > The following is the patch that works. Where is the time event
> hook?
> >      > Does this mean I have to store the keypress event for later
> >     processing
> >      > in the time hook event?
> >
> >     In libvlc there are 2 events: libvlc_MediaPlayerPositionChanged and
> >     libvlc_MediaPlayerTimeChanged. But if you use VLC directly it's not
> >     much
> >     use. They correspond to INPUT_EVENT_POSITION in Qt (on 3.0).
> >
> >     It ends up doing
> >     emit positionUpdated( f_pos, i_time, i_length / CLOCK_FREQ );
> >
> >
> >
> >      > diff --git a/modules/gui/qt/main_interface.cpp
> >      > b/modules/gui/qt/main_interface.cpp
> >      > index a57506533d..cd1ebad916 100644
> >      > --- a/modules/gui/qt/main_interface.cpp
> >      > +++ b/modules/gui/qt/main_interface.cpp
> >      > @@ -28,7 +28,7 @@
> >      >   #endif
> >      >
> >      >   #include "qt.hpp"
> >      > -
> >      > +#include <QDebug>
> >      >   #include "main_interface.hpp"
> >      >   #include "input_manager.hpp"                    // Creation
> >      >   #include "actions_manager.hpp"                  // killInstance
> >      > @@ -72,6 +72,7 @@
> >      >
> >      >   #include <QTimer>
> >      >
> >      > +
> >      >   #include <vlc_actions.h>                    /* Wheel event */
> >      >   #include <vlc_vout_display.h>               /* vout_thread_t
> >     and VOUT_
> >      > events */
> >      >
> >      > @@ -1612,6 +1613,17 @@ void
> >      > MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
> >      >
> >
>  ************************************************************************/
> >      >   void MainInterface::keyPressEvent( QKeyEvent *e )
> >      >   {
> >      > +    switch (e->key()) {
> >      > +    case Qt::Key_End:
> >      > +    case Qt::Key_1:
> >      > +      qDebug()<<e<<" start timestamp \n";
> >      > +      break;
> >      > +    case Qt::Key_PageDown:
> >      > +    case Qt::Key_2:
> >      > +      qDebug()<<e<<" end timestamp \n";
> >      > +      break;
> >      > +    }
> >      > +
> >      >       handleKeyPress( e );
> >      >
> >      > Thanks,
> >      > John
> >      >
> >      > On Mon, Mar 7, 2022 at 2:02 PM Steve Lhomme <robux4 at ycbcr.xyz
> >     <mailto:robux4 at ycbcr.xyz>
> >      > <mailto:robux4 at ycbcr.xyz <mailto:robux4 at ycbcr.xyz>>> wrote:
> >      >
> >      >
> >      >
> >      >     On 2022-03-05 19:01, John Hammer wrote:
> >      >      > Hi,
> >      >      >     I want to retrieve the start and end timestamp of
> parts of
> >      >     the video
> >      >      > for post-processing with an external program. Since Lua
> >     extension
> >      >     does
> >      >
> >      >     You mean visually ? There are time events reported by the
> >     core that you
> >      >     can hook into to know where you are.
> >      >
> >      >      > not support keybindings, I have decided to modify the
> >     source code. I
> >      >      > could compile the 3.x branch and debug the qt module
> >     interface.
> >      >     It looks
> >      >      > like this in the keypress event callbacks of this module
> >     is where
> >      >     the
> >      >      > code to log the timestamps should go.
> >      >      >
> >      >      >      Am I on the right track on implementing this feature
> >     or is
> >      >     there
> >      >      > any other way?
> >      >      >
> >      >      >     I also would like to color the areas on the time
> >     slider where
> >      >     the
> >      >      > start and end timestamps occurred. I have no idea how to
> >     achieve
> >      >     this.
> >      >      > Any suggestions on which module to be changed to achieve
> this?
> >      >
> >      >     If you want to change the UI you have to modify the Qt gui
> >     module/
> >      >
> >      >      > --
> >      >      > Thanks,
> >      >      > John
> >      >      >
> >      >      > _______________________________________________
> >      >      > vlc-devel mailing list
> >      >      > To unsubscribe or modify your subscription options:
> >      >      > https://mailman.videolan.org/listinfo/vlc-devel
> >     <https://mailman.videolan.org/listinfo/vlc-devel>
> >      >     <https://mailman.videolan.org/listinfo/vlc-devel
> >     <https://mailman.videolan.org/listinfo/vlc-devel>>
> >      >     _______________________________________________
> >      >     vlc-devel mailing list
> >      >     To unsubscribe or modify your subscription options:
> >      > https://mailman.videolan.org/listinfo/vlc-devel
> >     <https://mailman.videolan.org/listinfo/vlc-devel>
> >      >     <https://mailman.videolan.org/listinfo/vlc-devel
> >     <https://mailman.videolan.org/listinfo/vlc-devel>>
> >      >
> >      >
> >      >
> >      > --
> >      > Regards
> >      >
> >      > _______________________________________________
> >      > vlc-devel mailing list
> >      > To unsubscribe or modify your subscription options:
> >      > https://mailman.videolan.org/listinfo/vlc-devel
> >     <https://mailman.videolan.org/listinfo/vlc-devel>
> >     _______________________________________________
> >     vlc-devel mailing list
> >     To unsubscribe or modify your subscription options:
> >     https://mailman.videolan.org/listinfo/vlc-devel
> >     <https://mailman.videolan.org/listinfo/vlc-devel>
> >
> >
> >
> > --
> > Regards
> >
> > _______________________________________________
> > vlc-devel mailing list
> > To unsubscribe or modify your subscription options:
> > https://mailman.videolan.org/listinfo/vlc-devel
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel



-- 
Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20220313/d6fe7f69/attachment.html>


More information about the vlc-devel mailing list