FFmpeg Grundlagen

Inhaltsübersicht

  • Einführung
  • Umpacken
  • Transcodieren
  • Bildformat ändern
  • A/V trennen
  • Ausschnitte

FFmpeg? Wosisdes?

Das FFmpeg-Projekt besteht aus einer Reihe von freien Computerprogrammen und Programmbibliotheken, die digitales Video- und Audiomaterial aufnehmen, konvertieren, senden (streamen) und in verschiedene Containerformate verpacken können.

Unter anderem enthält es mit libavcodec eine umfangreiche Sammlung von Audio- und Videocodecs.

 

Quelle: Wikipedia: FFmpeg

Wo kriegt man's her?

...vom "Bio-Bauernmarkt".
ffmpeg.org/download.html

Digital Video Trinity

Basis Syntax

ffmpeg [-y] -i INPUT_FILE [PARAMETER] [-f FORMAT] OUTPUT_FILE

FFmpeg, was kannst Du?

  • Liste Container: -formats
    File formats:
      D. = Demuxing supported
      .E = Muxing supported
          
  • Liste Codecs: -codecs / -encoder / -decoder
    Codecs:
      D..... = Decoding supported
      .E.... = Encoding supported
      ..V... = Video codec
      ..A... = Audio codec
      ..S... = Subtitle codec
      ...I.. = Intra frame-only codec
      ....L. = Lossy compression
      .....S = Lossless compression
          

Videofile: Was is drin?

ffmpeg -i INPUT_FILE -hide_banner
ffmpeg version 4.0.1-static https://johnvansickle.com/ffmpeg/
 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug
--disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6
--enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray
--enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf
--enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband
--enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus
--enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx
--enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2
--enable-libxvid --enable-libzimg
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-10-19T17:32:00.000000Z
  Duration: 00:00:12.05, start: 0.000000, bitrate: 16964 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661),
                      yuv420p, 1920x1080, 17011 kb/s,
                      30.02 fps, 30 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2016-10-19T17:32:00.000000Z
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D),
                      48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2016-10-19T17:32:00.000000Z
      handler_name    : SoundHandle
At least one output file must be specified

Umpacken

ffmpeg -i INPUT_FILE -c copy OUTPUT_FILE ffmpeg -i INPUT_FILE -c:v copy -c:a copy -map 0 OUTPUT_FILE

Codec

  • Videocodec: -c:v CODEC
  • Audiocodec: -c:a CODEC
  • A + V 1:1 kopieren: -c copy -map 0

Transcodieren

ffmpeg -i INPUT_FILE -c:v ffv1 -c:a pcm_s24le OUTPUT_FILE

ffmpeg -i INPUT_FILE -c:v ffv1 -c:a pcm_s16le OUTPUT_FILE

Video 1

  • Auflösung: -s WIDTHxHEIGHT
  • Seitenverhältnis: -aspect X:Y
  • Framerate: -r FPS

Bildformat ändern

ffmpeg -i INPUT_FILE -c:a copy -c:v ffv1 -s 720x576 OUTPUT_FILE

ffmpeg -i INPUT_FILE -c:a copy -c:v ffv1 -aspect 4:3 OUTPUT_FILE

ffmpeg -i INPUT_FILE -c:a copy -c:v ffv1 -r 30000/1001 OUTPUT_FILE

Video 2

  • Farbmodell/tiefe: -pix_fmt FORMAT

pix_fmt?

  • yuv422p = YUV 4:2:2 planar
  • yuv420p
  • yuv422p10le
  • yuv420p10le
  • yuva422p

  • Keep-or-die: -pix_fmt +
  • Liste: -pix_fmts

Subsampling ändern

ffmpeg -i INPUT_FILE -c:v ffv1 -pix_fmt yuv422p OUTPUT_FILE

(Achtung: re-encoding)

A/V separat

  • Video 'None': -vn
  • Audio 'None': -an

Audio

  • Audiocodec: -c:a CODEC
  • Samplerate: -ar SAMPLERATE
  • Kanäle: -ac CHANNELS
  • Bitrate: -b:a BITRATE{k,M}

A/V separat

  • Nur Bild (Original):
    ffmpeg -i INPUT_FILE -an -c:v copy OUTPUT_FILE
  • Nur Ton (Original):
    ffmpeg -i INPUT_FILE -vn -c:v copy OUTPUT_FILE
  • Nur Ton (MP3):
    ffmpeg -i INPUT_FILE -vn -c:a mp3 -b:a 128k out.mp3
  • Nur Ton (FLAC):
    ffmpeg -i INPUT_FILE -vn -c:a flac out.flac

Video 3

  • Bitrate: -b:v BITRATE{k,M}
  • Bitrate (min): -minrate BITRATE
  • Bitrate (max): -maxrate BITRATE
  • GOP size: -g FRAMES

Video Ausschnitte

  • Startposition: -ss DURATION
  • Rückwärts: -sseof DURATION
  • Länge: -t DURATION

 

DURATION:
Timecode: [-][HH:]MM:SS[.m]
oder
Sekunden: [-]S[.m]

Video Ausschnitte

  • Start Offset:
    ffmpeg -ss DURATION -i INPUT_FILE -c copy OUTPUT_FILE
  • Nur Anfang:
    ffmpeg -t DURATION -i INPUT_FILE -c copy OUTPUT_FILE
  • Offset + Länge:
    ffmpeg -ss DURATION -t DURATION -i INPUT_FILE -c copy OUTPUT_FILE

Transcoding II

"MPEG-4" (H.264)

"x264 H.264/MPEG-4 AVC encoder wrapper. [...]
libx264 supports an impressive number of features, [...]"
  • Codec: -c:v libx264
  • Bitrate: -b:v BITRATE{k,M}
  • CRF: -crf 0 (lossless) - 51 (worst)
  • Presets: -preset:v {ultrafast,superfast,veryfast,faster,fast,medium(*),slow,slower,veryslow}
  • Feintuning: -tune {film,animation,grain,...}

 

Quellen/Links: FFmpeg Wiki, FFmpeg docs

"Ein MPEG-4 bitte."

(H.264 / AAC in MP4)

ffmpeg -i INPUT_FILE -c:v libx264 -preset:v superfast -crf 22 -c:a aac -b:a 192k OUT.mp4

Haltbarkeit?

In a nutshell

  • Gebranntes (CD/DVD/BluRay): Nix gut.
  • HDD im Kastl: Nix gut.
  • Container verlustfrei (!) umpacken.
  • Generationsverluste vermeiden.
  • Audio: PCM
  • Lossless falls möglich (FFV1).
  • Offene Formate! (+ git clone FFmpeg)
  • Hashcodes. MD5 reicht.
  • Backup-Kopien.

Links

License and Credits

Der Text dieser Präsentation steht unter einer freien Lizenz zur Verfügung:

Creative Commons "Attribution-ShareAlike"
(CC-BY-SA)

Peter Bubestinger-Steindl
pb@fsfe.org