Mencoder und popen2

Hallo, Ich versuche gerade ein Python Script zu erstellen, welches mir Filme von DVD in das, für mein Handy verständliche, 3gp Format umwandelt. Dazu wollte ich MEncoder (MPlayer Projekt) verwenden um die Video Daten in ein angemessenes Format zu bringen, dann mit MPlayer selbst die Audio Daten umwandeln und mit FFMpeg alles wieder zusammenfügen und encoden. Die Ausführung von MEncoder funktioniert auch, allerdings wird die temporäre Datei nur 639,6kB groß und das Script scheint sich aufzuhängen oder in eine Endlos Schleife zu laufen und dabei den MEncoder Prozess zu blockieren. Da ich noch etwas unerfahren bin, was diese Thematik angeht, würde ich mich freuen, wenn mir jemand bei der Problemlösung einen Hinweis geben könnte. Hier ein Ausschnitt des Codes, in dem der Fehler liegen muss, da sich das Programm an diesem Punkt aufhängt: # Execute the command. pin, pout, perr = popen2.popen3( command ) x = command while pin: print x x = pin.readline()[:-1] pin.flush() perr.flush() pin.close() pout.close() perr.close() "command" ist hierbei ein vorher generierter Befehl, der z.B. so aussehen kann: "mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4 -vop expand=176:144,scale=176:144 -o /tmp/movie2mobile.avi -ofps 15 sample.mpg" "while pin:" habe ich gewählt, weil ich annehme, dass pin == None wird, wenn der MEncoder Prozess beendet ist und die Pipe dabei schliesst, kann sein, dass ich auch da falsch liege, aber eine andere Möglichkeit zu prüfen, ob der Prozess fertig ist kenne ich bislang nicht. Die Ausgabe soll später auch geparst werden, um z.B. für ein GUI die nötigen Werte zu ermitteln. Was mich wundert ist, dass, bis zu einem gewissen Punkt, die Ausgabe funktioniert, was etwa so aussieht: --> Snip <-- mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4 -vop expand=176:144,scale=176:144 -o /tmp/movie2mobile.avi -ofps 15 sample.mpg MEncoder 1.0pre7-3.3.5 (C) 2000-2005 MPlayer Team CPU: Advanced Micro Devices (Family: 8, Stepping: 0) Detected cache-line size is 64 bytes CPUflags: Type: 8 MMX: 1 MMX2: 0 3DNow: 0 3DNow2: 0 SSE: 0 SSE2: 0 Compiled for x86 CPU with extensions: MMX success: format: 0 data: 0x0 - 0x25d01e4 MPEG-PS file format detected. VIDEO: MPEG1 352x288 (aspect 8) 25.000 fps 1150.0 kbps (143.8 kbyte/s) [V] filefmt:2 fourcc:0x10000001 size:352x288 fps:25.00 ftime:=0.0400 Opening video filter: [expand osd=1] Expand: -1 x -1, -1 ; -1 (-1=autodetect) osd: 1 Opening video filter: [expand w=176 h=144] Expand: 176 x 144, -1 ; -1 (-1=autodetect) osd: 0 Opening video filter: [scale w=176 h=144] ========================================================================== Opening video decoder: [mpegpes] MPEG 1/2 Video passthrough VDec: vo config request - 352 x 288 (preferred csp: Mpeg PES) VDecoder init failed :( Opening video decoder: [libmpeg2] MPEG 1/2 Video decoder libmpeg2-v0.4.0b Selected video codec: [mpeg12] vfm:libmpeg2 (MPEG-1 or 2 (libmpeg2)) ========================================================================== Writing AVI header... ODML: Aspect information not (yet?) available or unspecified, not writing vprp header. VDec: vo config request - 352 x 288 (preferred csp: Planar YV12) VDec: using Planar YV12 as output csp (no 0) Movie-Aspect is 1.33:1 - prescaling to correct movie aspect. SwScaler: reducing / aligning filtersize 9 -> 8 SwScaler: reducing / aligning filtersize 9 -> 8 SwScaler: reducing / aligning filtersize 9 -> 8 SwScaler: reducing / aligning filtersize 9 -> 8 SwScaler: BICUBIC scaler, from Planar YV12 to Planar YV12 using MMX videocodec: libavcodec (176x144 fourcc=34504d46 [FMP4]) ODML: Aspect information not (yet?) available or unspecified, not writing vprp header. --> /Snip <-- Ich würde mich wahnsinnig freuen, wenn mir hier jemand helfen könnte, damit ich nach mehreren Tagen Fehlersuche, Google und anderen erfolglosen Versuchen, den Fehler zu finden, endlich weiterkommen würde. Grüße, Paul. -- Paul Schulze Mail: avlex@gmx.net Public Key: http://lightbringer.dyndns.org/keys/key_avlex.asc _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de

"while pin:" habe ich gewählt, weil ich annehme, dass pin == None wird, wenn der MEncoder Prozess beendet ist und die Pipe dabei schliesst, kann sein, dass ich auch da falsch liege, aber eine andere Möglichkeit zu prüfen, ob der Prozess fertig ist kenne ich bislang nicht.
Die Annahme ist falsch - woher soll denn wer anders einen Wert unter pin binden? Im TFM steht: Popen3 and Popen4 Objects Instances of the Popen3 and Popen4 classes have the following methods: poll( ) Returns -1 if child process hasn't completed yet, or its return code otherwise. wait( ) Waits for and returns the status code of the child process. The status code encodes both the return code of the process and information about whether it exited using the exit() system call or died due to a signal. Functions to help interpret the status code are defined in the os module; see section 6.1.5 for the W*() family of functions. Also: wait() aufrufen. MfG Diez _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de

Hallo ihr Beiden, Erst einmal danke für die schnellen Antworten von euch. Ich habe mich nun entschlossen auf popen2.popen3 zu verzichten und statt dessen Popen3 zu verwenden und Stderr nach Stdout des Child Prozesses umzuleiten (hauptsächlich, weil ich keine Ahnung habe, wie man diesen aus einem Popen3 Objekt ausliest und die Ausgabe im Terminal unterdrückt, 2>&1 war mein Freund). Damit hat mir der Hinweis auf Popen3.poll() natürlich sehr geholfen. Kann es sein, dass das auch die portablere Variante ist? Macht zu mindest auf den ersten Blick den Eindruck, da es glaube auch unter Windows entsprechende Mechanismen gibt (hab das nur mal gehört, ich hab kaum Ahnung von Windows Programmierung). Wenn ihr in dieser Hinsicht noch Hinweise für eventuelle Portierungen habt, bin ich sehr dankbar, das Programm soll schliesslich irgendwann mal für Mac und Windows zur Verfügung stehen. Ich habe mir auch commands.getstatusoutput( <cmd> ) mal angesehen und finde es für ein einfaches Ausführen brauchbar, allerdings brauche ich in diesem Fall die Ausgabe in Echtzeit (hab ich damit nicht hinbekommen), ich will ja schliesslich die Daten der Ausgabe (etwa für eine Progress Bar) direkt haben und nicht erst später. Das hab ich nun mit einigem hin und her mit den flush() Methoden der from/tochild Eigenschaften hinbekommen. Falls ich die Tage noch rausfinde, wie ich mit Sourceforge umgehen muss, werde ich den gesammten Source Code dann auch unter der GPL Lizens online stellen, vielleicht wollt ihr ja mal reinschaun. Das Projekt, welches ich dafür angemeldet habe, heisst movie2mobile, ist aber noch nicht genehmigt, da ich mir sowas ja immer erst vor einem Wochenende überlegen muss... Danke für die Hilfe, Paul. Am Freitag, den 07.10.2005, 16:11 +0200 schrieb Diez B. Roggisch:
"while pin:" habe ich gewählt, weil ich annehme, dass pin == None wird, wenn der MEncoder Prozess beendet ist und die Pipe dabei schliesst, kann sein, dass ich auch da falsch liege, aber eine andere Möglichkeit zu prüfen, ob der Prozess fertig ist kenne ich bislang nicht.
Die Annahme ist falsch - woher soll denn wer anders einen Wert unter pin binden?
Im TFM steht:
Popen3 and Popen4 Objects Instances of the Popen3 and Popen4 classes have the following methods: poll( ) Returns -1 if child process hasn't completed yet, or its return code otherwise. wait( ) Waits for and returns the status code of the child process. The status code encodes both the return code of the process and information about whether it exited using the exit() system call or died due to a signal. Functions to help interpret the status code are defined in the os module; see section 6.1.5 for the W*() family of functions.
Also: wait() aufrufen.
MfG Diez
Am Freitag, den 07.10.2005, 16:07 +0200 schrieb Hartmut Goebel:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hallo,
Paul Schulze schrieb:
aussehen kann: "mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4 -vop expand=176:144,scale=176:144 -o /tmp/movie2mobile.avi -ofps 15 sample.mpg"
Dieses Kommando bekommt doch das Ein- und das Ausgabe-File genannt, oder? Dann kannst Du das einfacher haben:
import commands status, text = commands.getstatusoutput(command)
In Python 2.4 gibt es ein neuse Modul "subprocess", dass Dir hier ahber keine Vorteile verschafft.
"while pin:" habe ich gewählt, weil ich annehme, dass pin == None wird,
Das stimmt nicht! pin ist eine Variable Deinen Scopes und kann daher nicht von einer andern Funktion verändert werden.
Wenn dann müsstest Du while pin.readline(): ... oder for x in pin.readlines(): nehmen.
- -- Schönen Gruß - Regards Hartmut Goebel
| Hartmut Goebel | IT-Security -- effizient | | h.goebel@goebel-consult.de | www.goebel-consult.de | -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org
iQEUAwUBQ0aBBszajR0mSa83AQIU6gf46qDiUuug4hg8+YQgQXNSRcJkrzgybNLb 5dULkfOFDOkOHGztJRIL9IRRAIHpxmDk9ceipsr+SQADWh5Wj4IcZtCwWM49R+7V hvMmhNhDj+Uk/HtJzkTcWP+fvxzbxatbuc2Y8M9TvXAdzjg/bkQ9xoQbRCkO+BLI lx/7Yu+ZtBnl3PrHXex0O8pPAE6DlS6cb5lKTj2AkMPRig00/m/PWPGNZc3bOyTJ l+ZSa9CXeECXBiwb61+h5SWGRd1QV+0rYscWWQLMD0b/lxWaojUuXQcB55HOR4uU AL+LZQNXVMG5W4X8VaHsIVYgAhAp3p0gcPbm6Cf5CO/VuihSWc50 =w26W -----END PGP SIGNATURE----- -- Paul Schulze Mail: avlex@gmx.net Public Key: http://lightbringer.dyndns.org/keys/key_avlex.asc
_______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Paul Schulze schrieb:
Ich habe mir auch commands.getstatusoutput( <cmd> ) mal angesehen und finde es für ein einfaches Ausführen brauchbar, allerdings brauche ich in diesem Fall die Ausgabe in Echtzeit (hab ich damit nicht hinbekommen), ich will ja schliesslich die Daten der Ausgabe (etwa für
commands.* liefert den output erst am Ende. Für Deine Anforderungen ist es also nicht geeignet. - -- Schönen Gruß - Regards Hartmut Goebel | Hartmut Goebel | IT-Security -- effizient | | h.goebel@goebel-consult.de | www.goebel-consult.de | -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org iQEVAwUBQ0gSuszajR0mSa83AQIW2wf/e226u8xiirXLicXFSjK9JJXRsj0ZLInV BCwBhw8fVcxxFMcrBJT1n/70FZi9elVPcIYQWFy305NjUwngDtKzBnWE2K82dwqe 4nWtCeUj3xw3wU8YwL7lUQv22WQ7MhlsrDrzGh0Qzi1kL2Swn6HDSNU5PTGpXPlf uW3bE7q4HxR0ePooneIt8uTY0QcuZGJGIA5lKBdFYCKpH4yAP+S4lfeJYKoJy+hX tZ6qWaKcCd61HR9gCUH39SAw9LlIOP59jasdjZwNqGsfREtobBK1S5pk1fsQ1E5R OoIM/ZWo+g+OKdufGhtiM2edUelZJqSSwFZBL7EGEjoOCDRPUsO/VA== =ox9f -----END PGP SIGNATURE----- _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
participants (3)
-
Diez B. Roggisch
-
Hartmut Goebel
-
Paul Schulze