avcodec library not extracting all the frames from a video
up vote
0
down vote
favorite
I have written a library that could be used with python to extract frames from a video in a buffer for some processing. I used the examples from the ffmpeg to build my library using libavcodec.
This and seems to be working fine for most of the videos. But I see on some videos where my library does not extract all the frames (way less than the FPS).
It seems like somehow the packets might be out of order and docoder is not able to handle it. I keep getting a lot of the following errors
pid=100 pes_code=0x1e0
nal_unit_type: 9, nal_ref_idc: 0
nal_unit_type: 1, nal_ref_idc: 2
deblocking_filter_idc 7 out of range
decode_slice_header error
no frame!
I use the following steps to setup the decoder.
//open input file, allocate context
if ((ret = avformat_open_input(&format_ctx, in_filename, 0, 0)) < 0) {
PyErr_SetString(ExtractorError, "Could not open input file!");
goto end;
}
if ((ret = avformat_find_stream_info(format_ctx, 0)) < 0) {
PyErr_SetString(ExtractorError, "Failed to retrieve input stream information!");
goto end;
}
av_dump_format(format_ctx, 0, in_filename, 0);
// Get the video index from the stream
for(int i=0; i<format_ctx->nb_streams ;i++ )
{
if( format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO )
{
video_stream_index = i;
break;
}
}
/* if video stream not availabe */
if((video_stream_index) == -1)
{
PyErr_SetString(ExtractorError, "video stream to retreive fps is not found!");
return NULL;
}
long duration = format_ctx->duration + (format_ctx->duration <= INT64_MAX - 5000 ? 5000 : 0);
float duration_in_secs = (float)duration / AV_TIME_BASE;
stream_mapping_size = format_ctx->nb_streams;
stream_mapping = av_mallocz_array(stream_mapping_size, sizeof(*stream_mapping));
if (!stream_mapping) {
ret = AVERROR(ENOMEM);
goto end;
}
AVCodec *pCodec = NULL;
AVCodecParameters *in_codecpar = NULL;
for (i = 0; i < format_ctx->nb_streams; i++) {
AVStream *in_stream = format_ctx->streams[i];
in_codecpar = in_stream->codecpar;
if (in_codecpar->codec_type != AVMEDIA_TYPE_AUDIO &&
in_codecpar->codec_type != AVMEDIA_TYPE_VIDEO &&
in_codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) {
stream_mapping[i] = -1;
continue;
}
if (in_codecpar->codec_type == AVMEDIA_TYPE_VIDEO){
pCodec = avcodec_find_decoder(in_codecpar->codec_id);
stream_mapping[i] = stream_index++;
break;
}
}
if(!pCodec){
PyErr_SetString(ExtractorError, "error, no pCodec!");
return NULL;
}
// convert CodecParam to CodecCtx
AVCodecContext *pCodecCtx = avcodec_alloc_context3(pCodec);
if (!pCodecCtx) {
PyErr_SetString(ExtractorError, "Failed to convert codecParam to CodecCtx!");
return NULL;
}
ret = avcodec_parameters_to_context(pCodecCtx, in_codecpar);
if (ret < 0)
goto end;
//open video decoder
if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0)
{
logging("EXTRACTOR: failed to open codec through avcodec_open2n");
return NULL;
}
In order to test it I used the following command from ffmpeg to extract frames from the same video and it worked fine.
ffmpeg -i ~/thuuz/extractor/03000.ts -f image2 -qscale:v 7 ffmpeg-detect--%03d.jpg -hide_banner -v quiet
Am I not passing the right codec params? Please let me know some inputs on how to debug this issue.
Thanks a lot.
linux video ffmpeg video-encoding video-codecs
migrated from superuser.com Nov 22 at 7:14
This question came from our site for computer enthusiasts and power users.
add a comment |
up vote
0
down vote
favorite
I have written a library that could be used with python to extract frames from a video in a buffer for some processing. I used the examples from the ffmpeg to build my library using libavcodec.
This and seems to be working fine for most of the videos. But I see on some videos where my library does not extract all the frames (way less than the FPS).
It seems like somehow the packets might be out of order and docoder is not able to handle it. I keep getting a lot of the following errors
pid=100 pes_code=0x1e0
nal_unit_type: 9, nal_ref_idc: 0
nal_unit_type: 1, nal_ref_idc: 2
deblocking_filter_idc 7 out of range
decode_slice_header error
no frame!
I use the following steps to setup the decoder.
//open input file, allocate context
if ((ret = avformat_open_input(&format_ctx, in_filename, 0, 0)) < 0) {
PyErr_SetString(ExtractorError, "Could not open input file!");
goto end;
}
if ((ret = avformat_find_stream_info(format_ctx, 0)) < 0) {
PyErr_SetString(ExtractorError, "Failed to retrieve input stream information!");
goto end;
}
av_dump_format(format_ctx, 0, in_filename, 0);
// Get the video index from the stream
for(int i=0; i<format_ctx->nb_streams ;i++ )
{
if( format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO )
{
video_stream_index = i;
break;
}
}
/* if video stream not availabe */
if((video_stream_index) == -1)
{
PyErr_SetString(ExtractorError, "video stream to retreive fps is not found!");
return NULL;
}
long duration = format_ctx->duration + (format_ctx->duration <= INT64_MAX - 5000 ? 5000 : 0);
float duration_in_secs = (float)duration / AV_TIME_BASE;
stream_mapping_size = format_ctx->nb_streams;
stream_mapping = av_mallocz_array(stream_mapping_size, sizeof(*stream_mapping));
if (!stream_mapping) {
ret = AVERROR(ENOMEM);
goto end;
}
AVCodec *pCodec = NULL;
AVCodecParameters *in_codecpar = NULL;
for (i = 0; i < format_ctx->nb_streams; i++) {
AVStream *in_stream = format_ctx->streams[i];
in_codecpar = in_stream->codecpar;
if (in_codecpar->codec_type != AVMEDIA_TYPE_AUDIO &&
in_codecpar->codec_type != AVMEDIA_TYPE_VIDEO &&
in_codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) {
stream_mapping[i] = -1;
continue;
}
if (in_codecpar->codec_type == AVMEDIA_TYPE_VIDEO){
pCodec = avcodec_find_decoder(in_codecpar->codec_id);
stream_mapping[i] = stream_index++;
break;
}
}
if(!pCodec){
PyErr_SetString(ExtractorError, "error, no pCodec!");
return NULL;
}
// convert CodecParam to CodecCtx
AVCodecContext *pCodecCtx = avcodec_alloc_context3(pCodec);
if (!pCodecCtx) {
PyErr_SetString(ExtractorError, "Failed to convert codecParam to CodecCtx!");
return NULL;
}
ret = avcodec_parameters_to_context(pCodecCtx, in_codecpar);
if (ret < 0)
goto end;
//open video decoder
if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0)
{
logging("EXTRACTOR: failed to open codec through avcodec_open2n");
return NULL;
}
In order to test it I used the following command from ffmpeg to extract frames from the same video and it worked fine.
ffmpeg -i ~/thuuz/extractor/03000.ts -f image2 -qscale:v 7 ffmpeg-detect--%03d.jpg -hide_banner -v quiet
Am I not passing the right codec params? Please let me know some inputs on how to debug this issue.
Thanks a lot.
linux video ffmpeg video-encoding video-codecs
migrated from superuser.com Nov 22 at 7:14
This question came from our site for computer enthusiasts and power users.
you posted the code to open the clip but you have problems decoding the stream... Are you sure that your problem is with the opening process? Does it work with the unmodified examples of ffmpeg?
– Harry
Nov 23 at 22:38
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have written a library that could be used with python to extract frames from a video in a buffer for some processing. I used the examples from the ffmpeg to build my library using libavcodec.
This and seems to be working fine for most of the videos. But I see on some videos where my library does not extract all the frames (way less than the FPS).
It seems like somehow the packets might be out of order and docoder is not able to handle it. I keep getting a lot of the following errors
pid=100 pes_code=0x1e0
nal_unit_type: 9, nal_ref_idc: 0
nal_unit_type: 1, nal_ref_idc: 2
deblocking_filter_idc 7 out of range
decode_slice_header error
no frame!
I use the following steps to setup the decoder.
//open input file, allocate context
if ((ret = avformat_open_input(&format_ctx, in_filename, 0, 0)) < 0) {
PyErr_SetString(ExtractorError, "Could not open input file!");
goto end;
}
if ((ret = avformat_find_stream_info(format_ctx, 0)) < 0) {
PyErr_SetString(ExtractorError, "Failed to retrieve input stream information!");
goto end;
}
av_dump_format(format_ctx, 0, in_filename, 0);
// Get the video index from the stream
for(int i=0; i<format_ctx->nb_streams ;i++ )
{
if( format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO )
{
video_stream_index = i;
break;
}
}
/* if video stream not availabe */
if((video_stream_index) == -1)
{
PyErr_SetString(ExtractorError, "video stream to retreive fps is not found!");
return NULL;
}
long duration = format_ctx->duration + (format_ctx->duration <= INT64_MAX - 5000 ? 5000 : 0);
float duration_in_secs = (float)duration / AV_TIME_BASE;
stream_mapping_size = format_ctx->nb_streams;
stream_mapping = av_mallocz_array(stream_mapping_size, sizeof(*stream_mapping));
if (!stream_mapping) {
ret = AVERROR(ENOMEM);
goto end;
}
AVCodec *pCodec = NULL;
AVCodecParameters *in_codecpar = NULL;
for (i = 0; i < format_ctx->nb_streams; i++) {
AVStream *in_stream = format_ctx->streams[i];
in_codecpar = in_stream->codecpar;
if (in_codecpar->codec_type != AVMEDIA_TYPE_AUDIO &&
in_codecpar->codec_type != AVMEDIA_TYPE_VIDEO &&
in_codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) {
stream_mapping[i] = -1;
continue;
}
if (in_codecpar->codec_type == AVMEDIA_TYPE_VIDEO){
pCodec = avcodec_find_decoder(in_codecpar->codec_id);
stream_mapping[i] = stream_index++;
break;
}
}
if(!pCodec){
PyErr_SetString(ExtractorError, "error, no pCodec!");
return NULL;
}
// convert CodecParam to CodecCtx
AVCodecContext *pCodecCtx = avcodec_alloc_context3(pCodec);
if (!pCodecCtx) {
PyErr_SetString(ExtractorError, "Failed to convert codecParam to CodecCtx!");
return NULL;
}
ret = avcodec_parameters_to_context(pCodecCtx, in_codecpar);
if (ret < 0)
goto end;
//open video decoder
if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0)
{
logging("EXTRACTOR: failed to open codec through avcodec_open2n");
return NULL;
}
In order to test it I used the following command from ffmpeg to extract frames from the same video and it worked fine.
ffmpeg -i ~/thuuz/extractor/03000.ts -f image2 -qscale:v 7 ffmpeg-detect--%03d.jpg -hide_banner -v quiet
Am I not passing the right codec params? Please let me know some inputs on how to debug this issue.
Thanks a lot.
linux video ffmpeg video-encoding video-codecs
I have written a library that could be used with python to extract frames from a video in a buffer for some processing. I used the examples from the ffmpeg to build my library using libavcodec.
This and seems to be working fine for most of the videos. But I see on some videos where my library does not extract all the frames (way less than the FPS).
It seems like somehow the packets might be out of order and docoder is not able to handle it. I keep getting a lot of the following errors
pid=100 pes_code=0x1e0
nal_unit_type: 9, nal_ref_idc: 0
nal_unit_type: 1, nal_ref_idc: 2
deblocking_filter_idc 7 out of range
decode_slice_header error
no frame!
I use the following steps to setup the decoder.
//open input file, allocate context
if ((ret = avformat_open_input(&format_ctx, in_filename, 0, 0)) < 0) {
PyErr_SetString(ExtractorError, "Could not open input file!");
goto end;
}
if ((ret = avformat_find_stream_info(format_ctx, 0)) < 0) {
PyErr_SetString(ExtractorError, "Failed to retrieve input stream information!");
goto end;
}
av_dump_format(format_ctx, 0, in_filename, 0);
// Get the video index from the stream
for(int i=0; i<format_ctx->nb_streams ;i++ )
{
if( format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO )
{
video_stream_index = i;
break;
}
}
/* if video stream not availabe */
if((video_stream_index) == -1)
{
PyErr_SetString(ExtractorError, "video stream to retreive fps is not found!");
return NULL;
}
long duration = format_ctx->duration + (format_ctx->duration <= INT64_MAX - 5000 ? 5000 : 0);
float duration_in_secs = (float)duration / AV_TIME_BASE;
stream_mapping_size = format_ctx->nb_streams;
stream_mapping = av_mallocz_array(stream_mapping_size, sizeof(*stream_mapping));
if (!stream_mapping) {
ret = AVERROR(ENOMEM);
goto end;
}
AVCodec *pCodec = NULL;
AVCodecParameters *in_codecpar = NULL;
for (i = 0; i < format_ctx->nb_streams; i++) {
AVStream *in_stream = format_ctx->streams[i];
in_codecpar = in_stream->codecpar;
if (in_codecpar->codec_type != AVMEDIA_TYPE_AUDIO &&
in_codecpar->codec_type != AVMEDIA_TYPE_VIDEO &&
in_codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) {
stream_mapping[i] = -1;
continue;
}
if (in_codecpar->codec_type == AVMEDIA_TYPE_VIDEO){
pCodec = avcodec_find_decoder(in_codecpar->codec_id);
stream_mapping[i] = stream_index++;
break;
}
}
if(!pCodec){
PyErr_SetString(ExtractorError, "error, no pCodec!");
return NULL;
}
// convert CodecParam to CodecCtx
AVCodecContext *pCodecCtx = avcodec_alloc_context3(pCodec);
if (!pCodecCtx) {
PyErr_SetString(ExtractorError, "Failed to convert codecParam to CodecCtx!");
return NULL;
}
ret = avcodec_parameters_to_context(pCodecCtx, in_codecpar);
if (ret < 0)
goto end;
//open video decoder
if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0)
{
logging("EXTRACTOR: failed to open codec through avcodec_open2n");
return NULL;
}
In order to test it I used the following command from ffmpeg to extract frames from the same video and it worked fine.
ffmpeg -i ~/thuuz/extractor/03000.ts -f image2 -qscale:v 7 ffmpeg-detect--%03d.jpg -hide_banner -v quiet
Am I not passing the right codec params? Please let me know some inputs on how to debug this issue.
Thanks a lot.
linux video ffmpeg video-encoding video-codecs
linux video ffmpeg video-encoding video-codecs
asked Nov 21 at 23:17
Guru Govindan
7941820
7941820
migrated from superuser.com Nov 22 at 7:14
This question came from our site for computer enthusiasts and power users.
migrated from superuser.com Nov 22 at 7:14
This question came from our site for computer enthusiasts and power users.
you posted the code to open the clip but you have problems decoding the stream... Are you sure that your problem is with the opening process? Does it work with the unmodified examples of ffmpeg?
– Harry
Nov 23 at 22:38
add a comment |
you posted the code to open the clip but you have problems decoding the stream... Are you sure that your problem is with the opening process? Does it work with the unmodified examples of ffmpeg?
– Harry
Nov 23 at 22:38
you posted the code to open the clip but you have problems decoding the stream... Are you sure that your problem is with the opening process? Does it work with the unmodified examples of ffmpeg?
– Harry
Nov 23 at 22:38
you posted the code to open the clip but you have problems decoding the stream... Are you sure that your problem is with the opening process? Does it work with the unmodified examples of ffmpeg?
– Harry
Nov 23 at 22:38
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425636%2favcodec-library-not-extracting-all-the-frames-from-a-video%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
you posted the code to open the clip but you have problems decoding the stream... Are you sure that your problem is with the opening process? Does it work with the unmodified examples of ffmpeg?
– Harry
Nov 23 at 22:38