gen_testmedia.sh (4833B)
1 #!/bin/sh 2 # This file is in the public domain. 3 # 4 # Regenerate the media files that the video thumbnail and audio preview 5 # plugins are tested against. They are checked into the repository (and 6 # shipped in the tarball), so you only need this if you want to change 7 # them -- or if you want to convince yourself that they really are 8 # synthetic and carry nobody's copyright. 9 # 10 # Everything here comes out of FFmpeg's lavfi test sources (solid colours, 11 # a box, a sine wave), so the result is not derived from any third party 12 # work. The files are dedicated to the public domain (CC0); see 13 # src/plugins/testdata/README.media. 14 # 15 # Usage: contrib/gen_testmedia.sh [output-directory] 16 set -e 17 18 OUT="${1:-src/plugins/testdata}" 19 FFMPEG="${FFMPEG:-ffmpeg}" 20 21 if ! command -v "$FFMPEG" > /dev/null 2>&1; then 22 echo "$0: $FFMPEG not found" >&2 23 exit 1 24 fi 25 26 # The video changes colour 20s in, and the thumbnailers are expected to 27 # sample around 30s, so a thumbnail of the wrong moment is a thumbnail of 28 # the wrong colour and the test notices. The white box keeps the frames 29 # from being perfectly flat, which the thumbnailers deliberately skip. 30 $FFMPEG -hide_banner -loglevel error -y \ 31 -f lavfi -i "color=c=black:s=160x120:r=5:d=20,drawbox=x=10:y=10:w=24:h=24:color=white:t=fill" \ 32 -f lavfi -i "color=c=red:s=160x120:r=5:d=70,drawbox=x=116:y=76:w=24:h=24:color=white:t=fill" \ 33 -filter_complex "[0:v][1:v]concat=n=2:v=1:a=0[v]" \ 34 -map "[v]" -c:v libtheora -q:v 3 \ 35 "$OUT/thumbnail_pattern.ogv" 36 37 # A 30s tone that changes pitch halfway through, so that a preview taken 38 # from the wrong place is at least in principle detectable. 8kHz mono is 39 # plenty for something that gets re-encoded at 24 kbps. 40 $FFMPEG -hide_banner -loglevel error -y \ 41 -f lavfi -i "sine=f=440:d=15:r=8000" \ 42 -f lavfi -i "sine=f=880:d=15:r=8000" \ 43 -filter_complex "[0:a][1:a]concat=n=2:v=0:a=1[a]" \ 44 -map "[a]" -c:a libvorbis -q:a -2 -ac 1 \ 45 "$OUT/preview_tone.ogg" 46 47 # The same audio in a file that also has a video stream, so that the 48 # preview plugins are exercised on a video container too. 49 $FFMPEG -hide_banner -loglevel error -y \ 50 -f lavfi -i "color=c=black:s=160x120:r=5:d=10,drawbox=x=10:y=10:w=24:h=24:color=white:t=fill" \ 51 -f lavfi -i "color=c=red:s=160x120:r=5:d=20,drawbox=x=116:y=76:w=24:h=24:color=white:t=fill" \ 52 -f lavfi -i "sine=f=440:d=15:r=8000" \ 53 -f lavfi -i "sine=f=880:d=15:r=8000" \ 54 -filter_complex "[0:v][1:v]concat=n=2:v=1:a=0[v];[2:a][3:a]concat=n=2:v=0:a=1[a]" \ 55 -map "[v]" -map "[a]" -c:v libtheora -q:v 3 -c:a libvorbis -q:a -2 -ac 1 \ 56 "$OUT/preview_tone.ogv" 57 58 # A 16:9 video with three text subtitle tracks (English and German as 59 # SubRip, French as ASS) for the "srt:LANG" option, and flat stretches 60 # for the "gallery:N" option: with gallery:4 the tiles are sampled at 61 # 5s (black -> must be shifted), 15s (red), 25s (white -> must be 62 # shifted) and 35s (blue). 63 TMP=$(mktemp -d) 64 trap 'rm -rf "$TMP"' EXIT 65 cat > "$TMP/en.srt" << 'EOSRT' 66 1 67 00:00:01,000 --> 00:00:04,000 68 Hello, world! 69 70 2 71 00:00:12,500 --> 00:00:15,250 72 This is the second line 73 spanning two rows. 74 75 3 76 00:00:33,000 --> 00:00:38,000 77 Goodbye. 78 EOSRT 79 cat > "$TMP/de.srt" << 'EOSRT' 80 1 81 00:00:01,000 --> 00:00:04,000 82 Grüß Gott, Welt! 83 84 2 85 00:00:12,500 --> 00:00:15,250 86 Das ist die zweite Zeile 87 über zwei Reihen. 88 89 3 90 00:00:33,000 --> 00:00:38,000 91 Auf Wiedersehen. 92 EOSRT 93 cat > "$TMP/fr.ass" << 'EOASS' 94 [Script Info] 95 ScriptType: v4.00+ 96 PlayResX: 160 97 PlayResY: 90 98 99 [V4+ Styles] 100 Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding 101 Style: Default,Arial,12,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,1 102 103 [Events] 104 Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text 105 Dialogue: 0,0:00:01.00,0:00:04.00,Default,,0,0,0,,Bonjour, {\i1}le monde{\i0} ! 106 Dialogue: 0,0:00:12.50,0:00:15.25,Default,,0,0,0,,Deuxième ligne\Nsur deux rangs. 107 EOASS 108 $FFMPEG -hide_banner -loglevel error -y \ 109 -f lavfi -i "color=c=black:s=160x90:r=5:d=6" \ 110 -f lavfi -i "color=c=red:s=160x90:r=5:d=14,drawbox=x=10:y=10:w=24:h=24:color=white:t=fill" \ 111 -f lavfi -i "color=c=white:s=160x90:r=5:d=6" \ 112 -f lavfi -i "color=c=blue:s=160x90:r=5:d=14,drawbox=x=116:y=56:w=24:h=24:color=yellow:t=fill" \ 113 -i "$TMP/en.srt" -i "$TMP/de.srt" -i "$TMP/fr.ass" \ 114 -filter_complex "[0:v][1:v][2:v][3:v]concat=n=4:v=1:a=0[v]" \ 115 -map "[v]" -map 4 -map 5 -map 6 \ 116 -c:v libtheora -q:v 3 -g 10 -c:s:0 srt -c:s:1 srt -c:s:2 ass \ 117 -metadata:s:s:0 language=eng -metadata:s:s:1 language=ger \ 118 -metadata:s:s:2 language=fre \ 119 "$OUT/subtitles.mkv" 120 121 ls -l "$OUT/subtitles.mkv" "$OUT/thumbnail_pattern.ogv" "$OUT/preview_tone.ogg" "$OUT/preview_tone.ogv"