hyun
hyun

Reputation: 11

I want to divide image into even and odd line

I have 4096x2048 resolution jpg image.

I want to divide the image into even odd line.

So, image pixel coordinate (1,1),(1,2)....(1,4096) and (3,1),(3,2)...(3,4096) ... are made into odd line image. And the new image file resolution will be 4096x1024.

I search many ffmpeg code.But i can't find that kind of code..

ffmpeg -i in.mp4 \
  -filter_complex "[0]il=l=d:c=d,split[o][e];\
                   [o]crop=iw:ih/2:0:0[odd];\
                   [e]crop=iw:ih/2:0:ih/2[even]" \
  -map "[odd]" -f rawvideo odd.yuv \
  -map "[even]" -f rawvideo even.yuv

it is what i do for dividing the images(video) into even odd part.

how can i make it?

Upvotes: 1

Views: 258

Answers (1)

Rotem
Rotem

Reputation: 32124

The command you have posted is working well, just change the formats.

You are not defining the format of the output images.
I suggest using PNG format for the output images instead of JPEG.

JPEG images looses quality due to lossy compression.
JPEG images are also in YUV420 pixel format, so the chroma channels are down-sampled.

We may use the following command:

ffmpeg -y -i in.jpg -filter_complex "[0]format=rgb24,il=l=d:c=d,split[o][e];[o]crop=iw:ih/2:0:0[odd];[e]crop=iw:ih/2:0:ih/2[even]" -map "[odd]" odd.png -map "[even]" even.png

The following command is a bit more elegant (without using l=d:c=d):

ffmpeg -y -i in.jpg -filter_complex "[0]format=rgb24,il=deinterleave,split[o][e];[o]crop=iw:ih/2:0:0[odd];[e]crop=iw:ih/2:0:ih/2[even]" -map "[odd]" odd.png -map "[even]" even.png

Sample input in.jpg:
enter image description here

Output:
odd.png:
enter image description here

even.png:
enter image description here


The format=rgb24 filter in the beginning of the filters chain converts the input pixel format from YUV420 to RGB, before splitting to even and odd.
It supposed to improve the quality of the output, but it is almost unnoticeable.

Upvotes: 1

Related Questions