Find the answer to your Linux question:
Results 1 to 2 of 2
friends, I am attempting to use jpg2yuv on many jpgs I have a dir with 300 jpegs ( 000.jpg - 299.jpg ) here is my script #!/bin/bash # n=300 n=300 ...
  1. #1
    Just Joined!
    Join Date
    Sep 2006
    Posts
    4

    problem with $( printf "%03d" $i in script

    friends,

    I am attempting to use jpg2yuv on many jpgs
    I have a dir with 300 jpegs ( 000.jpg - 299.jpg )

    here is my script
    #!/bin/bash
    # n=300
    n=300
    for (( i=000; i < n; i++ ))
    do
    jpeg2yuv -n 30 -I p -L 0 -f 30 -j "$( printf "%03d" $i).jpg | mpeg2enc -a 2 -f 8 -b 5800 -o "$( printf "%03d" $i).mpg
    printf " OK\n"
    done

    it fails - complaining that there is no such file----------
    <snip>
    INFO: [jpeg2yuv] Parsing & checking input files.
    **ERROR: [jpeg2yuv] System error while opening: "000.jpg | mpeg2enc -a 2 -f 8 -b 5800 -o 000.mpg": No such file or directory
    </snip>

    but - of course - there IS a 000.jpg and this works
    jpeg2yuv -n 30 -I p -L 0 -f 30 -j 000.jpg | mpeg2enc -a 2 -f 8 -b 5800 -o 000.mpg

    i get a good 000.mpg - so I know all is ok but for my script.
    ( i am not a real good scripter....)

    I am certain that it is something about my " or ' or lack of.....
    Thanks!

  2. #2
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    At first glance, you should change this:

    Code:
    jpeg2yuv -n 30 -I p -L 0 -f 30 -j "$( printf "&#37;03d" $i).jpg | mpeg2enc -a 2 -f 8 -b 5800 -o "$( printf "%03d" $i).mpg
    to this:

    Code:
    jpeg2yuv -n 30 -I p -L 0 -f 30 -j "$( printf "%03d" $i).jpg" | mpeg2enc -a 2 -f 8 -b 5800 -o "$( printf "%03d" $i).mpg"
    At second, you could rewrite the script as:

    Code:
    for f in *.jpg; do
      printf "processing %s ...\n" "$f"
      jpeg2yuv -n 30 -I p -L 0 -f 30 -j "$f" |
        mpeg2enc -a 2 -f 8 -b 5800 -o "${f%.jpg}.mpg"
      printf "%s done\n" "$f"	
    done

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...