[Libav-user] The stalls when using av_write_frame
松澤要
m.kaname at mail.cansoft.co.jp
Fri Feb 28 05:36:31 CET 2014
Hello. I'm new to libav.
Please teach me why stop.
It's the following situations.
Thanks
Kaname
ffmpeg: ffmpeg-2.1.3
develop os: mac osx
target os: Android armv7-a
AndroidManifest.xml permission: WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE
configure:
--disable-doc \
--disable-ffplay \
--disable-ffserver \
--disable-ffprobe \
--enable-zlib \
--enable-version3 \
--enable-nonfree \
--enable-shared \
--enable-static \
--enable-rdft \
--enable-ffmpeg \
--enable-protocol=file \
--enable-parsers \
--enable-demuxer=aac \
--enable-demuxer=ac3 \
--enable-demuxer=ape \
--enable-demuxer=asf \
--enable-demuxer=flac \
--enable-demuxer=matroska_audio \
--enable-demuxer=mp3 \
--enable-demuxer=mpc \
--enable-demuxer=mov \
--enable-demuxer=mpc8 \
--enable-demuxer=ogg \
--enable-demuxer=tta \
--enable-demuxer=wav \
--enable-demuxer=wv \
--enable-decoder=aac \
--enable-decoder=ac3 \
--enable-decoder=alac \
--enable-decoder=ape \
--enable-decoder=flac \
--enable-decoder=mp1 \
--enable-decoder=mp2 \
--enable-decoder=mp3 \
--enable-decoder=mpc7 \
--enable-decoder=mpc8 \
--enable-decoder=tta \
--enable-decoder=vorbis \
--enable-decoder=wavpack \
--enable-decoder=wmav1 \
--enable-decoder=wmav2 \
--enable-decoder=pcm_alaw \
--enable-decoder=pcm_dvd \
--enable-decoder=pcm_f32be \
--enable-decoder=pcm_f32le \
--enable-decoder=pcm_f64be \
--enable-decoder=pcm_f64le \
--enable-decoder=pcm_s16be \
--enable-decoder=pcm_s16le \
--enable-decoder=pcm_s16le_planar \
--enable-decoder=pcm_s24be \
--enable-decoder=pcm_daud \
--enable-decoder=pcm_s24le \
--enable-decoder=pcm_s32be \
--enable-decoder=pcm_s32le \
--enable-decoder=pcm_s8 \
--enable-decoder=pcm_u16be \
--enable-decoder=pcm_u16le \
--enable-decoder=pcm_u24be \
--enable-decoder=pcm_u24le \
--enable-decoder=rawvideo \
--enable-encoders \
--enable-libmp3lame \
--enable-libspeex \
--enable-libtheora \
--enable-libfaac \
--enable-libvorbis \
--enable-libaacplus \
stop source:
jint copyMovie(JNIEnv *pEnv, jobject pObj, jobject pMainAct, jstring pSrcFileName, jstring pDstFileName)
{
AVFormatContext* inFormatContext = NULL;
AVFormatContext* outFormatContext = NULL;
AVOutputFormat* fmt = NULL;
AVCodecContext* codecCtxIn = NULL;
AVCodecContext* codecCtxOut = NULL;
AVCodec* codecEnc = NULL;
AVCodec* codecDec = NULL;
int i, ret;
int streamIndex = -1;
char* srcMovieFilePath = (char *)(*pEnv)->GetStringUTFChars(pEnv, pSrcFileName, NULL);
char* dstMovieFilePath = (char *)(*pEnv)->GetStringUTFChars(pEnv, pDstFileName, NULL);
av_register_all();
if(avformat_open_input(&inFormatContext, srcMovieFilePath, NULL, NULL) != 0)
goto EXIT_METHOD;
if(avformat_find_stream_info(inFormatContext, NULL) < 0)
goto EXIT_METHOD;
for(i = 0; i < inFormatContext->nb_streams; i++){
if(inFormatContext->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO){
streamIndex = i;
break;
}
}
if(streamIndex < 0)
goto EXIT_METHOD;
codecCtxIn = inFormatContext->streams[streamIndex]->codec;
codecDec = avcodec_find_decoder(codecCtxIn->codec_id);
if(codecDec == NULL)
goto EXIT_METHOD;
if( avcodec_open2(codecCtxIn, codecDec, NULL) < 0 )
goto EXIT_METHOD;
fmt = av_guess_format( NULL, dstMovieFilePath, NULL );
if (!fmt) {
fmt = av_guess_format("mpeg", NULL, NULL);
}
if (!fmt)
goto EXIT_METHOD;
outFormatContext = avformat_alloc_context();
if (!outFormatContext)
goto EXIT_METHOD;
outFormatContext->oformat = fmt;
snprintf(outFormatContext->filename, sizeof(outFormatContext->filename), "%s", dstMovieFilePath);
codecEnc = avcodec_find_encoder( AV_CODEC_ID_MPEG4 );
if(codecEnc == NULL)
goto EXIT_METHOD;
codecCtxOut = avcodec_alloc_context3(codecEnc);
if( codecCtxOut ) {
codecCtxOut->bit_rate = codecCtxIn->bit_rate;
codecCtxOut->width = codecCtxIn->width;
codecCtxOut->height = codecCtxIn->height;
codecCtxOut->pix_fmt = codecCtxIn->pix_fmt;
codecCtxOut->codec_id = codecCtxIn->codec_id;
codecCtxOut->codec_type = codecCtxIn->codec_type;
codecCtxOut->time_base.num = codecCtxIn->time_base.num;
codecCtxOut->time_base.den = codecCtxIn->time_base.den;
codecCtxOut->time_base= codecCtxIn->time_base;
if ( avcodec_open2(codecCtxOut, codecEnc, NULL) >= 0 )
goto EXIT_METHOD;
} else {
goto EXIT_METHOD;
}
if ( !( fmt->flags & AVFMT_NOFILE ) ) {
if ( avio_open( &outFormatContext->pb, dstMovieFilePath, AVIO_FLAG_WRITE ) < 0 )
goto EXIT_METHOD;
}
avformat_write_header( outFormatContext, NULL );
AVPacket packet;
av_init_packet(&packet);
i = 0;
while ( av_read_frame(inFormatContext, &packet) >= 0 )
{
AVStream *inputStream = inFormatContext->streams[i];
if ( packet.stream_index == streamIndex ) {
/* if (av_write_frame(codecCtxOut, &packet) != 0) { // < It's stop when enable here
LOGI( "convert(): error while writing video frame\n" );
}*/
}
i++;
}
// av_write_frame(outFormatContext, NULL); // < It's stop when enable here
// av_write_trailer(outFormatContext); // < It's stop when enable here
EXIT_METHOD:
if ( fmt != NULL && outFormatContext != NULL ) {
if ( !( fmt->flags & AVFMT_NOFILE ) ) {
avio_close(outFormatContext->pb);
}
avformat_free_context(outFormatContext);
}
if ( codecCtxOut != NULL )
avcodec_close(codecCtxOut);
if ( codecCtxIn != NULL )
avcodec_close(codecCtxIn);
if ( inFormatContext != NULL )
avformat_close_input( &inFormatContext );
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20140228/e171171d/attachment.html>
More information about the Libav-user
mailing list