leandromoreira / ffmpeg-libav-tutorial

FFmpeg libav tutorial - learn how media works from basic to transmuxing, transcoding and more. Translations: πŸ‡ΊπŸ‡Έ πŸ‡¨πŸ‡³ πŸ‡°πŸ‡· πŸ‡ͺπŸ‡Έ πŸ‡»πŸ‡³ πŸ‡§πŸ‡·
https://github.com/leandromoreira/ffmpeg-libav-tutorial
BSD 3-Clause "New" or "Revised" License
9.93k stars 956 forks source link

Overlay shape while transcoding video #98

Closed LentilStew closed 3 years ago

LentilStew commented 3 years ago

I added this function in 3_transcoding.c image It's called to draw an square in every frame it only changes the Y of the YUV file, I made it just to see if I could overlay images this way FirstFrame This is the fist frame of the video, screenshot from VLC^^ LastFrame This is the last frame of the video, screenshot from VLC^^ frame-1423836064 This is the pgm output of the save_gray_frame function^^ frame-654704535 This is another example of the save_gray_Frame function ^^ Is this the intended way to overlay images?, Are there other ways of doing it? I imagine that the image is weird because of the compression image

leandromoreira commented 3 years ago

hi @LentilStew nice addition, usually the overlay is handled by the ffmpeg filtering (my intent is to do a next chapter on that).

But you can see filtering in action on github.

LentilStew commented 3 years ago

If anyone wants to overlay the image this way, without it being ugly, you have to copy the frame image and send the encoder a copy of the frame Remember to free the new frame

leandromoreira commented 3 years ago

cool @LentilStew thanks for sharing!

Why do you need to copy format, width... even using the av_frame_copy_props? (I don't know this API, just curious, by its name I suppose it should copy all the properties, I'm guessing)

LentilStew commented 3 years ago

I copied the code from here stackoverflow

But the av_frame_get_buffer() function says that "format (pixel format for video, sample format for audio)- width and height for video- nb_samples and channel_layout for audio" must be set before calling the function

and the function av_frame_copy_props() says that it does not copy pts, sample rate (for audio) or sample aspect ratio (for video), but not width/height or channel layout.

the av_frame_copy_props() only copies "metadata" fields from src to dst