Page 1 of 1

Resize without altering the palette (solved)

Posted: 2009-06-30T08:22:22-07:00
by etpicb
I am converting a movie from ntsc to pal, the subtitles (as the movie) need to be converted from the resolution of 720x480 to 720x576.

The subtitles are 8bits png files with at most 4 colours (one being the transparency), to convert all the files I used:

Code: Select all

for d in *.png ;do
convert "$d" -resize '720x576!' -colors 4 tmp.png || break
mv tmp.png "$d"
done
Unfortunately every subtitle file must use the _same_ four colours.
Using convert this way the four colours in each file can be (and are) different.

How can I force convert to maintain the original colours or how can I set the palette?

Thanks.

Re: Resize without altering the palette

Posted: 2009-06-30T09:52:39-07:00
by fmw42

Re: Resize without altering the palette

Posted: 2009-06-30T20:25:38-07:00
by anthony
If you resize using -sample only the original colors will be used. But at a loss of quality!

The other method as pointed out by fred, is to re-map the image to just the four colors desired. You may or may not want the dither for this (turn of dither with +dither)

Re: Resize without altering the palette

Posted: 2009-07-01T06:03:45-07:00
by etpicb
To anyone interested:

You can convert your DVD subtitles from one resolution to an other extracting them with

Code: Select all

tccat -i /dev/sr2 -T 8,-1 | tcextract -x ps1 -t vob -a 0x20 > subsen
mkdir subtitles
cd subtitles
subtitle2pgm -i ../subsen -c 224,224,32,0 -g 4 -t 1 # <-- verify the vaules of -c they depends on the movie(1)
convert all the png files with

Code: Select all

for d in *.png ;do
  convert "$d" -resize '720x575!' +dither -map "$d" tmp.png || break
  mv tmp.png "$d"
  echo "$d"
done
mixing them in the mpg file with the movie with

Code: Select all

spumux -s0 movie_subtitle.dvdxml <../movie.mpg >../movie_wsubs.mpg #<-- increase the -s value if it is not the first subtitle
and finally you can author your dvd with the mpg file.

About (1)
I usually use `-c 0,85,170,255' to see how is the palette and assign black to the background, white inside the letters and dark gray around.

Thanks everyone.