png2y4m.sh 1011 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. # Converts PNG files to Y4M.
  3. #
  4. # This script is different from png2y4m.c in that it:
  5. # - Uses JPEG color levels instead of video levels
  6. # - Uses the ITU-RBT.601 matrix instead of ITU-RBT.709 matrix
  7. # - Does not dither the input image
  8. if [ $# == 0 ]; then
  9. echo "usage: BUILD_ROOT=<build_dir> $0 *.png"
  10. exit 1
  11. fi
  12. if [ -z $BUILD_ROOT ]; then
  13. BUILD_ROOT=.
  14. fi
  15. if [ -z "$YUV2YUV4MPEG" ]; then
  16. YUV2YUV4MPEG=$BUILD_ROOT/tools/yuv2yuv4mpeg
  17. fi
  18. if [ ! -f "$YUV2YUV4MPEG" ]; then
  19. echo "File not found YUV2YUV4MPEG=$YUV2YUV4MPEG"
  20. echo "Do you have the right BUILD_ROOT=$BUILD_ROOT"
  21. exit 1
  22. fi
  23. FILES=$(find $@ -type f -name "*.png")
  24. for f in $FILES; do
  25. BASENAME=${f%.*}
  26. convert png:$BASENAME.png -sampling-factor 4:2:0 -depth 8 $BASENAME.yuv
  27. SIZE=$(identify $BASENAME.png | sed -re 's/^.*PNG\ +([0-9]+x[0-9]+).*$/\1/')
  28. WIDTH=$(echo $SIZE | cut -dx -f1)
  29. HEIGHT=$(echo $SIZE | cut -dx -f2)
  30. $YUV2YUV4MPEG $BASENAME -w$WIDTH -h$HEIGHT -an0 -ad0 -c420jpeg
  31. rm $BASENAME.yuv
  32. done