[FFmpeg-user] how to copy a video file using ffmpeg
hainei
hainei87 at 163.com
Sat Jun 18 08:13:00 CEST 2011
hi my friends.
i open a video file, then url_fopen a new file, just read the packet and
write the stream packet using the av_read_frame and av_write_frame.
but the program don't work, when the program run to the av_write_frame it
stop.
maybe the pts and dts have not set to the right value, but i don't know how
to set it.
/* 11-24 now, we start to transcode */
if(av_write_header(oFmtctx) < 0)
return -1;
//定位到起始值
av_q.num = 1;
av_q.den = AV_TIME_BASE;
if(video_index>=0){
st= iFmtctx->streams[video_index];
timestamp= av_rescale_q(timestamp, av_q, video_st->time_base);
}
av_seek_frame(iFmtctx, video_index, timestamp, AVSEEK_FLAG_BACKWARD);
while(av_read_frame(iFmtctx,&packet) >= 0)
{
/* if(packet.stream_index == video_index)
{
}
if(packet.stream_index == audio_index)
{
}*/
AVPacket opkt;
av_init_packet(&opkt);
data_buf = packet.data;
data_size = packet.size ;
opkt.stream_index = packet.stream_index ;
/*
if(packet.pts != AV_NOPTS_VALUE)
opkt.pts= av_rescale_q(packet.pts,
iFmtctx->streams[video_index]->time_base,
video_st->time_base);
else
opkt.pts= AV_NOPTS_VALUE;
if (packet.dts == AV_NOPTS_VALUE)
opkt.dts = av_rescale_q(packet.dts, av_q, video_st->time_base);
else
opkt.dts = av_rescale_q(packet.dts,
iFmtctx->streams[video_index]->time_base,
video_st->time_base);
*/
opkt.pts= av_rescale_q(packet.pts,
iFmtctx->streams[video_index]->time_base,
video_st->time_base);
opkt.dts = av_rescale_q(packet.dts,
iFmtctx->streams[video_index]->time_base,
video_st->time_base);
opkt.duration = av_rescale_q(packet.duration,
iFmtctx->streams[video_index]->time_base,
video_st->time_base);
opkt.flags= packet.flags;
opkt.data = data_buf;
opkt.size = data_size;
if (av_write_frame(oFmtctx, &opkt) != 0) {
fprintf(stderr, "Error while writing audio frame\n");
exit(1);
}
av_free_packet(&packet);
}
// write the trailer, if any
av_write_trailer(oFmtctx);
please give me help.
--
View this message in context: http://ffmpeg-users.933282.n4.nabble.com/how-to-copy-a-video-file-using-ffmpeg-tp3607322p3607322.html
Sent from the FFmpeg-users mailing list archive at Nabble.com.
More information about the ffmpeg-user
mailing list