Hi,
I can't add frames to the video_stream. Value of "index" always change
but index of video_st never changes. So I think I can't add frames but
I can't find why.. Can anyone help me.. Thank you..
Here is some parts of my code
static void write_video_frame(AVFormatContext *oc,AVFrame *pFrame,int
index)
{
int out_size, ret;
AVCodecContext *c;
static struct SwsContext *img_convert_ctx;
c = video_st->codec;
if (oc->oformat->flags & AVFMT_RAWPICTURE >0 ) else {
printf("Non Raw picture");
out_size = avcodec_encode_video(c, video_outbuf,
video_outbuf_size, pFrame);
if (out_size > 0) {
AVPacket pkt;
av_init_packet(&pkt);
if (c->coded_frame->pts != AV_NOPTS_VALUE)
pkt.pts= av_rescale_q(c->coded_frame->pts, c-
>time_base, video_st->time_base);
if(c->coded_frame->key_frame)
pkt.flags |= AV_PKT_FLAG_KEY;
pkt.stream_index= video_st->index;
pkt.data= video_outbuf;
pkt.size= out_size; sprintf(info,"write pkt.size
%d",pkt.stream_index);
log_message(info);
ret = av_interleaved_write_frame(oc, &pkt);
} else {
ret = 0;
}
}
if (ret != 0) {
fprintf(stderr, "Error while writing video frame\n");
exit(1);
}
}
void encodeVideo( AVFormatContext *oc,AVOutputFormat *fmt,JNIEnv* env,
jobject javaThis , char *orginalfilename, int w,int h,AVFrame
*pFrame,int index){
char filename[50] = "/sdcard/new_";
int i;
char deletedfile[40];
char secondfilename[50];
for(i=0;i<50;i++){
secondfilename[i]='\0';
}
for(i=12;i<50;i++){
filename[i]='\0';
}
strncpy(secondfilename,orginalfilename
+8,strlen(orginalfilename)-8);
strcat(filename , secondfilename);
av_register_all();
fmt = av_guess_format(NULL, filename, NULL);
if (!fmt) {
printf("Could not deduce output format from file extension:
using MPEG.\n");
fmt = av_guess_format("mpeg", NULL, NULL);
}
if (!fmt) {
fprintf(stderr, "Could not find suitable output format\n");
exit(1);
}
oc = avformat_alloc_context();
if (!oc) {
fprintf(stderr, "Memory error\n");log_message("Memory error");
exit(1);
}
oc->oformat = fmt;
snprintf(oc->filename, sizeof(oc->filename), "%s", filename);
video_st = NULL;
if (fmt->video_codec != CODEC_ID_NONE) {
video_st = add_video_stream(oc,w,h,fmt->video_codec);
}
if (av_set_parameters(oc, NULL) < 0) {
fprintf(stderr, "Invalid output format parameters\n");
exit(1);
}
dump_format(oc, 0, filename, 1);
if (video_st)
open_video(oc);
if (!(fmt->flags & AVFMT_NOFILE)) {
if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) {
fprintf(stderr, "Could not open '%s'\n", filename);
exit(1);
}
}
av_write_header(oc);
write_video_frame(oc,pFrame,index);
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en