Username or Email
Password
Remember me
Sign in
Sign up
Add Paste
Add Collection
You are not allowed to edit this paste! A fork will be created instead.
C/C++
CSS
HTML
Markdown
PHP
Python
Text
ABAP
ActionScript
ADA
Apache Conf
AsciiDoc
Assembly x86
AutoHotKey
BatchFile
BBCode
C9Search
Clojure
Cobol
CoffeeScript
ColdFusion
C#
Curly
D
Dart
Diff
Dot
Erlang
EJS
Forth
FreeMarker
Glsl
Go
Groovy
HAML
Handlebars
Haskell
haXe
HTML (Ruby)
INI
Jack
Jade
Java
JavaScript
JSON
JSONiq
JSP
JSX
Julia
LaTeX
LESS
Liquid
Lisp
LiveScript
LogiQL
LSL
Lua
LuaPage
Lucene
Makefile
MATLAB
MEL
MySQL
MUSHCode
Nix
Objective-C
OCaml
Pascal
Perl
pgSQL
Powershell
Prolog
Properties
Protobuf
R
RDoc
RHTML
Ruby
Rust
SASS
SCAD
Scala
Scheme
SCSS
SH
SJS
Space
snippets
Soy Template
SQL
Stylus
SVG
Tcl
Tex
Textile
Toml
Twig
Typescript
VBScript
Velocity
Verilog
XML
XQuery
YAML
#!/usr/bin/env python2 # # Quick and dirty ffmpeg command crafter # # Outputs the ffmpeg command to encode your raw MPEG2 Video file with h264 into # a matroska container. You can optionally select start/end time and a specific # audio tracks (e.g ac3). # # Copyright (c) 2014 by ManiacTwister # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see
. # import sys, getopt, time, os, pipes try: from ffprobe import FFProbe except ImportError: raise ImportError('Please install the python ffprobe package. E.g with: sudo pip2 install ffprobe') def printHelp(argv): print argv[0] + ' -i
-o
[-s
-e
-ac
--overwrite]' def errorMsg(msg): print msg sys.exit(2) def isTimeFormat(input): try: time.strptime(input, '%H:%M:%S') return True except ValueError: return False def main(argv): ffmpeg_args = ["ffmpeg"] inputfile = '' concatfile = '' outputfile = None start = None end = None acodec = None overwrite = False audio_index = None try: opts, args = getopt.getopt(argv[1:],"hi:o:s:e:a:c:f",["ifile=","ofile=","start=","end=","acodec=", "concat=", "overwrite"]) except getopt.GetoptError: printHelp(argv) sys.exit(2) for opt, arg in opts: if opt == '-h': printHelp(argv) sys.exit() elif opt in ("-i", "--ifile"): inputfile = arg elif opt in ("-c", "--concat"): concatfile = arg elif opt in ("-o", "--ofile"): outputfile = arg elif opt in ("-s", "--start"): start = arg elif opt in ("-e", "--end"): end = arg elif opt in ("-a", "--acodec"): acodec = arg elif opt in ("-f", "--overwrite"): overwrite = True if concatfile is not '': concat_file = open(concatfile, "r") videofiles = concat_file.read().splitlines() inputfile = videofiles[0].replace("file '", "").replace("'", "") ffmpeg_args.append("-f concat") ffmpeg_args.append("-i") if not os.path.isfile(inputfile): errorMsg("Input file '" + inputfile + "' doesn't exist") if outputfile is None: outputfile = inputfile.replace(".m2t", ".mkv"); outputfile = outputfile.replace("raw/", ""); if os.path.isfile(outputfile) and not overwrite: errorMsg("Output file '" + inputfile + "' does exist. Use -f to overwrite") if concatfile is not '': ffmpeg_args.append(pipes.quote(concatfile)) else: ffmpeg_args.append(pipes.quote(inputfile)) ffmpeg_args.append("-sn") # Append start and end time if start is not None: if isTimeFormat(start): ffmpeg_args.append("-ss " + start) else: errorMsg("Start time '" + start + "' has wrong format") if end is not None: if isTimeFormat(end): ffmpeg_args.append("-to " + end) else: errorMsg("End time '" + end + "' has wrong format") ffmpeg_args.append("-c:v libx264 -map 0:0 -c:a copy") # Append audio stream if acodec is not None: metadata=FFProbe(inputfile) for stream in metadata.streams: if stream.isAudio() and stream.codec() == acodec: audio_index = stream.__dict__['index'] break if audio_index is None: print("Audio stream with codec '" + acodec + "' not found, using 0") else: ffmpeg_args.append("-map 0:" + audio_index) ffmpeg_args.append("-f matroska") ffmpeg_args.append(pipes.quote(outputfile)) print ' '.join(ffmpeg_args) if __name__ == "__main__": main(sys.argv)
Private