Can anyone re-direct me here please?
The following extracted lines of code are taken from an adapted
output_example.c which reads in a movie file and converts frames to RGB
and then re-encodes the RGB frames into an output file. I'm sure some
of the variable names will be familiar to many of you.
If I simply pass the ipFrame directly into the write_video_frame() - it
works OK (although, I confess I'm still not sure how - but I do end up
with an output file nevertheless?). However, if I pass in the opFrame
into write_video_frame() (i.e. the one converted to RGB and back again)
then the program barfs with the trace given at the bottom of this email.
Relevant declarations are here...
ipFrame = avcodec_alloc_frame();
opFrame = avcodec_alloc_frame();
ipFrameRGB = avcodec_alloc_frame();
PixelFormat ipPixFmt = ipCodecCtx->pix_fmt;
video_outbuf_size = 200000;
video_outbuf = (uint8_t *)av_malloc(video_outbuf_size);
int num_bytes_per_frame = avpicture_get_size(PIX_FMT_RGB24,
ipCodecCtx->width, ipCodecCtx->height);
uint8_t *ipBufferRGB=(uint8_t
*)av_malloc(num_bytes_per_frame*sizeof(uint8_t));
avpicture_fill((AVPicture *)ipFrameRGB, ipBufferRGB, PIX_FMT_RGB24,
ipCodecCtx->width, ipCodecCtx->height);
...
output_example.c code in here to initialise the output video stream
...
while decoding the input video stream
...
if(frameFinished)
{
// Convert the image from its native format to RGB
struct SwsContext *ipCtx =
sws_getContext(ipCodecCtx->width, ipCodecCtx->height,
ipCodecCtx->pix_fmt,
ipCodecCtx->width, ipCodecCtx->height,
PIX_FMT_RGB24,
SWS_FAST_BILINEAR, NULL, NULL, NULL);
sws_scale(ipCtx, ipFrame->data, ipFrame->linesize,
0, ipCodecCtx->height,
ipFrameRGB->data, ipFrameRGB->linesize);
// ########### I INTEND TO ADJUST THE RGB PIXELS HERE
##################
// ########### BEFORE RE-ENCODING INTO THE OUTPUT FILE
#################
// Convert the image back to its native format
struct SwsContext *opCtx =
sws_getContext(ipCodecCtx->width, ipCodecCtx->height,
ipCodecCtx->pix_fmt,
ipCodecCtx->width, ipCodecCtx->height, ipPixFmt,
SWS_FAST_BILINEAR, NULL, NULL, NULL);
sws_scale(opCtx, ipFrameRGB->data, ipFrameRGB->linesize,
0, ipCodecCtx->height,
opFrame->data, ipFrame->linesize);
opFrame->pts = opPacket.pts; // retain original timestamps
write_video_frame(opFormatCtx, opVideoSt, opFrame); // from
output_example.c
} // end if frame finished
...
end while decoding the input stream
This piece of code crashes in the avcodec_encode_video within the
write_video_frame...
#0 0x00002b1394f50102 in memcpy () from /lib64/libc.so.6
#1 0x00002b13953eff30 in ?? ()
#2 0x00000000004cd975 in MPV_encode_picture (avctx=0xcabc60, buf=<value
optimized out>, buf_size=<value optimized out>, data=0xcab870) at
libavcodec/mpegvideo_enc.c:874
#3 0x000000000048610f in avcodec_encode_video (avctx=0xcabc60,
buf=0x2b139528d010 "", buf_size=200000, pict=0xcab870) at
libavcodec/utils.c:897
#4 0x000000000041477a in write_video_frame (opFormatCtx=0xc9a010,
st=0xcabad0, avFrame=0xcab870) at writer.c++:140
#5 0x00000000004151e1 in main (argc=5, argv=0x7fff1646f9f8) at
writer.c++:424
where line 140 is the encode line thus:
out_size = avcodec_encode_video(opCodecCtx, video_outbuf,
video_outbuf_size, opFrame);
I have probably made some ridiculous assumption about the way the Frame
buffers (ip/op/RGB) work and wondered if anyone could tell if I at least
have the right approach (e.g. do I need to prime the opFrame with all
the ipFrame characteristics somehow) or if someone has an similar
example clip somewhere that I could look at?
Gary
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user