IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

stdout en temps réel et subprocess


Sujet :

Python

  1. #1
    Membre averti
    Homme Profil pro
    infographiste3d
    Inscrit en
    Octobre 2011
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Jura (Franche Comté)

    Informations professionnelles :
    Activité : infographiste3d
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Octobre 2011
    Messages : 19
    Par défaut stdout en temps réel et subprocess
    Bonjour,
    Je suis en train de programmer un GUI pour le soft ffmpeg
    Je cherche a capturer en temps réelle la sortie que donne l exécution de la ligne de commande pour pouvoir mettre à jour une bar de progression.
    voici mon problème:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
    import subprocess,sys
     
    command = "K:\\_RD\\_LVR_RD\\Batch\\encodage\\ffmpeg\\bin\\ffmpeg.exe -y -i L:\\test.avi -vcodec libx264 -vpre libx264-Medium -crf 10.2 -r 25 -acodec copy L:\\test_AVC_H264.avi"
     
    process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
     
    lineNumber=0    
    while True:
        buff = process.stdout.readline()
        lineNumber=lineNumber+1
        print "lineNumber:  ",lineNumber
        if buff == '' and process.poll() != None: 
            break
        sys.stdout.write(buff)
     
    process.wait()
    Avec ce code la console imprime successivement et en temp reelle les premières lignes. Mais au moment de l encodage, les lignes ne s'impriment plus.
    Ce n'est que lorsque l'encodage est terminer que le bloque avec toutes le info de progression s imprime.
    Il m'est du coup impossible d'utiliser ces infos pour ma bar de progression.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
     
    Buff--------------->ffmpeg version N-36193-gf514695, Copyright(c)2000-2011 the FFmpeg developers
    Buff--------------->  built on Dec 26 2011 17:50:37 with gcc 4.6.2
    Buff--------------->  configuration: --enable-gpl --enable-version3 --disable-w3 2threads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib --enable-fr ei0r --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable libopenjpeg --enable-librtmp --enab le-libschroedinger --enable-libspeex --enable-libtheora --enable-libvo-aacenc -- enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enab le-libxavs --enable-libxvid --enable-zlib
    Buff--------------->  libavutil      51. 33.100 / 51. 33.100
    Buff--------------->  libavcodec     53. 48.100 / 53. 48.100
    Buff--------------->  libavformat    53. 28.100 / 53. 28.100
    Buff--------------->  libavdevice    53.  4.100 / 53.  4.100
    Buff--------------->  libavfilter     2. 54.100 /  2. 54.100
    Buff--------------->  libswscale      2.  1.100 /  2.  1.100
    Buff--------------->  libswresample   0.  5.100 /  0.  5.100
    Buff--------------->  libpostproc    51.  2.100 / 51.  2.100
    Buff--------------->Input #0, avi, from 'L:\test.avi':
    Buff--------------->  Metadata:
    Buff--------------->    TCOD            : 71600000
    Buff--------------->    TCDO            : 165600000
    Buff--------------->  Duration: 00:00:09.40, start: 0.000000, bitrate: 1660532 k b/s Buff--------------->    Stream #0:0: Video: rawvideo, bgra, 1920x1080, 25 tbr, 2 5 tbn, 25 tbc Buff--------------->    Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 4 4100 Hz, 2 channels, s16, 1411 kb/s 
    Buff--------------->Incompatible pixel format 'bgra' for codec 'libx264', auto-s electing format 'yuv420p'
    Buff--------------->[buffer @ 038101C0] w:1920 h:1080 pixfmt:bgra tb:1/1000000 s ar:0/1 sws_param:
    Buff--------------->[buffersink @ 03817D40] auto-inserting filter 'auto inserted  scale 0' between the filter 'src' and the filter 'out'
    Buff--------------->[scale @ 03815400] w:1920 h:1080 fmt:bgra -> w:1920 h:1080 f mt:yuv420p flags:0x4
    Buff--------------->[libx264 @ 03823BC0] using cpu capabilities: MMX2 SSE2Fast FastShuffle SSEMisalign LZCNT
    Buff--------------->[libx264 @ 03823BC0] profile High, level 4.0
    Buff--------------->Output #0, avi, to 'L:\test_AVC_H264.avi':
    Buff--------------->  Metadata:
    Buff--------------->    TCOD            : 71600000
    Buff--------------->    TCDO            : 165600000
    Buff--------------->    ISFT            : Lavf53.28.100
    Buff--------------->    Stream #0:0: Video: h264 (H264 / 0x34363248), yuv420p, 1 920x1080, q=-1--1, 25 tbn, 25 tbc
    Buff--------------->    Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 2 channels, 1411 kb/s
    Buff--------------->Stream mapping:
    Buff--------------->  Stream #0:0 -> #0:0 (rawvideo -> libx264)
    Buff--------------->  Stream #0:1 -> #0:1 (copy)
    Buff--------------->Press [q] to stop, [?] for help
    Buff--------------->frame=    3 fps=  0 q=0.0 size=      10kBtime=00:00:00.00 b
    frame=    7 fps=  7 q=0.0 size=      10kB time=00:00:00.00 bitrate=  0.0kbits/sframe=   13 fps=  8 q=0.0 size=      10kB time=00:00:00.00bitrate=   0.0kbits/s
    frame=   19 fps=  9 q=0.0 size=      10kB time=00:00:00.00 bitrate=   0.0kbits/s
    frame=   26 fps= 10 q=0.0 size=      10kB time=00:00:00.00 bitrate=   0.0kbits/sframe=   32 fps= 10 q=0.0 size=      10kB time=00:00:00.00 bitrate=   0.0kbits/s
    frame=   38 fps= 10 q=0.0 size=      10kB time=00:00:00.00 bitrate=   0.0kbits/sframe=   44 fps= 10 q=0.0 size=   10kB time=00:00:00.00 bitrate=   0.0kbits/sframe=   46 fps=  9 q=0.0 size=      10kB time=00:00:00.00 bitrate=   0.0kbits/s
    frame=   52 fps=  9 q=0.0 size=      10kB time=00:00:00.00 bitrate=   0.0kbits/s
    frame=   58 fps= 10 q=0.0 size=      10kB time=00:00:00.00 bitrate=   0.0kbits/s
    frame=   63 fps= 10 q=16.0 size=     694kB time=00:00:00.-4 bitrate=-142094.8kbi
    frame=   66 fps=  9 q=16.0 size=    2627kB time=00:00:00.08 bitrate=268956.2kbit
    frame=   71 fps=  9 q=16.0 size=    5886kB time=00:00:00.28 bitrate=172198.5kbit
    frame=   75 fps=  9 q=16.0 size=    8459kB time=00:00:00.44 bitrate=157482.3kbit
    frame=   80 fps=  9 q=16.0 size=   11686kB time=00:00:00.64 bitrate=149580.8kbit
    frame=   85 fps=  9 q=16.0 size=   14916kB time=00:00:00.84 bitrate=145461.8kbit
    frame=   89 fps=  9 q=16.0 size=   17479kB time=00:00:01.00 bitrate=143184.7kbit
    frame=   94 fps=  9 q=16.0 size=   20664kB time=00:00:01.20 bitrate=141065.2kbit
    frame=   99 fps=  9 q=16.0 size=   23816kB time=00:00:01.40 bitrate=139355.6kbit
    frame=  102 fps=  9 q=16.0 size=   25713kB time=00:00:01.52 bitrate=138581.4kbit
    frame=  107 fps=  9 q=16.0 size=   28857kB time=00:00:01.72 bitrate=137438.7kbit
    frame=  111 fps=  8 q=16.0 size=   31387kB time=00:00:01.88 bitrate=136765.9kbit
    frame=  115 fps=  8 q=16.0 size=   33912kB time=00:00:02.04 bitrate=136181.1kbit
    frame=  120 fps=  8 q=16.0 size=   37078kB time=00:00:02.24 bitrate=135598.2kbit
    frame=  122 fps=  8 q=13.0 size=   38327kB time=00:00:02.32 bitrate=135333.3kbit
    frame=  127 fps=  8 q=16.0 size=   41480kB time=00:00:02.52 bitrate=134844.5kbit
    frame=  132 fps=  8 q=16.0 size=   44605kB time=00:00:02.72 bitrate=134338.9kbit
    frame=  137 fps=  8 q=16.0 size=   47670kB time=00:00:02.92 bitrate=133735.9kbit
    frame=  143 fps=  8 q=16.0 size=   49062kB time=00:00:03.16 bitrate=127189.3kbit
    frame=  147 fps=  8 q=16.0 size=   49660kB time=00:00:03.32 bitrate=122535.5kbit
    frame=  150 fps=  8 q=16.0 size=   50113kB time=00:00:03.44 bitrate=119337.9kbit
    frame=  153 fps=  8 q=16.0 size=   50554kB time=00:00:03.56 bitrate=116329.9kbit
    frame=  158 fps=  8 q=16.0 size=   51305kB time=00:00:03.76 bitrate=111779.9kbit
    frame=  164 fps=  8 q=16.0 size=   52194kB time=00:00:04.00 bitrate=106893.2kbit
    frame=  171 fps=  8 q=16.0 size=   53217kB time=00:00:04.28 bitrate=101859.3kbit
    frame=  178 fps=  8 q=16.0 size=   54253kB time=00:00:04.56 bitrate=97465.3kbits
    frame=  184 fps=  8 q=16.0 size=   55146kB time=00:00:04.80 bitrate=94115.1kbits
    frame=  191 fps=  8 q=16.0 size=   56196kB time=00:00:05.08 bitrate=90621.9kbits
    frame=  197 fps=  9 q=16.0 size=   57070kB time=00:00:05.32 bitrate=87878.7kbits
    frame=  201 fps=  9 q=16.0 size=   60562kB time=00:00:05.48 bitrate=90534.2kbits
    frame=  205 fps=  8 q=16.0 size=   63805kB time=00:00:05.64 bitrate=92675.0kbits
    frame=  208 fps=  8 q=16.0 size=   66233kB time=00:00:05.76 bitrate=94198.4kbits
    frame=  212 fps=  8 q=16.0 size=   69450kB time=00:00:05.92 bitrate=96103.6kbits
    frame=  216 fps=  8 q=16.0 size=   72664kB time=00:00:06.08 bitrate=97904.7kbits
    frame=  220 fps=  8 q=16.0 size=   75857kB time=00:00:06.24 bitrate=99586.6kbits
    frame=  224 fps=  8 q=16.0 size=   79033kB time=00:00:06.40 bitrate=101162.0kbit
    frame=  229 fps=  8 q=16.0 size=   82996kB time=00:00:06.60 bitrate=103015.8kbit
    frame=  232 fps=  8 q=16.0 size=   85355kB time=00:00:06.72 bitrate=104051.5kbit
    frame=  235 fps=  6 q=-1.0 Lsize=  134980kB time=00:00:09.32 bitrate=118643.0kbi
    ts/s
    Buff--------------->video:133334kB audio:1619kB global headers:0kB muxing overhe
    ad 0.019495%
    Buff--------------->[libx264 @ 03823BC0] frame I:3     Avg QP:10.54  size:660722
     
    Buff--------------->[libx264 @ 03823BC0] frame P:232   Avg QP:12.64  size:579965
     
    Buff--------------->[libx264 @ 03823BC0] mb I  I16..4: 16.5% 59.2% 24.2%
    Buff--------------->[libx264 @ 03823BC0] mb P  I16..4: 12.1% 48.3% 12.7%  P16..4
    :  7.7% 10.8%  6.7%  0.0%  0.0%    skip: 1.7%
    Buff--------------->[libx264 @ 03823BC0] 8x8 transform intra:66.0% inter:40.5%
    Buff--------------->[libx264 @ 03823BC0] coded y,uvDC,uvAC intra: 96.5% 94.9% 93
    .5% inter: 80.2% 82.4% 73.7%
    Buff--------------->[libx264 @ 03823BC0] i16 v,h,dc,p:  6%  3% 47% 44%
    Buff--------------->[libx264 @ 03823BC0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 12%
    34%  5%  6%  6%  6%  5%  6%
    Buff--------------->[libx264 @ 03823BC0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 17% 11%
    21%  8%  9%  9%  9%  7%  8%
    Buff--------------->[libx264 @ 03823BC0] i8c dc,h,v,p: 72%  7% 10% 11%
    Buff--------------->[libx264 @ 03823BC0] Weighted P-Frames: Y:0.0% UV:0.0%
    Buff--------------->[libx264 @ 03823BC0] ref P L0: 41.1% 10.4% 30.3% 18.3%
    Buff--------------->[libx264 @ 03823BC0] kb/s:116199.16

  2. #2
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 695
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 695
    Par défaut
    Salut,

    Le script Python faisant en fonction des informations récupérées sur stdout, cela (me) laisse supposer que ffmpeg les envoie peut être sur stderr.

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  3. #3
    Membre averti
    Homme Profil pro
    infographiste3d
    Inscrit en
    Octobre 2011
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Jura (Franche Comté)

    Informations professionnelles :
    Activité : infographiste3d
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Octobre 2011
    Messages : 19
    Par défaut
    J ai essayé ça:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
    import subprocess,sys
     
    command = "K:\\_RD\\_LVR_RD\\Batch\\encodage\\ffmpeg\\bin\\ffmpeg.exe -y -i L:\\test.avi -vcodec libx264 -vpre libx264-Medium -crf 10.2 -r 25 -acodec copy L:\\test_AVC_H264.avi"
     
    process = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     
    #lineNumber=0    
    while True:
        buff = process.stdout.readline()
        bufferr = process.stderr.readline()
        if bufferr == '' and process.poll() != None: 
            break
        sys.stdout.write("Buff--------------->"+buff)
        sys.stdout.write("Bufferr--------------->"+bufferr)
     
    process.wait()
    il me retourne cette erreur:
    File "C:\Users\Lucasky\Desktop\testwexpect2.py", line 10, in <module>
    bufferr = process.stderr.read()
    AttributeError: 'NoneType' object has no attribute 'read'

    Il ne sortirai donc rien en stderr???

  4. #4
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 695
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 695
    Par défaut
    Salut,
    La documentation dit:
    Popen.stderr¶
    If the stderr argument was PIPE, this attribute is a file object that provides error output from the child process. Otherwise, it is None.
    Ce qui est cohérent avec:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    bufferr = process.stderr.read()
    AttributeError: 'NoneType' object has no attribute 'read'
    De là à conclure qu'il n'y a rien qui sort sur stderr...
    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  5. #5
    Membre averti
    Homme Profil pro
    infographiste3d
    Inscrit en
    Octobre 2011
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Jura (Franche Comté)

    Informations professionnelles :
    Activité : infographiste3d
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Octobre 2011
    Messages : 19
    Par défaut
    merci pour ta réponse,
    j ai essayé ceci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
    import subprocess,sys
     
    command = "K:\\_RD\\_LVR_RD\\Batch\\encodage\\ffmpeg\\bin\\ffmpeg.exe -y -i L:\\test.avi -vcodec libx264 -vpre libx264-Medium -crf 10.2 -r 25 -acodec copy L:\\test_AVC_H264.avi"
     
    process = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     
    #lineNumber=0    
    while True:
        buff = process.stdout.readline()
        try:
                bufferr = process.stderr.readline()
        except:
                bufferr = "no stderr"
        if buff == '' and process.poll() != None: 
            break
        sys.stdout.write("Buff--------------->"+buff+"\n")
        sys.stdout.write("Bufferr------------>"+bufferr+"\n")
     
    process.wait()
    dsl je debute...
    Est ce que tu pensais plus a un code comme ceci pour récupérer le stderr ?
    Quant j exécute ce denier la sorti stderr reste en None tout le long de l’exécution de la commande.
    lucas

  6. #6
    Expert confirmé
    Avatar de fred1599
    Homme Profil pro
    Lead Dev Python
    Inscrit en
    Juillet 2006
    Messages
    4 049
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Lead Dev Python
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2006
    Messages : 4 049
    Par défaut
    Si je peux me permettre il existe un wrapper pour ffmpeg --> pyffmpeg

  7. #7
    Membre averti
    Homme Profil pro
    infographiste3d
    Inscrit en
    Octobre 2011
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Jura (Franche Comté)

    Informations professionnelles :
    Activité : infographiste3d
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Octobre 2011
    Messages : 19
    Par défaut
    merci fred
    Je connaissais pas
    Je vais regarder leurs code et voir comment ils procèdent
    merci

  8. #8
    Membre averti
    Homme Profil pro
    infographiste3d
    Inscrit en
    Octobre 2011
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Jura (Franche Comté)

    Informations professionnelles :
    Activité : infographiste3d
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Octobre 2011
    Messages : 19
    Par défaut
    Malheureusement les sources pyffmpeg ne sont pas dispo.
    Impossible de voir comment ils ont procédé.

    J'ai trouvé cette discution:
    http://stackoverflow.com/questions/3...ess-in-windows

    C'est exactement mon souci.
    Les réponses ont l'air d avoir résolu le problème mais pour moi ça ne marche pas.
    si qq un a une idée...
    Lucas

Discussions similaires

  1. Écrire stdout dans un QTextEdit en "temps réel"
    Par ElFenec dans le forum PyQt
    Réponses: 7
    Dernier message: 15/07/2009, 10h22
  2. [MFC] graphique temps réel
    Par _Thomas_ dans le forum MFC
    Réponses: 10
    Dernier message: 01/06/2004, 11h56
  3. Voir requête éxécuté en temps réel ?
    Par [DreaMs] dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 08/01/2004, 14h52
  4. cubes temps réel en ROLAP
    Par Guizz dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 09/07/2003, 16h36
  5. Durée d'un traitement temps réel
    Par Almex dans le forum C
    Réponses: 5
    Dernier message: 29/03/2003, 14h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo