Skip to content

Commit

Permalink
Connected settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kanehekili committed Dec 20, 2022
1 parent b100e5e commit 8ced7a8
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 47 deletions.
1 change: 1 addition & 0 deletions .settings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/org.eclipse.core.resources.prefs
67 changes: 51 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,76 @@
# VideoMerge
Version 1.0.1
Version 1.0.2

![Download](https://github.com/kanehekili/VideoMerge/releases/download/1.0.1/videomerge1.0.1.tar)
![Download](https://github.com/kanehekili/VideoMerge/releases/download/1.0.1/videomerge1.0.2.tar)

UI Tool to merge different videos using ffmpeg
Supports the (fast) merge of homogenius streams as well as (slower) reencoding different file formats.

##Features
## Features
VideoMerge tends to have a very simple interface, It detects the best way to concat mp2,mp4,mkv,webm and more containers into one video.

![Screenshot](https://github.com/kanehekili/VideoMerge/blob/main/Merge1.png)

Using settings (the cog icon), reencoding can be forced (takes longer) and the rotational infos may be ignored. Used as fallback, if the "automatic" merge doesn't deliver the results expected.

Different rotated videos will be made "homogenious", see the limitations for more infos.

### Prerequisites
* python3
* ffmpeg
* python3-pyqt5 on Debian and derivatives

#### Set GTK Theme for this QT application
If you are running a DE with GTK/Gnome (as opposed to LXQT or KDE) you need to tweak your system:
(Arch users may have to install qt5-styleplugins from AUR)

`sudo nano /etc/environment`

add the following line:

`QT_QPA_PLATFORMTHEME=gtk2`

and logout/login (or reboot)


##Limitations
Currently VideoMerge will not merge Portrait and Landscape Video - it simply makes no sense.
On reencoding, all videos needs to have the same resolution, size and framespeed (fps). Curerntly the first video in the list will be the "reference" for all videos in the list.
## Limitations
Currently VideoMerge will not merge Portrait and Landscape Video - use the settings to turn rotational recognition off.
On reencoding, all videos needs to have the same resolution, size and framespeed (fps). Currently the first video in the list will be the "reference" for all videos in the list.

##Issues
## Issues
Merging videos is complex, since there are many variations. If you encounter a problem, post parts of the videos to a website where I can download them.

##Installation
todo
## Installation

#Arch Linux
get it from AUR
### How to install with a terminal
* Install dependencies (see prerequisites)
* Download the videocut*.tar from the download link (see above)
* Extract it to a location that suits you.
* Open a terminal to execute the install.sh file inside the folder with sudo like `sudo ./install.sh`
* The app will be installed in /opt/videomerge with a link to /usr/bin.
* The app should be appear in a menu or "Actvities"
* In the terminal can be started via `videomerge`
* python qt5 and ffmpeg are required
* you may now remove that download directory.
* logs can be found in the user home ".config/VideoMerge" folder

#Ubuntu and Debian
ppa

##Changes
### Arch Linux
TODO

### Ubuntu and Debian
TODO

## Changes
20.12.2022
* Path fixes

18.12.2022
* Rotational recognition

10.12.2022
* Initial release

18.10.2022
* Rotational recognition



Expand Down
2 changes: 1 addition & 1 deletion build/build.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
startApp=VideoMerge.py
appName=videomerge
version=1.0.1
version=1.0.2
pkgrelease=1
ubu1=focal
ubu2=jammy
80 changes: 50 additions & 30 deletions src/VideoMerge.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# copyright (c) 2022 kanehekili ([email protected])
# 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 2 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
# <http://www.gnu.org/licenses/>.
'''
Created on Apr 16, 2020
Expand All @@ -15,7 +27,7 @@
import datetime
import re
import FFMPEGTools
from FFMPEGTools import FFStreamProbe
from FFMPEGTools import FFStreamProbe,OSTools
from fractions import Fraction
import glob

Expand All @@ -34,11 +46,12 @@ def __init__(self,debugOptions):
FFMPEGTools.setupRotatingLogger("VideoMerge",debugOptions["logConsole"])
FFMPEGTools.setLogLevel(debugOptions["level"])
log.info("Start session")
self.setWindowIcon(self.getAppIcon())
self.setWindowIcon(getAppIcon()) #Titlebar icon only!
self.mimeHelper = MimeHelper()
self._generateStatusIcons()
self.init_ui()
self.merger=None
self.settings=SettingsModel()

def init_ui(self):
self.setWindowTitle("VideoMerge")
Expand Down Expand Up @@ -107,9 +120,6 @@ def _generateStatusIcons(self):
self.statusIcons = [t1,t2,t3]
#?self.statusIcons = [QtGui.QIcon(QtCore.QDir.current().absoluteFilePath("/icons/"+name)) for name in ["idleIcon.png", "execIcon.png","doneIcon.png"]]

def getAppIcon(self):
return QtGui.QIcon('icons/merge.png')


def init_toolbar(self):
self.startAction = QtWidgets.QAction(QtGui.QIcon('./icons/start-icon.png'), 'Start Concat', self)
Expand Down Expand Up @@ -221,10 +231,9 @@ def startMerge(self):
me = MergeEntry(self.listWidget.items(indx))
mel.append(me)

self.merger = Merger(mel,self.mimeHelper.homogenious)
self.merger = Merger(mel,self.mimeHelper.homogenious,self.settings)
self.merger.onProgress.connect(self._onMergeProgress)
self.merger.onStatus.connect(self._showStatus)
self.merger.onImpossible.connect(self._noGood)
targetFile = self.getTargetFile(self.merger)
if targetFile is None:
return
Expand All @@ -237,10 +246,7 @@ def startMerge(self):

def _asyncMerge(self,targetFile):
self.merger.gatherInfos()
if self.merger.isImpossible():
self._showStatus(self.merger.lastError)
else:
self.merger.saveTo(targetFile)
self.merger.saveTo(targetFile)

def getTargetFile(self,merger):
targetPath = merger.getTargetPath()
Expand All @@ -257,7 +263,7 @@ def stopMerge(self):
self.merger.interrupt()

def openMediaSettings(self):
dlg = SettingsDialog(self, None) #no model yet: self.settings)
dlg = SettingsDialog(self, self.settings)
dlg.show()

def addURL(self,path):
Expand Down Expand Up @@ -302,7 +308,7 @@ def __init__(self):
# keep flags- save them later
super(SettingsModel, self).__init__()
self.reencode=False
self.rotation=False
self.noRotation=False


class SettingsDialog(QtWidgets.QDialog):
Expand All @@ -324,13 +330,15 @@ def init_ui(self):
encodeBox = QtWidgets.QVBoxLayout(frame1)
self.check_reencode = QtWidgets.QCheckBox("Force Reencode (Slow!)")
self.check_reencode.setToolTip("Reencode the files. Might take longer")
#self.check_reencode.setChecked(self.model.reencoding)#session data .must not be saved...
self.check_reencode.setChecked(self.model.reencode)#session data .must not be saved...
self.check_reencode.stateChanged.connect(self.on_reencodeChanged)
encodeBox.addWidget(self.check_reencode)

self.check_rotation = QtWidgets.QCheckBox("Ignore rotation information")
self.check_rotation.setToolTip("Ignore the roation infos. Might lead to funny results")
encodeBox.addWidget(self.check_rotation)
#self.check_reencode.setChecked(self.model.rotation)
self.check_rotation.setChecked(self.model.noRotation)
self.check_rotation.stateChanged.connect(self.on_rotationChanged)
outBox = QtWidgets.QVBoxLayout()
# outBox.addStretch(1)
self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
Expand All @@ -348,6 +356,13 @@ def init_ui(self):
# make it wider...
self.setMinimumSize(400, 0)

def on_reencodeChanged(self, reencode):
self.model.reencode = QtCore.Qt.Checked == reencode

def on_rotationChanged(self, rotation):
self.model.noRotation = QtCore.Qt.Checked == rotation


class LongRunningOperation(QtCore.QThread):
finished = pyqtSignal()
noGood= pyqtSignal(str)
Expand All @@ -364,7 +379,7 @@ def run(self):
#Log.logException("***Error in LongRunningOperation***")
#self.msg = "Error while converting: "+str(ex)
self.noGood.emit(str(ex))
traceback.print_exc(file=sys.stdout)
log.exception("Merge failure")
finally:
self.finished.emit()
self.quit()
Expand Down Expand Up @@ -529,7 +544,6 @@ def width(self):
class Merger(QtCore.QObject):
onProgress = pyqtSignal(int)
onStatus = pyqtSignal(str)
onImpossible = pyqtSignal(str)
REG_TIME = re.compile('(time=[ ]*)([0-9:.]+)') #2 groups!
MODE_FAST=1
MODE_TS=2
Expand All @@ -539,7 +553,7 @@ class Merger(QtCore.QObject):
TMP_FILE='/tmp/_merge'
ROT_FILE='/tmp/_rot'

def __init__(self,mergeEntryList,fastMode):
def __init__(self,mergeEntryList,fastMode,settings):
super(Merger, self).__init__()
self.runningProcess=None
self.mergeList=mergeEntryList
Expand All @@ -548,12 +562,12 @@ def __init__(self,mergeEntryList,fastMode):
self.timeMark=None
self.processed=0
#self.fastMode=fastMode #either fast or needs to reencode
self.conversionMode=self.MODE_FAST if fastMode else self.MODE_REENCODE
self.conversionMode=self.MODE_FAST if fastMode and not settings.reencode else self.MODE_REENCODE
self.errors=[]
self.videoList=[]
self.totalTime=0
self.timeCursor=0 #for multi TS operations like rotatate & mux
self.lastError=None
self.settings=settings

'''
Must be the same:
Expand Down Expand Up @@ -615,10 +629,9 @@ def _refineMuxing(self):
if val is not None:
log.info("Invalid stream value %s : %s - ignoring file %s"%(val,adjacent,adjacent.src)) #TODO cal.value(key)

if not ca.hasCompatibleRotation(adjacent):
self.lastError="Portrait and Landscape can't be joined"
self.conversionMode=self.MODE_IMPOSSIBLE
self.onImpossible.emit(self.lastError)
if not ca.hasCompatibleRotation(adjacent) and self.autoRotate():
self.errors.append("Portrait and Landscape can't be joined")
self.validateDone()
break

self.conversionMode=self.MODE_REENCODE #brute force. take the first videoList
Expand All @@ -630,6 +643,8 @@ def _refineMuxing(self):
self.onStatus.emit("Merging with TS filters")
break

def autoRotate(self):
return not self.settings.noRotation

def healFPS(self,ref,instance):
pass #iterate throught the fps and get the most sane one
Expand All @@ -646,8 +661,6 @@ def saveTo(self,targetFile):
self.commandReencodeMP4Eloquent(targetFile)
elif self.conversionMode==self.MODE_TS:
self.processTS(targetFile)
#elif self.conversionMode==self.MODE_ROTATE:
# self.processRotationStuff(targetFile)
else:
with open(mergeFile,'w') as aFile:
aFile.write('ffconcat version 1.0\n')
Expand Down Expand Up @@ -696,7 +709,8 @@ def commandReencodeMP4Eloquent(self,targetFile):
cmdString.append("scale="+prim.width()+":"+prim.height())
cmdString.append(",setdar="+str(darMode.numerator)+"/"+str(darMode.denominator)+",")
cmdString.append("fps="+str(prim.fps())+",")
cmdString.append("rotate="+str(prim.rotation()))
rot = str(prim.rotation()) if self.autoRotate() else "0"
cmdString.append("rotate="+rot)
cmdString.append("[v")
cmdString.append(str(indx))
cmdString.append("]; ")
Expand Down Expand Up @@ -734,7 +748,7 @@ def processTS(self,targetFile):
tmpFiles.append(tempFile)
fnr+=1
srcFile =ca.src
if ca.rotation()!=0:
if ca.rotation()!=0 and self.autoRotate():
cmd=['ffmpeg', "-hide_banner", "-y",'-i',ca.src,"-vf","rotate=0",rotFile]
self._runCommand(cmd, "Rotate",self.timeCursor)#
srcFile=rotFile
Expand Down Expand Up @@ -896,6 +910,9 @@ def warn(self,text):
log.warning("Warning:%s",text)


def getAppIcon():
return QtGui.QIcon('icons/merge.png')

def excepthook(exc_type, exc_value, exc_tb):
tb = "".join(traceback.format_exception(exc_type, exc_value, exc_tb))
log.error("Application failure:\n %s", tb)
Expand Down Expand Up @@ -925,8 +942,11 @@ def parseOptions(args):
def main():
try:
sys.excepthook = excepthook
#setCurrentWorkingDirectory()
folder = OSTools().getLocalPath(__file__)
#find your files and icons:
OSTools().setMainWorkDir(folder)
app = QApplication(sys.argv)
app.setWindowIcon(getAppIcon())
res = parseOptions(sys.argv)
win = VideoMerge(res)

Expand Down

0 comments on commit 8ced7a8

Please sign in to comment.