Thanks, Hendrik, for your generous help. I still don't quite
understand it here. What's the reason to copy the target avframe data?
After the data copying, can I still scale the second image onto the
same target avframe? Also, I don't understand the algorithm to add
linesize/2 to the data pointers. After doing that, it seems like I got
a memory access error when calling sws_scale.
Your way should be the ideal one to accomplish what I want. I just
need to get it done right. :)

On 3/14/10, Hendrik Jürgens <[email protected]> wrote:
> You simply have to adjust the data pointers of your target image, to scale
> the second input on it.
>
> Simply copy the data and linesize arrays.
> Then add linesize/2 to the data pointers. With this you get a shift in the x
> direction.
>
> i.e.
> avframecopy = avframe;
> avframecopy.data[0] += avframecopy.linesize[0] / 2;
> avframecopy.data[1] += avframecopy.linesize[1] / 2;
> avframecopy.data[2] += avframecopy.linesize[2] / 2;
>
> then you can scale your second image with a resolution of 320x480 on this
> "new" target.
>
> This should do the trick here.
>
> Please note, that this needs more rethinking, if your target resolution
> differs. But with yuv420 and 640x480 you shouldn't have a problem here.
>
> ________________________________________
> Von: [email protected] [[email protected]] im
> Auftrag von Ke Yu [[email protected]]
> Gesendet: Freitag, 12. März 2010 21:00
> An: Libav* user questions and discussions
> Betreff: Re: [libav-user] stitch avframes
>
> I think I figured out what you meant. Here's my understanding (my pixel_fmt
> is PIX_FMT_YUV420P):
> 1). concatenate each corresponding field in avframe->data with data from
> both src images (avframes);
> 2). double the value of each field in avframe->linesize;
> 3). sws_scale the avframe built with step 1) and 2) into the allocated
> avframe with res. 640x480.
>
> I'm trying it now. I'll let you know how it goes.
>
> Best Regards.
>
> On Fri, Mar 12, 2010 at 12:03 PM, Ke Yu <[email protected]> wrote:
>
>> Thanks for the great idea. Following your suggestion, I scaled one of the
>> source images to the allocated dest. frame (640x480). It is fast! However,
>> I
>> could only scale the first src image to the left portion of the dest.
>> frame.
>> How can I scale the second src image to the right portion of the dest.
>> frame? sws_scale/sws_getContext only give sizes no location coordinates.
>> Is there a way with which I can specify the coordinates as well?
>>
>> Thanks again!
>>
>> 2010/3/12 Hendrik Jürgens <[email protected]>
>>
>> Am 12.03.2010 01:14, schrieb Stefano Sabatini:
>>>
>>> On date Thursday 2010-03-11 14:21:24 -0500, Ke Yu encoded:
>>>>
>>>>> Hi!
>>>>>
>>>>> I've got avframes from two udp multicast video streams. I would like to
>>>>> scale every avframe into half (only x coordinate, e.g.,
>>>>> 640x480->320x480) and stitch the two scaled avframes into one avframe
>>>>> with
>>>>> original size (e.g., 640x480). After that, I'll encode the generated
>>>>> avframes into one output video stream. My input video streams have the
>>>>> same
>>>>> encoding context. The frame rate is 30 fps. So I have about 33ms to
>>>>> finish
>>>>> the scaling and stitching. The performance is critical. I plan to use
>>>>> sws_scale to scale the avframe but don't know how to stitch two scaled
>>>>> avframes together. I prefer not to use a third party image lib.
>>>>>
>>>>> Can anyone help me to figure that out?
>>>>>
>>>>
>>>> Try with libavfilter+overlay, integration into main SVN pending.
>>>>
>>>> Regards.
>>>>
>>>
>>>
>>> Hi,
>>>
>>> You can allocate your AVFrame with the target resolution (640x480) and
>>> then let sws_scale the sourceimages directly onto this frame.
>>>
>>> You simply have to modify the data pointers and linepitches of yout
>>> AVFrame before giving them to sws_scale. If you don't need any
>>> transparency
>>> or some other fancy image stuff this should be the fastest way.
>>>
>>>
>>> Best regards
>>> Hendrik
>>>
>>> _______________________________________________
>>> libav-user mailing list
>>> [email protected]
>>> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>>>
>>
>>
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to