• Slidy
  • Command-line cinema

    De Ustensile
    Aller à : navigation, rechercher

    Some Sources of copyleft materials online

    example: Fats Waller on archive.org


    Wget is a simple way to download things from the web. These can be webpages, videos, sounds -- basically anything that has a proper URL to access it (for youtube videos or other "closed" sources see youtube-dl)

    wget URL


    youtube-dl URL

    There are *many* interesting options with youtube-dl

    Show formats available:

    youtube-dl -F URL

    Download a particular format (using its numeric code)

    youtube-dl -f43 URL

    Download a video + the automatically generated subtitles!

    youtube-dl --write-auto-sub URL


    Basic key commands when playing a movie with mplayer

    SPACE: Pause/Play
    . : Forward one frame
    Left + Right : Jump
    9 0 : Volume
    [ ] : Speed
    o   : Toggle display mode (shows current time and duration)
    f   : Toggle fullscreen
    s   : Save current frame (with -vf screenshot, see Mplayer Snapshots)
    q   : Quit

    Time options

    Play from 10 seconds to 1 minute 6 seconds.

    mplayer -ss 10 -endpos 56

    Play from 01:10:30 - 01:11:00

    mplayer -ss 01:10:30 -endpos 30

    Extracting Frames from a Movie: Mplayer Snapshots

    mplayer -vf screenshot <source>

    Then while the movie is playing ... press the s key each time you want to save a frame. You should find files named like:


    Extracting Frames from a Movie: ffmpeg

    ffmpeg uses a "printf" style code for working with image sequences. They also look like "%04d" where the number (4 in this case) means how many numbers to use in total so for instance, "foo%04d.jpg" would produce filenames like:


    And a code like "%09d.png" would produce things like:


    To extract all of the frames of a video:

    ffmpeg -i <source> <destination%06d.jpg>
    ffmpeg -ss 12:00 -i <source> -vframes 100 <destination%04d.jpg>

    Timing (start + stop) can be controlled with -ss (skip start) and -t (total time of result)

    When -ss is before the -i ffmpeg attempts to JUMP which is fast only precise to the nearest key frame.

    Extract 3 seconds starting at (near) 05:47 and save as snip.mp4

    ffmpeg -ss 05:47 -i ten.mp4 -t 3 snip.mp4

    When you put -ss after the -i, the timing is more precise but it's slower as the movie is actually played (quickly) up to that precise point.

    Extract 3 seconds starting at (exactly) 05:47 and save as snip.mp4

    ffmpeg -i ten.mp4 -ss 05:47 -t 3 snip.mp4
    ffmpeg -ss 05:47 -i powersof10/ten.mp4 -vframes 10 snip%04d.jpg

    Starting at 05:47 output one frame every 5 seconds for 10 frames, save using names starting snip0001.jpg

    ffmpeg -ss 05:47 -i powersof10/ten.mp4 -r 1/5 -vframes 10 snip%04d.jpg

    Combine Image Sequence starting frames000001.jpg and the audio in soundtrack.wav, save result as result.mp4:

    ffmpeg -i frames%06d.jpg -i soundtrack.wav result.mp4


    ffmpeg -ri 10 -i frame%06d.jpg -i apologie.wav apologie.mp4

    To force ffmpeg to OVERWRITE any previously existing file (useful when inside a larger script that you want to run again and again) -- add the -y to AUTO-YES the question about replacing the output.

    ffmpeg -r 10 -i frame%06d.jpg -i apologie.wav -y apologie.mp4

    Frame to movie with ffmpeg

    If you have a set of sequentially numbered files (as generated from a %0nd pattern:

    ffmpeg -f image2 -i anim%04d.jpg -s 160x120 -y anim.ogv

    Or if the numbering isn't sequential (there are gaps), you can use a traditional "glob" (asterisk), NB the use of the single quotes is important (prevents bash from expanding the glob, leaving that work to ffmpeg itself):

    ffmpeg -f image2 -pattern_type glob -i 'anim*.png' -s 160x120 -y anim.ogv

    Extraction de sons

    ffmpeg -i <source> output.wav


    ffmpeg -i <source> output.mp3

    If you have a video and you want to simply separate the audio, without recompressing it (which is faster and doesn't change the quality / data), you can say something like:

    Copying just the ogg audio from a webm:

    ffmpeg -i mysource.webm -vn -c:a copy output.ogg

    Copying just the AAC audio from an MP4:

    ffmpeg -i mysource.mp4 -vn -c:a copy output.aac

    Padding audio

    Add 10 seconds to start and 30 seconds to end of input, save as output:

    sox input.wav output.wav pad 10 30

    Mixing audio

    with ffmpeg

    ffmpeg -i apologie.wav -i badmusic.wav -filter_complex amerge mix.mp3

    it uses the duration of the shortest file.

    you can also explicitly limit the number of audio channels with:

    ffmpeg -i apologie.wav -i badmusic.wav -filter_complex amerge -ac 1 mix.mp3

    Sequence (concatenate) audio / video

    For audio, you can use sox like this:

    sox a.wav b.wav c.wav output.wav

    For video, you can use mlt / melt .....

    melt a.mp4 b.mp4 c.mp4 -consumer avformat:output.mp4 b=1000k

    You can also use melt to combine still images as "inter-titles", the numbers with "out" are frames (so for output at 25 fps, 50 = 2 seconds):

    melt title2-0.png out=50 \
    video.mp4 \
    title2-1.png out=100 \
    -consumer avformat:output.mp4 b=1000k

    To do this with ffmpeg you need to make a sort of playlist file that looks like:

    Create a file called playlist.txt:

    file 'a.wav'
    file 'b.wav'
    file 'c.wav'

    Then the command to put the pieces together is:

    ffmpeg -f concat -i concat.txt concat.mp3

    See: https://trac.ffmpeg.org/wiki/Concatenate

    Text / Titles

    Imagemagick! http://www.imagemagick.org/Usage/text/

    convert -size 640x480 -gravity center -pointsize 72 -font CoupeurBoldBlock.otf -background lightblue -fill blue caption:'HEY what about a very long text then?' title.png

    with a newline:

    convert -size 640x480 -gravity center -pointsize 72 -font CoupeurBoldBlock.otf -background lightblue -fill blue caption:'HEY!what about a very long text then?' title.png

    What colors?

    convert -list color

    Random color!

    convert -list color | cut -d" " -f1 | shuf | head -n1

    There's also label:, but it doesn't do word wrap.

    convert -size 640x480 -gravity center -pointsize 72 -font ~/.fonts/coupeur-boldblock/CoupeurBoldBlock.otf -background lightblue -fill blue caption:'HEY what about a very long text then?' title.png</source>
    convert -size 640x480 -gravity center -pointsize 72 -font -background lightblue -fill blue label:'magic\nmagic!!!' whoami.png

    title with random colors:

    convert -size 640x480 -gravity center -pointsize 72 \
       -font ~/.fonts/coupeur-boldblock/CoupeurBoldBlock.otf \
       -background $(convert -list color | cut -d" " -f1 | shuf | head -n1) \
       -fill $(convert -list color | cut -d" " -f1 | shuf | head -n1) \
       label:'Surprise!!!' surprise.png


    c1=`shuf imcolornames.txt | head -n 1`
    c2=`shuf imcolornames.txt | head -n 1`
    convert -size 640x480 -background $c1 -fill $c2 -pointsize 72 -gravity center -f ont /home/murtaugh/.fonts/OSP_Libertinage/Libertinage-s.ttf label:Contemporaneit y contemporaneity.png

    NB: Using the @ sign with label to read from a file seems to be blocked (by some kind of security policy).... back quoting a file might work though?!