Gambas-it

Gambas3 => Programmazione => Topic aperto da: Gianluigi - 08 Agosto 2018, 16:12:06

Titolo: Con Shell funziono, con Exec no
Inserito da: Gianluigi - 08 Agosto 2018, 16:12:06
Io di questi comandi ne so poco ma Ujlain mi ha chiesto perché Exec dava errore di "File or directory does not exist"

Io gli ho consigliato di usare Shell che funziona però non capisco il perché shell si e exec no, ecco il codice

Codice: [Seleziona]
Public Sub Button1_Click()

  Dim fname1, fname2, cmd As String

  fName1 = "~/Desktop/a.pdf"
  fName2 = "~/Desktop/a.3gp"
  cmd = Subst$("cp &1  &2", fname1, fname2)
  'Exec [cmd] Wait ''<------------------------------------Questo non funziona
  Shell cmd Wait ''<--------------------------------------Questo funziona, perché?

End
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: vuott - 08 Agosto 2018, 18:11:08
Io gli ho consigliato di usare
...ma pperché non usa Copy( ) (http://gambaswiki.org/wiki/lang/copy?nh)  ?    :-\
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: Gianluigi - 08 Agosto 2018, 18:25:32
Io gli ho consigliato di usare
...ma pperché non usa Copy( ) (http://gambaswiki.org/wiki/lang/copy?nh)  ?    :-\

Credo che voglia convertire dei file mp4 in 3gp usando ffmpeg attraverso i comandi di terminale e si è trovato questo malfunzionamento di Exec su cp e mv e mi ha chiesto conferma.

 :ciao: :ciao:
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: vuott - 08 Agosto 2018, 18:34:00
... e exec no

La domanda è: cosa vuole Exec ?
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: Gianluigi - 08 Agosto 2018, 19:20:18
Non capisco cosa vuoi sapere, io questi comandi non li ho mai usati e penso che mai li userò.
Per quel poco che ne so Exec e Shell si equivalgono e quindi...
Se per copiare il comando (Exec) è scritto sbagliato, mi potresti dire come va scritto correttamente?
Ho provato anche passando il risultato a process...

 :ciao: :ciao:
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: vuott - 08 Agosto 2018, 23:13:19
Va be'.... facciamola breve  >:( :  Exec vuole che le parti costituenti di una riga di comando siano passate attraverso un vettore di tipo Stringa.
Più precisamente Exec pretende che ogni parte essenziale e significante della riga di comando sia contenuta in un singolo elemento del vettore passato.

Invece, la soluzione vista sopra:
Codice: [Seleziona]
Exec [cmd]
passa, sì, un array di stringhe alla funzione Exec, ma l'intera riga di comando è passata tutta insieme all'interno del 1° elemento dell'array.
...e ciò non va bene.
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: Gianluigi - 09 Agosto 2018, 16:01:53
Che peccato, quante parole sprecate  :'(
Bastava che qualcuno di buona memoria mi rimandasse a questa discussione (http://www.gambas-it.org/smf/index.php?topic=5840.msg41935#msg41935) che mi era sfuggita (se si fa una ricerca con exec si ottiene un mare di comandi SQL), o alla cosa più importante la pagina della wiki (http://gambaswiki.org/wiki/doc/shellexec).
Rimane il fatto che con il tipo di programmi a cui sono interessato ben difficilmente dovrò ricorrere alla shell & C.
La mia unica colpa è stata quella di voler aiutare un conoscente mentre ero in altre faccende affaccendato, ho ricevuto l'ennesima lezione sul farsi gli affari propri.
Un'intera giornata praticamente buttata.  :'(
 :P :P :P

 :ciao: :ciao:
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: vuott - 09 Agosto 2018, 19:10:47
Rimane il fatto che con il tipo di programmi a cui sono interessato ben difficilmente dovrò ricorrere alla shell
Io sono d'accordo con le grandi perplessità ceskhoniane sull'uso smodato di Exec e Shell.
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: ujlain - 10 Agosto 2018, 14:52:39
Exec finally worked for me. The mistake I was making was treating Exec like Shell  :nono:. Exec expects each parameter to be a separate string separated by a comma. Example

Exec ["ffmpeg", "-y", "-i", fInp, "-f", "3gp", "-vcodec", "h263", "-vf", "scale=352x288", "-acodec", "aac", "-strict", "-2", "-nostats", fOut] Wait
   
Above worked for me. fInp is the input video file name. fOut is the output file name. I will upload the sample working code on Gambas Farm soon.
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: ujlain - 10 Agosto 2018, 14:58:46
I need to thank Gianluigi for pointing out to me this link http://gambaswiki.org/wiki/doc/shellexec
A repeat reading of above helped. But that is the way GAMBAS is  :hatecomputer:.. little or no documentation and where available , it is cryptic and needs a fine concentrated reading !
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: Gianluigi - 10 Agosto 2018, 17:31:32
I need to thank Gianluigi for pointing out to me this link http://gambaswiki.org/wiki/doc/shellexec
A repeat reading of above helped. But that is the way GAMBAS is  :hatecomputer:.. little or no documentation and where available , it is cryptic and needs a fine concentrated reading !

 :D
It is true that we would need more documentation, but the current one is good enough, the problem is that it is not easy to find it.

 :ciao: :ciao:
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: vuott - 10 Agosto 2018, 21:50:16
  ???

.........

(https://ilterronistadotcom.files.wordpress.com/2015/01/mad-at-theinternet.gif)
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: Gianluigi - 10 Agosto 2018, 22:53:07
  ???

 ??? Non sei d'accordo che di documentazione non ce n'è mai abbastanza, ma quella che c'è e discreta solo che è molto sparsa e difficile da reperire?  :-\
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: vuott - 12 Agosto 2018, 02:59:50
Exec ["ffmpeg", "-y", "-i", fInp, "-f", "3gp", "-vcodec", "h263", "-vf", "scale=352x288", "-acodec", "aac", "-strict", "-2", "-nostats", fOut] Wait

Ad ogni modo mi pare che questa riga converta un file video di formato .3gp in un file audio di formato .aac mediante il programma ffmpeg.
Per chi non possegga nel proprio sistema questo programma, ...shell per shell, è possibile utilizzare le risorse di GStreamer, che possediamo avendole caricate preliminarmente con l'installazione di Gambas.

Codice: [Seleziona]
Public Sub Main()

  Shell "gst-launch-1.0 filesrc location=/percorso/del/file.3gp ! decodebin ! audioconvert ! voaacenc ! 'audio/mpeg,stream-format=adts' ! filesink location=/percorso/del/file.acc"

End
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: Gianluigi - 12 Agosto 2018, 12:45:38
Non sono sicuro perché non l'ho provato, ma lui mi ha detto di averci convertito, riducendone il peso del 30%, file mp4 in 3gp
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: vuott - 12 Agosto 2018, 19:33:45
...file mp4 in 3gp

Per ora, senza "Shell ", sono riuscito solo a ottenere da un file video MP4 un file 3GP solo video:  ;D
Codice: [Seleziona]
Library "libgstreamer-1.0"

Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING
Private Const GST_FORMAT_TIME As Integer = 3

' gst_init (int *argc, char **argv[])
' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.
Private Extern gst_init(argc As Pointer, argv As Pointer)

' GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error)
' Create a new pipeline based on command line syntax.
Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer

' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state)
' Sets the state of the element.
Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer

' gboolean gst_element_query_duration(GstElement *element, GstFormat format, gint64 *duration)
' Queries an element for the total stream duration in nanoseconds.
Private Extern gst_element_query_duration(gselement As Pointer, formatI As Integer, duration As Pointer) As Boolean
 
' gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur)
' Queries an element for the stream position in nanoseconds.
Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean

' void gst_object_unref(gpointer object)
' Decrements the reference count on object.
Private Extern gst_object_unref(gobject As Pointer)


Public Sub Main()
 
 Dim video As Pointer
 Dim pos, dur As Long
 Dim po, du As Date
     
  gst_init(0, 0)
 
' Il percorso ed il nome del file origine .mp4 e quelli del file convertito .3gp  NON devono contenere spazi !
  video = gst_parse_launch("filesrc location=/percorso/del/file.mp4 ! qtdemux ! 3gppmux ! filesink location = /tmp/solovideo.3gp", 0)
       
' Avviamo la conversione video:
  gst_element_set_state(video, GST_STATE_PLAYING)
 
  Sleep 1
 
  Do
    gst_element_query_position(video, GST_FORMAT_TIME, VarPtr(pos))
    gst_element_query_duration(video, GST_FORMAT_TIME, VarPtr(dur))
    po = Date(0, 0, 0, 0, 0, 0, pos / 1000000)
    du = Date(0, 0, 0, 0, 0, 0, dur / 1000000)
    Write "\rTempo: " & po
  Loop Until Str(po) >= Str(du)
 
     
  Print "\nConversione terminata."
  gst_object_unref(video)
     
End


e un file 3GP solo audio:  ;D
Codice: [Seleziona]
Library "libgstreamer-1.0"

Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING
Private Const GST_FORMAT_TIME As Integer = 3

' gst_init (int *argc, char **argv[])
' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.
Private Extern gst_init(argc As Pointer, argv As Pointer)

' GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error)
' Create a new pipeline based on command line syntax.
Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer

' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state)
' Sets the state of the element.
Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer

' gboolean gst_element_query_duration(GstElement *element, GstFormat format, gint64 *duration)
' Queries an element for the total stream duration in nanoseconds.
Private Extern gst_element_query_duration(gselement As Pointer, formatI As Integer, duration As Pointer) As Boolean
 
' gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur)
' Queries an element for the stream position in nanoseconds.
Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean

' void gst_object_unref(gpointer object)
' Decrements the reference count on object.
Private Extern gst_object_unref(gobject As Pointer)


Public Sub Main()
 
 Dim audio As Pointer
 Dim pos, dur As Long
 Dim po, du As Date
     
  gst_init(0, 0)
 
' Il percorso ed il nome del file origine .mp4 e quelli del file convertito .3gp  NON devono contenere spazi !
  audio = gst_parse_launch("filesrc location=/percorso/del/file.mp4 ! qtdemux ! queue ! 3gppmux ! filesink location = /tmp/soloaudio.3gp", 0)
       
' Avviamo la conversione audio:
  gst_element_set_state(audio, GST_STATE_PLAYING)
 
  Sleep 1
 
  Do
    gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(pos))
    gst_element_query_duration(audio, GST_FORMAT_TIME, VarPtr(dur))
    po = Date(0, 0, 0, 0, 0, 0, pos / 1000000)
    du = Date(0, 0, 0, 0, 0, 0, dur / 1000000)
    Write "\rTempo: " & po
  Loop Until Str(po) >= Str(du)
 
     
  Print "\nConversione terminata."
  gst_object_unref(audio)
     
End
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: Gianluigi - 12 Agosto 2018, 20:07:55
Per ora, senza "Shell ", sono riuscito ...

 :ok:
E senza librerie esterne?  ;D
Titolo: Re:Con Shell funziono, con Exec no
Inserito da: vuott - 12 Agosto 2018, 21:12:36
E senza librerie esterne?  ;D

...'na botta 'n cap' !

 :violent:
Titolo: Re:Con Shell funziona, con Exec no
Inserito da: vuott - 15 Agosto 2018, 17:59:28
Sempre ancora con le funzioni esterne  >:( della risorsa GStreamer ho ottenuto finalmente un file video/audio .3gp da un file .mp4, ma... non vedo riduzione della dimensione del file finale.

Codice: [Seleziona]
Library "libgstreamer-1.0"

Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING
Private Const GST_FORMAT_TIME As Integer = 3

' gst_init (int *argc, char **argv[])
' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.
Private Extern gst_init(argc As Pointer, argv As Pointer)

' GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error)
' Create a new pipeline based on command line syntax.
Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer

' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state)
' Sets the state of the element.
Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer

' gboolean gst_element_query_duration(GstElement *element, GstFormat format, gint64 *duration)
' Queries an element for the total stream duration in nanoseconds.
Private Extern gst_element_query_duration(gselement As Pointer, formatI As Integer, duration As Pointer) As Boolean
 
' gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur)
' Queries an element for the stream position in nanoseconds.
Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean

' void gst_object_unref(gpointer object)
' Decrements the reference count on object.
Private Extern gst_object_unref(gobject As Pointer)


Public Sub Main()
 
 Dim video As Pointer
 Dim pos, dur As Long
 Dim po, du As Date
     
  gst_init(0, 0)
 
' Il percorso ed il nome del file origine .mp4 e quelli del file convertito .3gp  NON devono contenere spazi ! '
  video = gst_parse_launch("filesrc location=/percorso/file/video.mp4 ! qtdemux name=d ! queue ! h264parse ! 3gppmux name=mux ! filesink location=/tmp/prova.3gp d. ! queue ! aacparse ! mux.", 0)
       
' Avviamo la conversione video:
  gst_element_set_state(video, GST_STATE_PLAYING)
 
  Repeat
    gst_element_query_duration(video, GST_FORMAT_TIME, VarPtr(dur))
  Until dur > 0
 
  Repeat
    gst_element_query_position(video, GST_FORMAT_TIME, VarPtr(pos))
    gst_element_query_duration(video, GST_FORMAT_TIME, VarPtr(dur))
    po = Date(0, 0, 0, 0, 0, 0, pos / 1000000)
    du = Date(0, 0, 0, 0, 0, 0, dur / 1000000)
    Write "\rTempo: " & po
  Until Str(po) >= Str(du)
     
  Print "\nConversione terminata."
  gst_object_unref(video)
     
End