Audiospuren aus Videodateien entfernen und hinzufügen – ffmpeg

Ich stand vor dem Problem, eine bearbeitete Audiodatei mit der ursprünglichen Audiospur einer Videodatei (mp4) auszutauschen. Da ich nur die Audiodatei verändert hatte, wollte ich nicht das Video neu kodieren und so Gefahr laufen, die Qualität zu verändern, oder unnötig die Videodatei zu vergrößern.

Im Prinzip ist es ganz einfach (unter Linux): ffmpeg

Was ist drin

Um den Inhalt einer Videodatei zu verändern, sollte erst geschaut werden, was da überhaupt drin ist. Das erledigt der Befehl:

ffprobe INPUTVIDEO.mp4

ffprobe ist ein Analyseproramm und bei ffmpeg standardmäßig mit dabei.

Entfernen

Das Entfernen einer oder mehrerer Audiospuren funktioniert mit folgendem Befehl

ffmpeg -i InputVideo.mp4 -map 0 -map -0:a:0 -codec copy OutputVideo_EINS.mp4
  • -map 0 wählt alle (Video/Audio) Spuren aus
  • -0:a:0 wählt aus allen Spuren die Audiospur Nummer 1 (Zählweise ab 0) aus
  • -codec copy definiert, dass keine Neukodierung stattfindet

Will man alle Audiospuren aus dem Video entfernen, so gilt abgekürzt

  • -0:a wählt alle Audiospuren aus

Zur Auswahl stehen nicht nur a (Audiospuren), sondern auch v (Videospuren), s (Sub-/Untertitel), d (Datenspuren).

Hinzufügen

Das Hinzufügen einer oder mehrerer Audiospuren (zum vorherigen Beispiel) funktioniert mit folgendem Befehl

ffmpeg -i OutputVideo_EINS.mp4 -i Audiospur.m4a -codec copy -shortest OutputVideo_ZWEI.mp4
  • -i steuert, was in die Datei aufgenommen werden soll. Hier 1 Video- und 1 Audiospur
  • -codec copy definiert, dass keine Neukodierung stattfindet
  • -shortest kürzt alles auf die Länge der Datei mit der kürzesten Dauer

Zweite Spur hinzufügen

Wenn eine zweite Spur hinzugefügt werden muss, dann sollte darauf geachtet werden, dass die zweite Spur genau gleich lang ist, wie die erste Spur!

ffmpeg -i INPUTVIDEO.mp4 -i INPUTAUDIO.aac -map 0 -map 1 -metadata:s:a:1 title="MEIN TITEL DER AUDIOSPUR" -codec copy OUTPUTVIDEO.mp4

Extrahieren

Das Extrahieren einer Audiospur im Originalformat funktioniert folgendermaßen

ffprobe Name_der_Video_Datei

Als Ausgabe erhält man eine lange Ausgabe und zum Schluss findet man so etwas in dieser Art

Input #0, matroska,webm, from 'MeinVideo.webm':
Metadata:
ENCODER : Lavf58.20.100
Duration: 03:59:10.04, start: -0.007000, bitrate: 2285 kb/s
Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, bt709), 3840x2160, SAR 1:1 DAR 16:9, 59.94 fps, 59.94 tbr, 1k tbn, 1k tbc (default)
Metadata:
DURATION : 03:59:10.019000000
Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Metadata:
DURATION : 03:59:10.041000000

In diesem Falle handelt es sich bei Stream #0:1 Audio: opus um ein Ogg Vorbis Audio, das man in ein .ogg oder .oga abspeichern kann mit folgendem Befehl

ffmpeg -i MeinVideo.webm -map 0:a:0 -c copy MeinAudio.oga

In diesem Fall wird einfach die Audiodatei ohne ein neues konvertieren aus der Videodatei herauskopiert und liegt dann als MeinAudio.oga im Dateisystem.

Extrahieren und Konvertieren

Das Extrahieren und Konvertieren einer Audiospur in ein anderes Audioformat z.B. WAV geht sogar noch einfacher

ffmpeg -i MeinVideo.webm MeinAudio.wav

Bei komprimierten Audioformaten müssen natürlich noch ein paar mehr Parameter zur Steuerung der Qualität angegeben werden.

Open Source Voice Assistants

Siri, Duo, Alexa, Cortana oder wie sie alle heissen. Diese digitalen Assistenten, die immer einen Kanal zur Hersteller Cloud brauchen und über diesen Kanal auch immer mithören und das natürlich auch beim Hersteller verarbeiten. Warum tut man sich sowas an und stellt sich eine Wanze ins Eigenheim? Man muss schon einen gehörigen Schaden haben sich sowas in sein privates Zuhause zu stellen und auch noch Geld dafür zu bezahlen. Egal. Es gibt für sowas OpenSource Alternativen. Hier will ich einfach mal ein paar aufzählen

Kalliopehttps://kalliope-project.github.io/
Kalliope is a modular always-on voice controlled personal assistant designed for home automation. Kalliope can be installed on multiple linux system, and also on small single-board computers like the Raspberry Pi.

Mycrofthttps://mycroft.ai/
Mycroft is the world’s first open source assistant. Mycroft runs anywhere – on a desktop computer, inside an automobile, or on a Raspberry Pi. This is open source software which can be freely remixed, extended, and improved. Mycroft may be used in anything from a science project to an enterprise software application.

SUSIhttps://github.com/fossasia/susi_linux
This project aims at creating an implementation of Susi, capable to run on Linux Devices in a headless mode. It will enable you to bring Susi AI intelligence to all devices you may think like a Speaker, Car etc.

Jasperhttps://jasperproject.github.io/
Jasper is an open source platform for developing always-on, voice-controlled applications. Use your voice to ask for information, update social networks, control your home, and more. Jasper is always on, always listening for commands, and you can speak from meters away. Build it yourself with off-the-shelf hardware, and use our documentation to write your own modules.

Snipshttps://snips.ai/
Using Voice to Make Technology Disappear. Snips provides Private-By-Design, Decentralized Voice Assistant Technology and Solutions. Snips was built from scratch to protect your privacy. Everything runs directly on-device, meaning no one will ever hear your voice but you. This required over 4 years of research, during which our team pushed the limits of what can be done with AI on tiny devices. (Raspi)
Update 21.11.2019 : Sonos kauft französische Sprachassistenten-Firma Snips

Leonhttps://getleon.ai/
Leon is an open-source personal assistant who can live on your server. He does stuff when you ask him for. You can talk to him and he can talk to you. You can also text him and he can also text you. If you want to, Leon can communicate with you by being offline to protect your privacy.

Mozilla DeepSpeechhttps://github.com/mozilla/DeepSpeech
Project DeepSpeech is an open source Speech-To-Text engine, using a model trained by machine learning techniques, based on Baidu’s Deep Speech research paper. Project DeepSpeech uses Google’s TensorFlow project to make the implementation easier. Blogbeitrag „Mozilla stellt weltweit größten Sprach-Datensatz kostenlos zur Verfügung“

Almond https://almond.stanford.edu/
Almond is the open virtual assistant that you can access through your phone and the web. It helps you configure your devices, accounts, and public services, retrieve data from them, and execute actions on them. It also lets you share your data with your friends and families easily. Oh, by the way, it’s open source and it protects your privacy!

Vosk https://github.com/alphacep/vosk-api
Update 07.07.2021

Vosk is a speech recognition toolkit. Features:
Supports 18 languages and dialects – English, Indian English, German, French, Spanish, Portuguese, Chinese, Russian, Turkish, Vietnamese, Italian, Dutch, Catalan, Arabic, Greek, Farsi, Filipino, Ukrainian. More to come.
Works offline, even on lightweight devices – Raspberry Pi, Android, iOS
Installs with simple pip3 install vosk
Portable per-language models are only 50Mb each, but there are much bigger server models available.
Provides streaming API for the best user experience (unlike popular speech-recognition python packages)
There are bindings for different programming languages, too – java/csharp/javascript etc.
Allows quick reconfiguration of vocabulary for best accuracy.
Supports speaker identification beside simple speech recognition.

Github https://github.com/alphacep/vosk-api