• Willkommen im Linux Club - dem deutschsprachigen Supportforum für GNU/Linux. Registriere dich kostenlos, um alle Inhalte zu sehen und Fragen zu stellen.

Das Videoconverterscript

abgdf

Guru
Hallo,

nach etwas Diskussion über das Videoconverterscript unter

http://www.linux-club.de/viewtopic.php?f=18&t=104415

jetzt ein Vorschlag von mir für ein grafisches Abfragen der Optionen (mit dialog):

http://paste.pocoo.org/show/130417/

Viele Grüße
 
OP
A

abgdf

Guru
Hallo,

hier noch eine Abwandlung des Videoconverterscripts, ein Skript "mkdvd":

Es erzeugt (hoffentlich) aus einer mit mplayer abspielbaren Videodatei mittels "dvdauthor" die Dateien, die man benötigt, um diese auf eine DVD zu brennen und dann in einem DVD-Player über einen Fernseher abzuspielen.
Die Verzeichnisse "VIDEO_TS" und "AUDIO_TS" werden in ein Verzeichnis "mydvd" unterhalb des aktuellen Verzeichnisses geschrieben.

Zum Test wird am Ende das fertige DVD-Video aus dem Verzeichnis mit mplayer gezeigt:
Code:
#!/bin/bash

# mkdvd
# by abgdf, 4.9.2009, Licence GNU GPL

if test -z "$1" 
then
    echo "Usage: mkdvd file.avi"
    exit 1  
fi  

if test -e "./dvd.mpg" 
then 
    echo "File 'dvd.mpg' already exists. Nothing done."
    exit 2  
fi  

if test -e "./mydvd" 
then 
    echo "Directory 'mydvd' already exists. Nothing done."
    exit 3
fi  

mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=352:576,harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:acodec=ac3:abitrate=192:aspect=4/3 -ofps 25 -o "dvd.mpg" "$1"

mkdir -p ./mydvd/VIDEO_TS
mkdir -p ./mydvd/AUDIO_TS

dvdauthor -o "./mydvd" -t -f "./dvd.mpg"
rm ./dvd.mpg

dvdauthor -T

mplayer dvd:// -dvd-device ./mydvd/VIDEO_TS/
Also, ich find's cool :mrgreen:.

Viele Grüße
 
OP
A

abgdf

Guru
.. und dieses Python-Skript (Python 2.x) "mkdvd.py" sollte nach (fast) demselben Prinzip sogar mehrere Videodateien zu einer DVD mit mehreren Titeln verbinden (benötigt also auch mencoder und dvdauthor):
Code:
#!/usr/bin/env python
#-*- coding: iso-8859-1 -*-

# mkdvd.py
# by abgdf, 9.2009, Licence GNU GPL.

import sys
import os
import subprocess

def getNum(a):

    if a < 10:
        return "0" + str(a)
    else:
        return str(a)

args = sys.argv[1:]

if len(args) < 1:
    print "Usage: mkdvd.py title1.avi [title2.avi title3.avi ...]"
    sys.exit(1)

subdir = "mydvd"

if os.path.exists(os.path.join(os.getcwd(), subdir)):
    print "Subdirectory '" + subdir + "' already exists. Nothing done."
    sys.exit(2)
else:
    os.mkdir(os.path.join(os.getcwd(), subdir))
    os.mkdir(os.path.join(os.getcwd(), subdir, "files"))

menc = ["mencoder",
        "-oac",
        "lavc",
        "-ovc",
        "lavc",
        "-of",
        "mpeg",
        "-mpegopts",
        "format=dvd",
        "-vf",
        "scale=352:576,harddup",
        "-srate",
        "48000",
        "-af",
        "lavcresample=48000",
        "-lavcopts",
        "vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:acodec=ac3:abitrate=192:aspect=4/3",
        "-ofps",
        "25",
        "-o"]

fnames = []

for i in range(len(args)):
    fnames.append(os.path.join(os.getcwd(), subdir, "files", "dvd" + getNum(i + 1) + ".mpg"))
    menc.append(fnames[i])
    menc.append(args[i])
    subprocess.call(menc)
    print menc
    menc.pop()
    menc.pop()

xml = ['<dvdauthor dest="' + os.path.join(os.getcwd(), subdir) + '" >',
       '  <vmgm/>',
       '  <titleset>',
       '    <titles>',
       '      <video format="pal" aspect="4:3" />',
       '      <audio lang="DE" />']

for i in fnames:
    xml.append('      <pgc>')
    xml.append('        <vob file="' + i + '" chapters="00:00:00.00" />')
    xml.append('        <post>exit;</post>')
    xml.append('      </pgc>')

xml.extend(('    </titles>',
        '  </titleset>',
        '</dvdauthor>'))

xmlfname = os.path.join(os.getcwd(), subdir, "files", "dvdauthor.xml")

fh = file(xmlfname, "w")
for i in xml:
    fh.write(i + "\n")
fh.close()

subprocess.call(("dvdauthor", "-x", xmlfname))

print
print "Cleaning up."

for i in fnames:
    os.remove(i)

os.remove(xmlfname)

os.rmdir(os.path.join(os.getcwd(), subdir, "files"))

print
print "Finished: Directories 'VIDEO_TS' and 'AUDIO_TS' should be in"
print "'" + os.path.join(os.getcwd(), subdir) + "'. Bye."
print
:cool:

Viele Grüße
 
OP
A

abgdf

Guru
Dankeschön! Hab's heut' noch mal etwas verändert, das heißt hoffentlich noch ein bißchen schöner gemacht :p:
Code:
Siehe unten
Viele Grüße
 

TomcatMJ

Guru
Na das freut mich doch zu sehen daß mein kleines Converterscript mit dem ich mir in letzter Zeit Videos für UltraStar Deluxe und Performous passend umbastel (ist dann VCD bzw. XVCD Format) und Videos für die Nutzung mit mandvd bzw. tovid-gui vorbereite als Inspiration für dich gedient hat ;)
Im Laufe der Woche guck ich mir deine Scripte dann wohl auch mal etwas näher an, hab nur leider momentan nicht genug Zeit dafür :D

Tipp noch zur Lizenzierung: Du solltest noch die Version der GPL dazuschreiben unter der du dein neues Script stellken willst um irgendwelche Verwirrungen bzw. Unklarheiten zu vermeiden.

Bis denne,
Tom
 
OP
A

abgdf

Guru
Danke TomcatMJ, hab' dann also GPL 3 geschrieben.
Und noch ein paar Fehler abgefangen sowie ein paar Optionen einschließlich "-h" (Hilfe) eingefügt. Also, dann sieht das jetzt so aus:
Code:
#!/usr/bin/env python
#-*- coding: iso-8859-1 -*-

# mkdvd.py
#
# by abgdf, 9.2009, Licence GNU GPL, Version 3:
# http://www.gnu.org/licenses/gpl.html

import os
import sys

CLEAN = True
QUIET = True
SUBDIRNAME = "mydvd"

args = sys.argv[1:]

if len(args) < 1:
    print "Usage: mkdvd.py title1.avi [title2.avi title3.avi ...] [-v] [--noclean]"
    sys.exit(1)

for i in args:

    if "-v" in args:
        QUIET = False
        while "-v" in args:
            args.remove("-v")

    if "--noclean" in args:
        CLEAN = False
        while "--noclean" in args:
            args.remove("--noclean")

    if "-h" in args:

        print
        print "mkdvd.py by abgdf, 9.2009 (GNU GPL, V.3):"
        print "Create DVD-type movie-files (VOB etc.) using mencoder and dvdauthor."
        print
        print "Usage: mkdvd.py title1.avi [title2.avi title3.avi ...] [-v] [--noclean]"
        print
        print "Options:"
        print
        print "-v             Verbose: Don't suppress output of mencoder and dvdauthor."
        print "--noclean      Leave temporary (usually large) files in './mydvd/files'."
        print
        sys.exit(0)

subdir   = os.path.join(os.getcwd(), SUBDIRNAME)
filesdir = os.path.join(subdir, "files")

if os.path.exists(subdir):
    print "Subdirectory '" + subdir + "' already exists. Nothing done."
    sys.exit(2)

for i in args:

    if not os.path.isfile(os.path.join(os.getcwd(), i)):
        print "Error: File '" + os.path.join(os.getcwd(), i) + "' not found. Aborting."
        sys.exit(3)

os.mkdir(subdir)
os.mkdir(filesdir)

menc = ["mencoder", "-oac", "lavc", "-ovc", "lavc", "-of", "mpeg",
        "-mpegopts", "format=dvd", "-vf", "scale=352:576,harddup",
        "-srate", "48000", "-af", "lavcresample=48000", "-lavcopts",
        "vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:acodec=ac3:abitrate=192:aspect=4/3",
        "-ofps", "25", "-o"]

fnames = []

print
step_ = 1

for i in range(len(args)):

    if i < 10:
        istr = "0" + str(i + 1)
    else:
        istr = str(i + 1)

    fnames.append("dvd" + istr + ".mpg")

    menc.append(os.path.join(filesdir, fnames[i]))
    menc.append(args[i])

    if QUIET:
        menc.append("&>/dev/null")

    print str(step_) + ". Running mencoder on '" + args[i] + "'."
    step_ += 1

    os.system(" ".join(menc))

    menc.pop()
    menc.pop()
    if QUIET:
        menc.pop()

for i in range(len(fnames)):

    if not os.path.isfile(os.path.join(filesdir, fnames[i])):
        print
        print "Error: File '" + os.path.join(filesdir, fnames[i]) + "' missing."
        print "Probably mencoder had problems processing file '" + args[i] + "'."
        print "Aborting."
        print
        sys.exit(4)

# Composing xml-file for dvdauthor:

xml = ['<dvdauthor dest="' + subdir + '" >',
       '  <vmgm/>',
       '  <titleset>',
       '    <titles>',
       '      <video format="pal" aspect="4:3" />',
       '      <audio lang="DE" />']

for i in range(len(fnames)):

    xml.append('      <pgc>')
    xml.append('        <vob file="' + os.path.join(filesdir, fnames[i]) + '" chapters="00:00:00.00" />')

    # After playing a title, stop playing:

    xml.append('        <post>exit;</post>')

    """
    # After playing a title, move to the next one, if possible:

    if i < len(fnames) - 1:
        xml.append('        <post>jump title ' + str(i + 2) + ';</post>')
    else:
        xml.append('        <post>exit;</post>')
    """
    xml.append('      </pgc>')

xml.extend(('    </titles>',
        '  </titleset>',
        '</dvdauthor>'))

xmlfname = os.path.join(filesdir, "dvdauthor.xml")

print str(step_) + ". Writing xml-file."
step_ += 1

fh = file(xmlfname, "w")
for i in xml:
    fh.write(i + "\n")
fh.close()

print str(step_) + ". Running dvdauthor."
step_ += 1

dvda = "dvdauthor -x " + xmlfname

if QUIET:
    dvda += " &>/dev/null"

os.system(dvda)

if CLEAN:
    print str(step_) + ". Cleaning up."
    step_ += 1
    for i in fnames:
        os.remove(os.path.join(filesdir, i))
    os.remove(xmlfname)
    os.rmdir(filesdir)

print
print "Finished:"
print "Directories 'VIDEO_TS' and 'AUDIO_TS' should be in '" + subdir + "'."
print "Bye."
print
Wahrscheinlich kann das bei vielen von euch auch z.B. DeVeDe, aber bei mir gibt das immer einen Error, vielleicht, weil meine mplayer-Installation zu alt ist. Deshalb dann also das Skript oben, das bei mir ganz gut läuft, auch wenn es natürlich nur sehr eingeschränkte Optionen bietet (nur PAL, 4:3, DE).
Es ist ja auch eher ein schnell geschriebenes Skript ("Hack") als eine ausgereifte Anwendung ...

Viele Grüße
 
Oben