/usr/bin/anytovcd.sh is in mjpegtools 1:1.9.0-0.5ubuntu7.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 | #!/bin/sh
#
# anytovcd.sh
#
# Copyright (C) 2004,2005 Nicolas Boos <nicolaxx@free.fr>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
AUD_TRACK="1"
VOLUMES="1"
PREFIX_OUT="out"
VCD_TYPE="dvd"
DEC_TOOL="ffmpeg"
ENC_TOOL="mpeg2enc"
MATRICES="tmpgenc"
QUALITY="best"
CQMFILE="matrices.txt"
STATFILE="statfile.log"
BFR="bfr"
FFMPEG="ffmpeg"
MPEG2DEC="mpeg2dec"
MPEG2ENC="mpeg2enc"
MPLEX="mplex"
PGMTOY4M="pgmtoy4m"
SOX="sox"
TCCAT="tccat"
TCDEMUX="tcdemux"
TCPROBE="tcprobe"
TCREQUANT="tcrequant"
Y4MDENOISE="y4mdenoise"
Y4MSCALER="y4mscaler"
Y4MSPATIALFILTER="y4mspatialfilter"
Y4MUNSHARP="y4munsharp"
YUVDENOISE="yuvdenoise"
YUVFPS="yuvfps"
YUVMEDIANFILTER="yuvmedianfilter"
SCRIPT_NAME="anytovcd.sh"
SCRIPT_VERSION="13"
# custom quant. matrices
INTRA_KVCD="8,9,12,22,26,27,29,34,9,10,14,26,27,29,34,37,12,14,18,27,29,34,37,38,22,26,27,31,36,37,38,40,26,27,29,36,39,38,40,48,27,29,34,37,38,40,48,58,29,34,37,38,40,48,58,69,34,37,38,40,48,58,69,79"
INTER_KVCD="16,18,20,22,24,26,28,30,18,20,22,24,26,28,30,32,20,22,24,26,28,30,32,34,22,24,26,30,32,32,34,36,24,26,28,32,34,34,36,38,26,28,30,32,34,36,38,40,28,30,32,34,36,38,42,42,30,32,34,36,38,40,42,44"
INTRA_MVCD="8,10,16,20,25,28,33,44,10,10,14,26,27,29,34,47,16,14,18,27,29,34,37,48,20,26,27,31,36,37,38,50,25,27,29,32,37,40,48,58,28,33,36,42,45,50,58,68,33,37,39,44,48,56,66,79,37,39,45,48,56,66,79,83"
INTER_MVCD="16,18,20,22,23,27,32,40,18,20,22,24,26,32,36,42,20,22,24,26,33,38,42,44,22,24,26,34,38,42,44,46,23,26,33,38,42,44,46,48,27,32,38,42,44,46,48,50,32,36,42,44,46,48,50,52,40,42,44,46,48,50,52,58"
INTRA_TMPGENC="8,16,19,22,26,27,29,34,16,16,22,24,27,29,34,37,19,22,26,27,29,34,34,38,22,22,26,27,29,34,37,40,22,26,27,29,32,35,40,48,26,27,29,32,35,40,40,58,26,27,29,34,38,46,56,69,27,29,35,38,46,56,69,83"
INTER_TMPGENC="16,17,18,19,20,21,22,23,17,18,19,20,21,22,23,24,18,19,20,21,22,23,24,25,19,20,21,22,23,24,26,27,20,21,22,23,25,26,27,28,21,22,23,24,26,27,28,30,22,23,24,26,27,28,30,31,23,24,25,27,28,30,31,33"
matrix_copy ()
{
# TODO: find less ugly func.
echo "`echo "$1" | \
awk -F, '{for (i=1; i<=NF; i++) {n=n$i","; z+=1; if (i==64) {z=0; sub(",$","",n)}; if (z==8) {z=0; n=n"\n"}}; print n}'`"
}
range_check ()
{
# if input value < min. value
if test "$1" -lt "$2"; then
# = min. value
echo "$2"
# if input value > max. value
elif test "$1" -gt "$3"; then
# = max. value
echo "$3"
else
echo "$1"
fi
}
show_help ()
{
echo "-a audio_track audio track number (default = \"1\")"
echo "-A N:D force input pixel aspect ratio"
echo "-b blind mode (no video)"
echo "-c enable audio pass-through"
echo "-d tool_name video decoder tool"
echo " avail. : ffmpeg (default) or mpeg2dec"
echo "-D deinterlace video (ffmpeg decoder only)"
echo "-e tool_name video encoder tool"
echo " avail. : mpeg2enc (default) or ffmpeg (experimental)"
echo "-i filename input file"
echo "-I flag_name force input ilace flag"
echo " avail. : none, top_first and bottom_first"
echo "-J flag_name force output ilace flag (if possible)"
echo " avail. : none, top_first and bottom_first"
echo "-f filter1[:filter1_level][,filter2:[filter2_level]]... video filter(s)"
echo " avail. filters :"
echo " - hqdenoise (y4mdenoise)"
echo " - mean (yuvmedianfilter -f)"
echo " - median (yuvmedianfilter)"
echo " - spatial (y4mspatialfilter)"
echo " - temporal (yuvdenoise)"
echo " - unsharp (y4munsharp)"
echo " avail. levels :"
echo " - light (for low noise source)"
echo " - medium (for middle noise)"
echo " - heavy (for high noise)"
echo "-m mute mode (no audio) "
echo "-n norm output norm in case of input with non-standard framerate "
echo " avail. norms : pal (default), ntsc or ntsc_film"
echo "-o filename output files prefix (default = \"out\")"
echo "-p preset_name output type (default = dvd)"
echo " avail. : cvd, cvd_wide, dvd, dvd_wide, mvcd, svcd and vcd"
echo "-q level quality (default = best)"
echo " avail. : best, good, fair"
echo "-r enable two passes encoding mode"
echo "-R N:D force input framerate"
echo "-T length force input length (minutes)"
echo "-v show script version"
echo "-V number of volumes (default = \"1\")"
}
show_error ()
{
echo "**ERROR: [${SCRIPT_NAME}] $1"
}
show_info ()
{
echo " INFO: [${SCRIPT_NAME}] $1"
}
show_warn ()
{
echo "++ WARN: [${SCRIPT_NAME}] $1"
}
test_bin ()
{
if ! which ${1} >/dev/null; then
show_error "${1} binary not present."
exit 2
fi
}
for BIN in ${FFMPEG} ${PGMTOY4M}; do
test_bin ${BIN}
done
while getopts a:A:bcd:De:f:hi:I:J:mn:o:p:q:rR:T:vV: OPT
do
case ${OPT} in
a) AUD_TRACK="${OPTARG}";;
A) VID_SAR_SRC="${OPTARG}";;
b) BLIND_MODE="1";;
c) ACOPY_MODE="1";;
d) DEC_TOOL="${OPTARG}";;
D) DEINT_MODE="1";;
e) ENC_TOOL="${OPTARG}";;
h) show_help;
exit 0;;
i) VIDEO_SRC="${OPTARG}"; AUDIO_SRC="${VIDEO_SRC}";;
I) INTERLACING="${OPTARG}";;
J) INTERLACING_OUT="${OPTARG}";;
f) FILTERS_CHAIN="${OPTARG}";;
m) MUTE_MODE="1";;
n) OUT_NORM="${OPTARG}";;
o) PREFIX_OUT="${OPTARG}";;
p) VCD_TYPE="${OPTARG}";;
q) QUALITY="${OPTARG}";;
# r) ENC_TYPE="abr";;
r) REQUANT_MODE="1";;
R) VID_FPS_SRC="${OPTARG}";;
T) DURATION="${OPTARG}";;
v) echo "${SCRIPT_NAME} version ${SCRIPT_VERSION}"; exit 0;;
V) VOLUMES="${OPTARG}";;
\?) show_error "Unknown or uncomplete command line option.";
show_error "Use -h to get help.";
exit 2;;
esac
done
if test "${VIDEO_SRC}" = "" || ! test -r "${VIDEO_SRC}"; then
show_error "input file not specified or not present."
show_error "Use -h to get help."
exit 2
fi
FFMPEG_VERSION="`${FFMPEG} 2>&1 | awk '$4 == "build" {print $5}' | sed s/,// | head -1`"
AUD_TRACK="`range_check ${AUD_TRACK} 1 99`"
FFMPEG_AUD_TRACK="`${FFMPEG} -i \"${AUDIO_SRC}\" 2>&1 | awk '/Audio:/ {sub("^#","",$2); print $2}' | awk -F[ '{print $1}' | head -${AUD_TRACK} | tail -1`"
AUD_BITRATE_SRC="`${FFMPEG} -i "${AUDIO_SRC}" 2>&1 | awk '/Audio:/ {print $8}' | head -${AUD_TRACK} | tail -1`"
AUD_FMT_SRC="`${FFMPEG} -i "${AUDIO_SRC}" 2>&1 | awk '/Audio:/ {print $4}' | sed s/,// | head -${AUD_TRACK} | tail -1`"
AUD_FREQ_SRC="`${FFMPEG} -i "${AUDIO_SRC}" 2>&1 | awk '/Audio:/ {print $5}' | sed s/,// | head -${AUD_TRACK} | tail -1`"
Y4M_HEADER="`${FFMPEG} -i "${VIDEO_SRC}" -f yuv4mpegpipe -pix_fmt yuv420p -t 1 -y /dev/stdout 2>/dev/null | head -1`"
VID_FMT_SRC="`${FFMPEG} -i "${VIDEO_SRC}" 2>&1 | awk '/Video:/ {print $4}' | sed s/,// | head -1`"
VID_WIDTH_SRC="`echo ${Y4M_HEADER} | awk '{print $2}' | sed s/W//`"
VID_HEIGHT_SRC="`echo ${Y4M_HEADER} | awk '{print $3}' | sed s/H//`"
VID_SIZE_SRC="${VID_WIDTH_SRC}x${VID_HEIGHT_SRC}"
FF_DEC="${FFMPEG} -i \"${VIDEO_SRC}\""
FF_DEC_AFLAGS="-map ${FFMPEG_AUD_TRACK} -i \"${AUDIO_SRC}\""
# video deinterlacing
if test "${DEC_TOOL}" = "ffmpeg" && test "${DEINT_MODE}" = "1"; then
INTERLACING="none"
FF_DEC="${FF_DEC} -deinterlace"
fi
# input interlacing
if test "${INTERLACING}" = "none"; then
VID_ILACE_SRC="p"
elif test "${INTERLACING}" = "top_first"; then
VID_ILACE_SRC="t"
elif test "${INTERLACING}" = "bottom_first"; then
VID_ILACE_SRC="b"
else
VID_ILACE_SRC="`echo ${Y4M_HEADER} | awk '{print $5}' | cut -c 2-`"
fi
# output interlacing
if test "${INTERLACING_OUT}" = "none"; then
VID_ILACE_OUT="p"
elif test "${INTERLACING_OUT}" = "top_first"; then
VID_ILACE_OUT="t"
elif test "${INTERLACING_OUT}" = "bottom_first"; then
VID_ILACE_OUT="b"
else
VID_ILACE_OUT="${VID_ILACE_SRC}"
fi
# input framerate
if test "${VID_FPS_SRC}" = ""; then
VID_FPS_SRC="`echo ${Y4M_HEADER} | awk '{print $4}' | cut -c 2-`"
fi
# input pixel/sample aspect ratio
if test "${VID_SAR_SRC}" = ""; then
VID_SAR_SRC="`echo ${Y4M_HEADER} | awk '{print $6}' | cut -c 2-`"
fi
VID_SAR_N_SRC="`echo ${VID_SAR_SRC} | cut -d: -f1`"
VID_SAR_D_SRC="`echo ${VID_SAR_SRC} | cut -d: -f2`"
if test "${VID_SAR_N_SRC}" = "0" || test "${VID_SAR_D_SRC}" = "0"; then
show_warn "Unknown pixel aspect ratio, defaulting to 1:1"
VID_SAR_SRC="1:1"
fi
FF_ENC="${FFMPEG} -v 0 -f yuv4mpegpipe -i /dev/stdin -bf 2"
MPEG2ENC="${MPEG2ENC} -v 0 -M 0 -R 2 -s -2 1 -E -5"
MPLEX_FLAGS="-v 1"
PGMTOY4M="${PGMTOY4M} -r ${VID_FPS_SRC} -i ${VID_ILACE_SRC} -a ${VID_SAR_SRC}"
Y4MSCALER_FLAGS="-v 0 -S option=cubicCR -O infer=exact"
# ffmpeg decoder version
if test "${FFMPEG_VERSION}" -ge "4731"; then
FF_DEC="${FF_DEC} -f image2pipe -vcodec pgmyuv"
else
FF_DEC="${FF_DEC} -f imagepipe -img pgmyuv"
fi
# quality presets
if test "${QUALITY}" = "best"; then
QUANT="4"
elif test "${QUALITY}" = "good"; then
QUANT="5"
elif test "${QUALITY}" = "fair"; then
QUANT="6"
else
show_error "the specified quality preset is inexistant."
show_error "Use -h to get help."
exit 2
fi
# profile(s)
if test "${VCD_TYPE}" = "cvd"; then
FF_ENC="${FF_ENC} -vcodec mpeg2video -f rawvideo -bufsize 224"
MPEG2ENC="${MPEG2ENC} -f 8"
VID_FMT_OUT="m2v"
VID_MINRATE_OUT="0"
VID_MAXRATE_OUT="7500"
VID_SAR_525_OUT="20:11"
VID_SAR_625_OUT="59:27"
VID_SIZE_525_OUT="352x480"
VID_SIZE_625_OUT="352x576"
AUD_FMT_OUT="ac3"
AUD_BITRATE_OUT="192"
AUD_FREQ_OUT="48000"
AUD_CHANNELS_OUT="2"
# default volume size in mbytes (m = 1000)
VOL_SIZE="4700"
MPLEX_FLAGS="${MPLEX_FLAGS} -f 8"
Y4MSCALER_FLAGS="${Y4MSCALER_FLAGS} -O preset=cvd"
elif test "${VCD_TYPE}" = "cvd_wide"; then
FF_ENC="${FF_ENC} -vcodec mpeg2video -f rawvideo -bufsize 224"
MPEG2ENC="${MPEG2ENC} -f 8"
VID_FMT_OUT="m2v"
VID_MINRATE_OUT="0"
VID_MAXRATE_OUT="7500"
VID_SAR_525_OUT="80:33"
VID_SAR_625_OUT="236:81"
VID_SIZE_525_OUT="352x480"
VID_SIZE_625_OUT="352x576"
AUD_FMT_OUT="ac3"
AUD_BITRATE_OUT="192"
AUD_FREQ_OUT="48000"
AUD_CHANNELS_OUT="2"
VOL_SIZE="4700"
MPLEX_FLAGS="${MPLEX_FLAGS} -f 8"
elif test "${VCD_TYPE}" = "dvd"; then
FF_ENC="${FF_ENC} -target dvd -f rawvideo -dc 10"
MPEG2ENC="${MPEG2ENC} -f 8 -D 10"
VID_FMT_OUT="m2v"
VID_MINRATE_OUT="0"
VID_MAXRATE_OUT="8000"
VID_SAR_525_OUT="10:11"
VID_SAR_625_OUT="59:54"
VID_SIZE_525_OUT="720x480"
VID_SIZE_625_OUT="720x576"
AUD_FMT_OUT="ac3"
AUD_BITRATE_OUT="192"
AUD_FREQ_OUT="48000"
AUD_CHANNELS_OUT="2"
VOL_SIZE="4700"
MPLEX_FLAGS="${MPLEX_FLAGS} -f 8"
Y4MSCALER_FLAGS="${Y4MSCALER_FLAGS} -O preset=dvd"
elif test "${VCD_TYPE}" = "dvd_wide"; then
FF_ENC="${FF_ENC} -target dvd -f rawvideo -dc 10"
MPEG2ENC="${MPEG2ENC} -f 8 -D 10"
VID_FMT_OUT="m2v"
VID_MINRATE_OUT="0"
VID_MAXRATE_OUT="8000"
VID_SAR_525_OUT="40:33"
VID_SAR_625_OUT="118:81"
VID_SIZE_525_OUT="720x480"
VID_SIZE_625_OUT="720x576"
AUD_FMT_OUT="ac3"
AUD_BITRATE_OUT="192"
AUD_FREQ_OUT="48000"
AUD_CHANNELS_OUT="2"
VOL_SIZE="4700"
MPLEX_FLAGS="${MPLEX_FLAGS} -f 8"
Y4MSCALER_FLAGS="${Y4MSCALER_FLAGS} -O preset=dvd_wide"
elif test "${VCD_TYPE}" = "mvcd"; then
FF_ENC="${FF_ENC} -vcodec mpeg1video -f rawvideo -bufsize 40 -me_range 64"
MPEG2ENC="${MPEG2ENC} -f 2 -g 12 -G 24 -B 256 -S 797"
MATRICES="mvcd"
VID_FMT_OUT="m1v"
VID_ILACE_OUT="p"
VID_MINRATE_OUT="0"
VID_MAXRATE_OUT="1152"
VID_SAR_525_OUT="10:11"
VID_SAR_625_OUT="59:54"
VID_SIZE_525_OUT="352x240"
VID_SIZE_625_OUT="352x288"
AUD_FMT_OUT="mp2"
AUD_BITRATE_OUT="128"
AUD_FREQ_OUT="44100"
AUD_CHANNELS_OUT="2"
# 360000 sectors * 2324 bytes per sector / 1000 / 1000
VOL_SIZE="836"
MPLEX_FLAGS="${MPLEX_FLAGS} -f 2 -r 1400 -V"
Y4MSCALER_FLAGS="${Y4MSCALER_FLAGS} -O preset=vcd"
elif test "${VCD_TYPE}" = "svcd"; then
FF_ENC="${FF_ENC} -target svcd -f rawvideo"
MPEG2ENC="${MPEG2ENC} -f 4 -B 256 -S 797"
VID_FMT_OUT="m2v"
VID_MINRATE_OUT="0"
VID_MAXRATE_OUT="2500"
VID_SAR_525_OUT="15:11"
VID_SAR_625_OUT="59:36"
VID_SIZE_525_OUT="480x480"
VID_SIZE_625_OUT="480x576"
AUD_FMT_OUT="mp2"
AUD_BITRATE_OUT="224"
AUD_FREQ_OUT="44100"
AUD_CHANNELS_OUT="2"
VOL_SIZE="836"
MPLEX_FLAGS="${MPLEX_FLAGS} -f 4"
Y4MSCALER_FLAGS="${Y4MSCALER_FLAGS} -O preset=svcd"
elif test "${VCD_TYPE}" = "vcd"; then
ENC_TYPE="cbr"
FF_ENC="${FF_ENC} -target vcd -f rawvideo -me_range 64"
MPEG2ENC="${MPEG2ENC} -f 1 -B 256 -S 797"
VID_FMT_OUT="m1v"
VID_ILACE_OUT="p"
VID_SAR_525_OUT="10:11"
VID_SAR_625_OUT="59:54"
VID_SIZE_525_OUT="352x240"
VID_SIZE_625_OUT="352x288"
AUD_FMT_OUT="mp2"
AUD_BITRATE_OUT="224"
AUD_FREQ_OUT="44100"
AUD_CHANNELS_OUT="2"
VOL_SIZE="836"
MPLEX_FLAGS="${MPLEX_FLAGS} -f 1"
Y4MSCALER_FLAGS="${Y4MSCALER_FLAGS} -O preset=vcd"
else
show_error "the specified output type/profile is inexistant."
show_error "Use -h to get help."
exit 2
fi
# audio pass-through
if test "${ACOPY_MODE}" = "1"; then
AUD_BITRATE_OUT="${AUD_BITRATE_SRC}"
AUD_FMT_OUT="${AUD_FMT_SRC}"
AUD_FREQ_OUT="${AUD_FREQ_SRC}"
fi
# output filenames
VIDEO_OUT="${PREFIX_OUT}.${VID_FMT_OUT}"
AUDIO_OUT="${PREFIX_OUT}.${AUD_FMT_OUT}"
MPEG_OUT="${PREFIX_OUT}-%d.mpg"
# output interlacing
if test "${VID_ILACE_OUT}" = "b"; then
FF_ENC="${FF_ENC} -ildct -ilme -top 0"
MPEG2ENC="${MPEG2ENC} -I 1 -z b"
elif test "${VID_ILACE_OUT}" = "t"; then
FF_ENC="${FF_ENC} -ildct -ilme -top 1"
MPEG2ENC="${MPEG2ENC} -I 1 -z t"
else
MPEG2ENC="${MPEG2ENC} -I 0"
fi
# output framerate
if test "${VID_FPS_SRC}" = "30000:1001" || test "${VID_FPS_SRC}" = "24000:1001" || test "${VID_FPS_SRC}" = "25:1"; then
VID_FPS_OUT="${VID_FPS_SRC}"
elif test "${OUT_NORM}" = "ntsc"; then
VID_FPS_OUT="30000:1001"
elif test "${OUT_NORM}" = "ntsc_film"; then
VID_FPS_OUT="24000:1001"
else
VID_FPS_OUT="25:1"
fi
# output sar and framesize for pal/ntsc
if test "${VID_FPS_OUT}" = "25:1"; then
VID_SAR_OUT="${VID_SAR_625_OUT}"
VID_SIZE_OUT="${VID_SIZE_625_OUT}"
else
VID_SAR_OUT="${VID_SAR_525_OUT}"
VID_SIZE_OUT="${VID_SIZE_525_OUT}"
fi
# cvd_wide "preset" for y4mscaler
if test "${VCD_TYPE}" = "cvd_wide"; then
Y4MSCALER="${Y4MSCALER} -O sar=${VID_SAR_OUT} -O size=${VID_SIZE_OUT}"
fi
# pipe buffer
if which ${BFR} >/dev/null; then
PIPE_BUFFER="${BFR} -b 16m |"
fi
# video decoder
if test "${DEC_TOOL}" = "mpeg2dec"; then
test_bin ${MPEG2DEC}
DECODER="${MPEG2DEC} -s -o pgmpipe \"${VIDEO_SRC}\" | ${PGMTOY4M} |"
elif test "${DEC_TOOL}" = "ffmpeg"; then
test_bin ${FFMPEG}
DECODER="${FF_DEC} -y /dev/stdout | ${PGMTOY4M} |"
else
show_error "the specified video decoder tool is not used by this script."
show_error "Use -h to get help."
exit 2
fi
# video framerate correction
if test "${VID_FPS_SRC}" = "${VID_FPS_OUT}"; then
FRC=""
else
test_bin ${YUVFPS}
FRC="${YUVFPS} -r ${VID_FPS_OUT} |"
fi
# video "deinterlacer"
if test "${VID_ILACE_SRC}" != "p" && test "${VID_ILACE_OUT}" = "p"; then
Y4MSCALER_FLAGS="${Y4MSCALER_FLAGS} -I ilace=top_only"
fi
# video scaler
if test "${VID_SAR_SRC}" = "${VID_SAR_OUT}" && test "${VID_SIZE_SRC}" = "${VID_SIZE_OUT}" && test "${VID_ILACE_SRC}" = "${VID_ILACE_OUT}"; then
SCALER=""
else
test_bin ${Y4MSCALER}
SCALER="${Y4MSCALER} ${Y4MSCALER_FLAGS} |"
fi
# video filters chain
for FILTER in `echo ${FILTERS_CHAIN} | sed s/,/"\n"/g`; do
FILTER_TYPE="`echo ${FILTER} | awk -F: '{print $1}'`"
FILTER_LEVEL="`echo ${FILTER} | awk -F: '{print $2}'`"
if test "${FILTER_LEVEL}" = ""; then
FILTER_LEVEL="light"
fi
MEANFILTER_FLAGS="-f"
Y4MDENOISE_FLAGS="-v 0"
# filter level
if test "${FILTER_LEVEL}" = "light"; then
YUVMEDIANFILTER_FLAGS="-t 0"
YUVDENOISE_FLAGS="-l 1 -t 4 -S 0"
YUVDENOISE2_FLAGS="-y 4 -u 8 -v 8"
YUVDENOISE3_FLAGS=""
Y4MSPATIALFILTER_FLAGS="-x 0 -y 0"
MEANFILTER_FLAGS="${MEANFILTER_FLAGS} -t 0"
Y4MDENOISE_FLAGS="${Y4MDENOISE_FLAGS} -t 1"
Y4MUNSHARP_FLAGS="-L 1.5,0.2,0"
elif test "${FILTER_LEVEL}" = "medium"; then
YUVMEDIANFILTER_FLAGS="-T 0"
YUVDENOISE_FLAGS="-l 2 -t 6 -S 0"
YUVDENOISE2_FLAGS="-y 8 -u 16 -v 16"
YUVDENOISE3_FLAGS=""
Y4MSPATIALFILTER_FLAGS="-X 4,0.64 -Y 4,0.8"
MEANFILTER_FLAGS="${MEANFILTER_FLAGS} -r 1 -T 0 -w 12"
Y4MDENOISE_FLAGS="${Y4MDENOISE_FLAGS} -t 2"
Y4MUNSHARP_FLAGS="-L 2.0,0.3,0"
elif test "${FILTER_LEVEL}" = "heavy"; then
YUVMEDIANFILTER_FLAGS=""
YUVDENOISE_FLAGS="-l 3 -t 8 -S 0"
YUVDENOISE2_FLAGS="-y 16 -u 32 -v 32"
YUVDENOISE3_FLAGS=""
Y4MSPATIALFILTER_FLAGS="-X 4,0.5 -Y 4,0.5 -x 2,0.5 -y 2,0.5"
MEANFILTER_FLAGS="${MEANFILTER_FLAGS} -r 1 -R 1"
Y4MDENOISE_FLAGS="${Y4MDENOISE_FLAGS} -t 3"
Y4MUNSHARP_FLAGS="-L 5.0,0.5,0"
else
show_error "the specified \"${FILTER_LEVEL}\" filter level is inexistant."
exit 2
fi
# filter type
if test "${FILTER_TYPE}" = "none"; then
FILTER=""
elif test "${FILTER_TYPE}" = "hqdenoise"; then
test_bin ${Y4MDENOISE}
FILTER="${Y4MDENOISE} ${Y4MDENOISE_FLAGS} |"
elif test "${FILTER_TYPE}" = "mean"; then
test_bin ${YUVMEDIANFILTER}
FILTER="${YUVMEDIANFILTER} ${MEANFILTER_FLAGS} |"
elif test "${FILTER_TYPE}" = "median"; then
test_bin ${YUVMEDIANFILTER}
FILTER="${YUVMEDIANFILTER} ${YUVMEDIANFILTER_FLAGS} |"
elif test "${FILTER_TYPE}" = "spatial"; then
test_bin ${Y4MSPATIALFILTER}
FILTER="${Y4MSPATIALFILTER} ${Y4MSPATIALFILTER_FLAGS} |"
elif test "${FILTER_TYPE}" = "temporal_old"; then
test_bin ${YUVDENOISE}
FILTER="${YUVDENOISE} ${YUVDENOISE_FLAGS} |"
elif test "${FILTER_TYPE}" = "temporal_rc1"; then
test_bin ${YUVDENOISE}
FILTER="${YUVDENOISE} ${YUVDENOISE2_FLAGS} |"
elif test "${FILTER_TYPE}" = "temporal"; then
test_bin ${YUVDENOISE}
FILTER="${YUVDENOISE} ${YUVDENOISE3_FLAGS} |"
elif test "${FILTER_TYPE}" = "unsharp"; then
test_bin ${Y4MUNSHARP}
FILTER="${Y4MUNSHARP} ${Y4MUNSHARP_FLAGS} |"
else
show_error "the specified \"${FILTER_TYPE}\" filter type is not used by this script."
exit 2
fi
FILTERS="${FILTERS} ${FILTER}"
done
# 3:2 pulldown
if test "${VID_FPS_OUT}" = "24000:1001" && test "${VID_FMT_OUT}" = "m2v"; then
FF_ENC="${FF_ENC}"
MPEG2ENC="${MPEG2ENC} -p"
fi
# quantisation matrices
if test "${MATRICES}" = "kvcd"; then
FF_ENC="${FF_ENC} -intra_matrix ${INTRA_KVCD} -inter_matrix ${INTER_KVCD}"
MPEG2ENC="${MPEG2ENC} -K kvcd"
elif test "${MATRICES}" = "mvcd"; then
echo "`matrix_copy ${INTRA_MVCD}`" > ${CQMFILE}
echo "`matrix_copy ${INTER_MVCD}`" >> ${CQMFILE}
FF_ENC="${FF_ENC} -intra_matrix ${INTRA_MVCD} -inter_matrix ${INTER_MVCD}"
MPEG2ENC="${MPEG2ENC} -K file=${CQMFILE}"
elif test "${MATRICES}" = "tmpgenc"; then
FF_ENC="${FF_ENC} -intra_matrix ${INTRA_TMPGENC} -inter_matrix ${INTER_TMPGENC}"
MPEG2ENC="${MPEG2ENC} -K tmpgenc"
fi
# video encoding mode
if test "${ENC_TYPE}" = "cbr"; then
# when using -q with mpeg2enc, variable bitrate is selected.
# it's not ok for vcds...
MPEG2ENC="${MPEG2ENC}"
elif test "${ENC_TYPE}" = "abr"; then
if test "${DURATION}" != ""; then
# input total time (seconds)
VID_TIME_SRC="`echo "${DURATION}" | \
awk '{print $1 * 60}'`"
else
# input length (frames)
if echo "${VID_FMT_SRC}" | grep -e mpeg1 -e mpeg2 >/dev/null 2>&1; then
test_bin ${TCCAT} && test_bin ${TCDEMUX}
VID_LENGTH_SRC="`${TCCAT} -i "${VIDEO_SRC}" | ${TCDEMUX} -W 2>&1 | awk '/unit/ {print sum+=$2}' | tail -1`"
else
test_bin ${TCPROBE}
VID_LENGTH_SRC="`${TCPROBE} -i "${VIDEO_SRC}" 2>/dev/null | awk '/length:/ {print $2}'`"
fi
# input total time (seconds) = nb of frames / fps
VID_TIME_SRC="`echo "${VID_LENGTH_SRC}:${VID_FPS_SRC}" | \
awk -F: '{print $1 / $2 * $3 + 1}'`"
fi
test_bin bc
# available kbits (k = 1000) per second = global bitrate
BPS="`echo "${VOLUMES} * ${VOL_SIZE} * 1000 * 8 / ${VID_TIME_SRC}" | bc`"
# muxing-overhead: 3% (0.97 * ...)
VID_BITRATE_OUT="`echo "0.97 * ${BPS} - ${AUD_BITRATE_OUT}" | bc | \
awk -F. '{print $1}'`"
VID_BITRATE_OUT="`range_check ${VID_BITRATE_OUT} ${VID_MINRATE_OUT} ${VID_MAXRATE_OUT}`"
FF_ENC="${FF_ENC} -minrate ${VID_MINRATE_OUT} -maxrate ${VID_MAXRATE_OUT} -b ${VID_BITRATE_OUT} -passlogfile ${STATFILE}"
FF_STATS="${FF_ENC} -pass 1"
MPEG2ENC_STATS="${MPEG2ENC} -b ${VID_BITRATE_OUT} -q 1 -v 1 2>${STATFILE}"
FF_ENC="${FF_ENC} -pass 2"
MPEG2ENC="${MPEG2ENC}"
else
FF_ENC="${FF_ENC} -maxrate ${VID_MAXRATE_OUT} -qscale ${QUANT}"
MPEG2ENC="${MPEG2ENC} -b ${VID_MAXRATE_OUT} -q ${QUANT}"
fi
# video encoder
if test "${ENC_TOOL}" = "ffmpeg"; then
test_bin ${FFMPEG}
ANALYSER="${FF_STATS} -y \"${VIDEO_OUT}\""
ENCODER="${FF_ENC} -y \"${VIDEO_OUT}\""
elif test "${ENC_TOOL}" = "mpeg2enc"; then
test_bin ${MPEG2ENC}
ANALYSER="${MPEG2ENC_STATS} -o \"${VIDEO_OUT}\""
ENCODER="${MPEG2ENC} -o \"${VIDEO_OUT}\""
else
show_error "the specified video encoder tool is not used by this script."
show_error "Use -h to get help."
exit 2
fi
# audio resampler
if test "${AUD_FREQ_SRC}" = "${AUD_FREQ_OUT}"; then
AUDIO_RESAMPLER=""
else
test_bin ${SOX}
AUDIO_RESAMPLER="${SOX} -t au /dev/stdin -r ${AUD_FREQ_OUT} -t au /dev/stdout polyphase |"
fi
# audio decoder/encoder
if test "${ACOPY_MODE}" = "1"; then
AUDIO_DECODER="${FFMPEG} ${FF_DEC_AFLAGS}"
AUDIO_ENCODER="-acodec copy -y \"${AUDIO_OUT}\""
elif test "${AUD_FREQ_SRC}" = "${AUD_FREQ_OUT}"; then
AUDIO_DECODER="${FFMPEG} ${FF_DEC_AFLAGS}"
AUDIO_ENCODER="-ab ${AUD_BITRATE_OUT} -ac ${AUD_CHANNELS_OUT} -y \"${AUDIO_OUT}\""
else
AUDIO_DECODER="${FFMPEG} ${FF_DEC_AFLAGS} -v 0 -f au -y /dev/stdout |"
AUDIO_ENCODER="${FFMPEG} -f au -i /dev/stdin -ab ${AUD_BITRATE_OUT} -ac ${AUD_CHANNELS_OUT} -y \"${AUDIO_OUT}\""
fi
# output some info.
show_info "===== SOURCE STREAM ====================="
show_info " frame size: ${VID_SIZE_SRC}"
show_info " frame rate: ${VID_FPS_SRC}"
show_info " interlacing: ${VID_ILACE_SRC}"
show_info " pixel aspect ratio: ${VID_SAR_SRC}"
show_info "===== OUTPUT STREAM ====================="
show_info " frame size: ${VID_SIZE_OUT}"
show_info " frame rate: ${VID_FPS_OUT}"
show_info " interlacing: ${VID_ILACE_OUT}"
show_info " pixel aspect ratio: ${VID_SAR_OUT}"
# video "analyse"
if ! test "${BLIND_MODE}" = "1" && test "${ENC_TYPE}" = "abr"; then
eval "${DECODER} ${FILTERS} ${FRC} ${SCALER} ${PIPE_BUFFER} ${ANALYSER}"
if test "${ENC_TOOL}" = "mpeg2enc"; then
# calculate average quant value from pseudo statfile (mpeg2enc output)
QUANT="`awk -F= '/quant=/ {print $2}' "${STATFILE}" | \
awk '{iquant=$1; \
oquant=iquant; \
if (iquant>= 10) {oquant=9}; \
if (iquant>= 12) {oquant=10}; \
if (iquant>= 14) {oquant=11}; \
if (iquant>= 16) {oquant=12}; \
if (iquant>= 18) {oquant=13}; \
if (iquant>= 20) {oquant=14}; \
if (iquant>= 22) {oquant=15}; \
if (iquant>= 24) {oquant=16}; \
if (iquant>= 28) {oquant=17}; \
if (iquant>= 32) {oquant=18}; \
if (iquant>= 36) {oquant=19}; \
if (iquant>= 40) {oquant=20}; \
if (iquant>= 44) {oquant=21}; \
if (iquant>= 48) {oquant=22}; \
if (iquant>= 52) {oquant=23}; \
if (iquant>= 56) {oquant=24}; \
if (iquant>= 64) {oquant=25}; \
if (iquant>= 72) {oquant=26}; \
if (iquant>= 80) {oquant=27}; \
if (iquant>= 88) {oquant=28}; \
if (iquant>= 96) {oquant=29}; \
if (iquant>= 104) {oquant=30}; \
if (iquant>= 112) {oquant=31}; \
nquant+=1; \
sum_quant+=oquant; \
print sum_quant/nquant}' | \
tail -1 | awk -F. '{print $1}'`"
QUANT="`range_check $QUANT 3 31`"
ENCODER="${MPEG2ENC} -b ${VID_MAXRATE_OUT} -q ${QUANT} -o ${VIDEO_OUT}"
fi
fi
# video (de)coding
if ! test "${BLIND_MODE}" = "1"; then
eval "${DECODER} ${FILTERS} ${FRC} ${SCALER} ${PIPE_BUFFER} ${ENCODER}"
fi
# audio (de)coding
if ! test "${MUTE_MODE}" = "1"; then
eval "${AUDIO_DECODER} ${AUDIO_RESAMPLER} ${AUDIO_ENCODER}"
fi
# multiplexing
if ! test "${BLIND_MODE}" = "1" && ! test "${MUTE_MODE}" = "1"; then
if test "${REQUANT_MODE}" = "1"; then
VID_SRC_SIZE="`ls -l ${VIDEO_OUT} | awk '{print $5}'`"
AUD_SRC_SIZE="`ls -l ${AUDIO_OUT} | awk '{print $5}'`"
REQUANT_FACT="`echo "scale=3; ${VID_SRC_SIZE} / (0.96 * ${VOL_SIZE} * 1000 * 1000 - ${AUD_SRC_SIZE})" | bc -l`"
# sed is here to replace a "requant_fact * 1000"
if test `echo ${REQUANT_FACT} | sed s/"\."//` -gt 1000; then
VIDEO_SRC="${VIDEO_OUT}"
VIDEO_OUT="${PREFIX_OUT}.req"
show_info "Requantisation factor: ${REQUANT_FACT}"
test_bin ${TCREQUANT}
${TCREQUANT} -i ${VIDEO_SRC} -o ${VIDEO_OUT} -f ${REQUANT_FACT}
else
show_warn "Requantisation not done. Requantisation factor lesser than 1.0."
fi
fi
test_bin ${MPLEX}
${MPLEX} ${MPLEX_FLAGS} -o "${MPEG_OUT}" "${VIDEO_OUT}" "${AUDIO_OUT}"
fi
rm -f ${CQMFILE} ${STATFILE}
exit 0
|