0

I'm trying to scale and crop an image and use it as MKV attachment in one shot, but without success. I understand that the "-attach" command does exactly that, but the problem is that I don't have the final image as a file. Instead I'm trying to crop and scale the file on the fly, doing something like this:

ffmpeg -fflags +genpts \
-i video.h265 \
-i audio.ac3 \
-i sub.ass \
-i cover_img.jpg \
-filter_complex "[3:v]crop=in_h:in_h,scale=600:600[cover]; [3:v]crop=in_h:in_h,scale=120:120[small_cover]; [3:v]scale='-1:600'[cover_land]; [3:v]scale='-1:120'[small_cover_land]" \
-map 0:v:0 -map 1:a:0 -map 2:s:0 \
-map "[cover]" -disposition:v:1 attached_pic -metadata:s:v:1 filename="cover.jpg" -metadata:s:v:1 mimetype="image/jpeg" \
-map "[small_cover]" -disposition:v:2 attached_pic -metadata:s:v:2 filename="small_cover.jpg" -metadata:s:v:2 mimetype="image/jpeg" \
-map "[cover_land]" -disposition:v:3 attached_pic -metadata:s:v:3 filename="cover_land.jpg" -metadata:s:v:3 mimetype="image/jpeg" \
-map "[small_cover_land]" -disposition:v:4 attached_pic -metadata:s:v:4 filename="small_cover_land.jpg" -metadata:s:v:1 mimetype="image/jpeg" \
-r 24000/1001 -c:s ass -c:a copy \
-c:v mjpeg -c:v:0 libx265 \
out.mkv

But it doesn't work, because the streams are mapped as video, not attachments.

I also tried to change the "[3:v]" in filter_complex to "[3:t]", but it doesn't work, since pictures are considered as video streams.

Now I resorted to a two-step process, but I'm looking for a way to do both things at the same time:

ffmpeg -i cover_img.jpg \
-filter_complex "[0:v]crop=in_h:in_h,scale=600:600[cover]; [0:v]crop=in_h:in_h,scale=120:120[small_cover]; [0:v]scale='-1:600'[cover_land]; [0:v]scale='-1:120'[small_cover_land]" \
-c:v mjpeg \
-map "[cover]" cover.jpg \
-map "[small_cover]" small_cover.jpg \
-map "[cover_land]" cover_land.jpg \
-map "[small_cover_land]" small_cover_land.jpg

ffmpeg -fflags +genpts \
-i video.h265 \
-i audio.ac3 \
-i sub.ass \
-map 0:v:0 -map 1:a:0 -map 2:s:0 \
-attach "cover.jpg" -metadata:s:t:0 mimetype="image/jpeg" \
-attach "small_cover.jpg" -metadata:s:t:1 mimetype="image/jpeg" \
-attach "cover_land.jpg" -metadata:s:t:2 mimetype="image/jpeg" \
-attach "small_cover_land.jpg" -metadata:s:t:3 mimetype="image/jpeg" \
-r 24000/1001 -c:s ass -c:a copy \
-c:v libx265 \
out.mkv

Thank you for your help.

1 Answers1

0

-attach expects an external file URL and does not work with streams sent from a filtergraph output.

Gyan
  • 85,394
  • 9
  • 169
  • 201