<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://forum.ubuntu-fr.org/extern.php?action=feed&amp;tid=916501&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Forum Ubuntu-fr.org / [Script/Python] convertir des vidéos mp4 en mkv dès qu'elles arrivent]]></title>
		<link>http://forum.ubuntu-fr.org/viewtopic.php?id=916501</link>
		<description><![CDATA[Les sujets les plus récents dans [Script/Python] convertir des vidéos mp4 en mkv dès qu'elles arrivent.]]></description>
		<lastBuildDate>Mon, 14 May 2012 09:32:44 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Réponse à&#160;:  [Script/Python] convertir des vidéos mp4 en mkv dès qu'elles arrivent]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=9252891#p9252891</link>
			<description><![CDATA[<p>Merci. Je vais essayer.</p>]]></description>
			<author><![CDATA[dummy@example.com (thom83)]]></author>
			<pubDate>Mon, 14 May 2012 09:32:44 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=9252891#p9252891</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [Script/Python] convertir des vidéos mp4 en mkv dès qu'elles arrivent]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=9250911#p9250911</link>
			<description><![CDATA[<p>En fait, si tu regardes la doc, tu verras que mon exemple est juste le code du daemon de la doc pyinotify</p><p><a href="https://github.com/seb-m/pyinotify/blob/master/python2/examples/daemon.py">https://github.com/seb-m/pyinotify/blob … /daemon.py</a></p><p>auquel j&#039;ai ajouté la class EventHandler, piquée à<br /><a href="https://github.com/seb-m/pyinotify/blob/master/python2/examples/tutorial_notifier.py">https://github.com/seb-m/pyinotify/blob … otifier.py</a></p><p>Ensuite j&#039;ajoute une action (ffmpeg sur le fichier reçu, ou ce qu&#039;on veut, cp, mv...).</p><p>J&#039;ai testé en copiant 3 fichiers d&#039;un coup dans la directory, pas de problème.</p>]]></description>
			<author><![CDATA[dummy@example.com (k3c)]]></author>
			<pubDate>Mon, 14 May 2012 05:37:22 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=9250911#p9250911</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [Script/Python] convertir des vidéos mp4 en mkv dès qu'elles arrivent]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=9250081#p9250081</link>
			<description><![CDATA[<p>Tu le lances au démarrage de ta machine par exemple, via un bête</p><div class="codebox"><pre><code>python daemon_pyinotify.py</code></pre></div><p>Ca te rend la main de suite, c&#039;est un daemon, il tourne dans son coin.</p><p>Il y a juste une chose à savoir dans ce script, la ligne</p><div class="codebox"><pre><code>process = subprocess.call([&#039;ffmpeg&#039;, &#039;-i&#039;, fichier, &#039;-y&#039;, &#039;-vcodec&#039;, &#039;copy&#039; , &#039;-acodec&#039;, &#039;copy&#039;, fichier[:-4] + &#039;.mkv&#039;])</code></pre></div><p>peut être remplacée par ce que tu veux, mais si tu veux exécuter par exemple la commande</p><div class="codebox"><pre><code>cp fichier /home/abc/traitement</code></pre></div><p>tu ne mets pas les blancs, tu écris juste</p><div class="codebox"><pre><code>process = subprocess.call([&#039;cp&#039;, fichier,&#039;/home/gg/traitement&#039;])</code></pre></div><p>(et enlever le test sur .mp4 si tu veux faire un truc différent).</p>]]></description>
			<author><![CDATA[dummy@example.com (k3c)]]></author>
			<pubDate>Sun, 13 May 2012 22:53:44 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=9250081#p9250081</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [Script/Python] convertir des vidéos mp4 en mkv dès qu'elles arrivent]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=9244171#p9244171</link>
			<description><![CDATA[<p>Où met-on ce script, et à quel moment le lance-t-on, à moins qu&#039;il se lance lui-même ?</p>]]></description>
			<author><![CDATA[dummy@example.com (thom83)]]></author>
			<pubDate>Sun, 13 May 2012 13:33:49 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=9244171#p9244171</guid>
		</item>
		<item>
			<title><![CDATA[[Script/Python] convertir des vidéos mp4 en mkv dès qu'elles arrivent]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=9218931#p9218931</link>
			<description><![CDATA[<p>Bonjour</p><p>Je récupère des vidéos avec TVDownloader<br /><a href="http://forum.ubuntu-fr.org/viewtopic.php?id=409313&amp;p=1">http://forum.ubuntu-fr.org/viewtopic.php?id=409313&amp;p=1</a></p><p>Je copie ensuite ces vidéos sur ma Dune <br /><a href="http://hdland.fr/lang-en/lecteurs-multimedias/111-dune-hd-max-lecteur-multimedia-avec-lecteur-bluray-489703134012.html">http://hdland.fr/lang-en/lecteurs-multi … 34012.html</a><br />qui lit tous les formats, sauf le mp4</p><p>Comme j&#039;oublie régulièrement de convertir mes vidéos, j&#039;ai écrit un petit script tout simple, qui utilise pyinotify pour surveiller le répertoire ~/TVDownloader</p><p>Quand je lance TVDownloader et qu&#039;un fichier .mp4 y est complètement écrit (surveillance de l&#039;évènement IN_CLOSE_WRITE), une commande de conversion </p><div class="codebox"><pre><code>ffmpeg -i fichier.mp4 -y -vcodec copy -acodec copy fichier.mkv</code></pre></div><p>est lancée<br />le -y sert à forcer la création du fichier .mkv si un fichier partiel existait déjà.</p><p>Remplacer dans le script /home/gg/TVdownloader par votre répertoire d&#039;installation de TVDownloader (ou un autre répertoire que vous voulez surveiller)</p><p>Le fichier<br />/tmp/pyinotify.pid<br />contient le pid du process daemon</p><p>Le code</p><div class="codebox"><pre class="vscroll"><code># Example: daemonize pyinotify&#039;s notifier.
# Requires Python &gt;= 2.5
import functools
import sys
import pyinotify
import subprocess

class Counter(object):
    &quot;&quot;&quot;
    Simple counter.
    &quot;&quot;&quot;
    def __init__(self):
        self.count = 0
    def plusone(self):
        self.count += 1

class EventHandler(pyinotify.ProcessEvent):
    def process_IN_CLOSE_WRITE(self, event):
        print &quot;Close_write:&quot;, event.pathname
        fichier = event.pathname
        if fichier[-4:].lower() == &#039;.mp4&#039;:
            process = subprocess.call([&#039;ffmpeg&#039;, &#039;-i&#039;, fichier, &#039;-y&#039;, &#039;-vcodec&#039;, &#039;copy&#039; , &#039;-acodec&#039;, &#039;copy&#039;, fichier[:-4] + &#039;.mkv&#039;])
def on_loop(notifier, counter):
    &quot;&quot;&quot;
    Dummy function called after each event loop, this method only
    ensures the child process eventually exits (after 5 iterations).
    &quot;&quot;&quot;
    sys.stdout.write(&quot;Loop %d\n&quot; % counter.count)
    counter.plusone()

handler = EventHandler()
wm = pyinotify.WatchManager()
notifier = pyinotify.Notifier(wm, handler)
wm.add_watch(&#039;/home/gg/TVDownloader&#039;, pyinotify.IN_CLOSE_WRITE)
on_loop_func = functools.partial(on_loop, counter=Counter())
try:
    notifier.loop(daemonize=True, callback=on_loop_func,
                 pid_file=&#039;/tmp/pyinotify.pid&#039;, stdout=&#039;/tmp/stdout.txt&#039;)
except pyinotify.NotifierError, err:
    print &gt;&gt; sys.stderr, err</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (k3c)]]></author>
			<pubDate>Fri, 11 May 2012 15:11:10 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=9218931#p9218931</guid>
		</item>
	</channel>
</rss>
