Inhaltsverzeichnis
Videos Encodieren
Manche Videos lassen sich nicht abspielen wegen Codec Warnung, daher muss man manche Videos umwandeln wenn man keine Codecs installieren mag. Dies gelang gut mit HandBrake
. Dort hatte ich ein .mp4 Video geladen welches sich nicht unter VLC abspielen ließ(hat Codecs vermisst) Mit Handbrake konnte ich es in .webm Format umwandeln und nun läuft es überall. Es ist dabei aber auch größer geworden von 20 MB auf 40 MB gewachsen.
Im weiteren Schritt ließ es sich nun auch mit ffmpeg
bearbeiten. Es ging mir darum die Zeitdauer des Videos zu minimieren.
Videos reparieren
The idea is to strip off the first 44 bytes of the header, for instance with a hex editor or using dd
from CoreUtils
and then to rebuild an ADTS stream from the stripped file using faad
.
dd ibs=1 skip=44 if='your broken file.m4a' of=raw.aac faad -a adts.aac raw.aac
mplayer mencoder
Man kann versuchen die defekte Video-Datei mit mencoder
umzuwandeln und so evtl. zu reparieren:
mencoder -forceidx -oac pcm -ovc copy corruptvideo.mp4 -o fixedvideo.avi
Springt zu 56. Sekunde
mencoder -ss 56
Verschiedene Optionen an mplayer
übergeben um das defekte Video dennoch irgendwie abzuspielen.
You can use the scale filer as an output option to tell ffmpeg to scale your images. This allows you to keep the input images at their original size. Examples:
-vf scale=1280:828 -vf scale=1280:-1
These two scale examples would both resize your 1700×1100 input to 1280×828. The -1 tells ffmpeg to scale the height automatically while keeping the aspect ratio. With your input size and the requested 1280 output width the height would end up being 828.
mplayer -nosound -vf scale=1024:576 20150502_006.mp4 mplayer -nosound -vo x11 -screenw 1920 -screenh 1088 20150502_006.mp4
Forced video codec: ffh264vdpau
mplayer -vo vdpau -vc ffh264vdpau 'So Live.avi'
ffmpeg
Das Video zu einer niedrigeren Auflösung encodieren. Oder mit ffmpeg zu einem anderen Format umwandeln:
ffmpeg -i "So Live.avi" -qscale 4 So_Live.mp4
ffmpeg -i "So Live.avi" -acodec copy -vcodec copy So_Live.avi
Hiermit wird das Video richtig klein, indem die Framsize verkleiner wird. Von 40 MB auf 5 MB verkleinert.
ffmpeg -i The\ Run\ of\ the\ Golden\ Bull.webm -vf "scale=iw/2:ih/2" half_the_frame_size.mkv
oder
ffmpeg -i input.mkv -vf "scale=iw/3:ih/3" a_third_the_frame_size.mkv
Nur die ersten 30 Sekunden eines Videos in eine neue Datei speichern
ffmpeg -i originalfilm.mkv -t 00:00:30 TheRunoftheGoldenBull.mkv
Da der obige Kommando sehr lange dauerte, ohne sichtbare Qualitätsunterschiede, habe ich den folgenden Kommando genommen der wesentlich schneller ist:
ffmpeg -i originalfilm.mkv -t 00:00:30 -c copy TheRunoftheGoldenBull_30s.mkv
Aus der Mitte eines Videos einen bestimmten Bereich wählen. Hier ab der 11. Sekunde und ab da 31 Sekunden weiter.
ffmpeg -ss 00:00:11 -i originalfilm.mkv -t 31 -c copy supershort01.mkv
Video beschleunigen
ffmpeg -i 20210112_15171777.mp4 -filter:v "setpts=0.5*PTS" output_fast.mp4
Video verlangsamen
ffmpeg -i 20210112_15171777.mp4 -filter:v "setpts=2.0*PTS" output_slow.mp4
Zwei einzelne Video Dateien zusammenfügen. Hierzu müssen die beiden oder mehrere Dateien untereinander in einer Text Datei eingetragen werden:
cat files.txt file '20210112_video01.mp4' file '20210112_video02.mp4'
Anschließend beginnt das zusammensetzen der Dateien mit ffmpeg
ffmpeg -f concat -safe 0 -i files.txt -c copy output.mp4
Audio, Musik, Ton aus einer Musik-Datei zu einem Video hinzufügen
ffmpeg -i ronnimachtsport01.mp4 -i music.m4a -map 0:v -map 1:a -c:v copy -shortest output_mit_musik.mp4
Untrunc
oder eine verbesserte Version:
Es wir neben der defekten Videodatei noch eine funktionierende Datei benötigt welche vom gleichen Gerät erstellt worden ist wie die defekte.
Zusätzlich werden noch benötigte Libraries mit apt
oder zypper
installiert:
sudo apt install libavformat-dev libavcodec-dev libavutil-dev
Unter Suse benötigte ich noch das Paket zlib-devel
zypper in zlib-devel
Dann untrunc
nach der README kompilieren und installieren.
Die Verwendung von untrunc
geschieht durch den Aufruf des Programms mit benötigten Optionen -s
- step through unknown sequences und optional -v
damit ausführliche Informationen ausgeben werden. Anschließend wird eine funktionierende Videodatei und die defekten Videodatei übergeben.
./untrunc -v -s ../../Videos/20150514_001.mp4 ../20150502_006_defekt.mp4
Video und Bild Aufnahme
Mit hilfe gängiger Programme wie Mplay, mpv und Vlc
Video aufnehmen
If you want to record continuous video:
mencoder tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0:forceaudio:adevice=/dev/dsp -ovc lavc -oac mp3lame -lameopts cbr:br=64:mode=3 -o filename.avi
Press Ctrl+c to end the recording.
Unter Debian, openSuse und weiteren zu finden
guvcview | GTK+ UVC Viewer and Capturer | Paket
Screenshots von WebCam
MPlayer
To use MPlayer to take snapshots from your webcam run this command from the terminal:
mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0 -fps 15 -vf screenshot
From here you have to press s to take the snapshot. The snapshot will be saved in your current folder as shotXXXX.png.
MPV
Unter Raspberry mit OSMC bietet sich das Programm mpv
an, da mencoder
nicht existiert. Außerdem sollte man beim Raspberry 1 avi
als Dateiformat wählen, da mpv
anhand der Endung automatisch den dazugehörigen Codec erkennt und avi
am Performantesten läuft aber zwar miese Qualität bietet. Als Endung mp4, würde ein qualitative hohe Auflösung liefern aber sehr stark ruckeln.
mpv av://video4linux2:/dev/video0 --o NameVideodatei.avi
Spezieller Raspberry Schalter in mpv
--hwdec=<api> Specify the hardware video decoding API that should be used if possible. Whether hardware decoding is actually done depends on the video codec. If hardware decoding is not possible, mpv will fall back on software decoding. <api> can be one of the following: no always use software decoding (default) auto see below vdpau requires --vo=vdpau or --vo=opengl (Linux only) vaapi requires --vo=opengl or --vo=vaapi (Linux only) vaapi-copy copies video back into system RAM (Linux with Intel GPUs only) videotoolbox requires --vo=opengl (OS X 10.8 and up only) dxva2-copy copies video back to system RAM (Windows only) rpi requires --vo=rpi (Raspberry Pi only - default if available) auto tries to automatically enable hardware decoding using the first available method. This still depends what VO you are using. For example, if you are not using --vo=vdpau or --vo=opengl, vdpau decoding will never be enabled. Also note that if the first found method doesn't actually work, it will always fall back to software decoding, instead of trying the next method (might matter on some Linux systems).
VLC
VLC can also be used to view and record your webcam. In VLC's file menu, open the 'Capture Device…' dialog and enter the video and audio device files. Or from the command line, do:
vlc v4l:// :v4l-vdev="/dev/video0" :v4l-adev="/dev/audio2"
This will make VLC mirror your webcam. To take stills, simply choose 'Snapshot' in the 'Video' menu. To record the stream, you add a –sout argument, e.g.
vlc v4l:// :v4l-vdev="/dev/video0" :v4l-adev="/dev/audio2" --sout "#transcode{vcodec=mp1v,vb=1024,scale=1,acodec=mpga,ab=192,channels=2}:duplicate{dst=std{access=file,mux=mpeg1,dst=/tmp/test.mpg}}"
Kein Ton, Optionen habe ich leicht geändert am 25.12.2018
cvlc v4l:// :v4l-vdev="/dev/video0" :v4l-adev="/dev/video0" --sout "#transcode{vcodec=h264,vb=1024,scale=1,acodec=mpga,ab=192,channels=2}:duplicate{dst=std{access=file,mux=mpeg1,dst=/tmp/test.mpg}}"
Für Raspberry mit OSMC optimiert
cvlc v4l:// :v4l-vdev="/dev/video0" :v4l-adev="/dev/audio2" --sout "#transcode{vcodec=mp4v,vb=1024,scale=1,acodec=mpga,ab=192,channels=2mux=mpeg1,dst=/tmp/test2.mpg}}"