[Libav-user] Decoding Raw Stream crashes

toebsen b toebsen at hotmail.com
Thu Dec 22 19:03:26 EET 2016


can somebody please help me with my problem? I really don't get what I'm doing wrong.

Thanks in advance,
Tobi

Am 16.12.2016 13:21 schrieb toebsen b <toebsen at hotmail.com>:

Hi,


I'm trying to decode a Raw Stream using the ffmpeg API (version 2.8) which is sent over TCP with the following gstreamer pipeline on the server side:

 > nv4l2src name=source ! video/x-raw-yuv,format=(fourcc)I420,width=1552,height=720 ! tcpserversink name=sink port=50000
In this case TCP is necessary because artifacts are not acceptable in this kind of application.

When reading the first frame it crashes in the avcodec_decode_video2 line with an unhandled exception caught 0xC0000005 error.
My program works for other types of streams e.g. H264, only decoding raw streams seems to be the problem.

When I play the stream with ffplay it works just fine. I also tried to put the packet buffer directly into an AVFrame which works, but the packet size changes and the images get distorted over time.
Due to restriction i'm not able to provide an examplatory stream.

How can I decode the raw stream appropriately using avcodec_decode_video2?
What am I doing wrong?

Used Libraries:
- avcodec-57.dll
- avformat-57.dll
- avutil-55.dll
- swresample-2.dll
- swscale-4.dll

best regards,
Tobi

Attached is the code and logs:

The ffmpeg initialization is as follows:
        _avFormatContext = avformat_alloc_context();
av_register_all();
avcodec_register_all();
avformat_network_init();
packet.data = NULL;

_avFormatContext->iformat = av_find_input_format("rawvideo");

AVDictionary *options = NULL;
std::stringstream ss;
ss << _width << "x" << _height;
av_dict_set(&options, "video_size", ss.str().c_str(), 0);
av_dict_set(&options, "pixel_format", "yuv420p", 0);
if( avformat_open_input(&_avFormatContext, _fileToPlay.c_str(), NULL, &options) < 0)
{
return false;
}
av_dict_set(&options, "video_size", ss.str().c_str(), 0);
av_dict_set(&options, "pixel_format", "yuv420p", 0);
if(avformat_find_stream_info(_avFormatContext, &options) < 0)
{
return false;
}

for(size_t i =0; i<_avFormatContext->nb_streams;i++)
{
if(_avFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
video_stream_index = i;
}
}

if( video_stream_index == -1)
{
return false;
}
av_init_packet(&packet);
oc = avformat_alloc_context();
av_read_play(_avFormatContext);
stream = _avFormatContext->streams[video_stream_index];
codec = avcodec_find_encoder_by_name("rawvideo");

if (!codec)
{
return false;
}

_avCodecContext = avcodec_alloc_context3(codec);
if( avcodec_copy_context(_avCodecContext, stream->codec) != 0)
{
return false;
}
_avCodecContext->thread_count = 1;

if (avcodec_open2(_avCodecContext, codec, NULL) < 0)
{
return false;
}

return true;

I'am grabbing the frame with the following code:

AVFrame* pic  = NULL;
uint8_t* picture_buf = NULL;
{
int size = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, _avCodecContext->width, _avCodecContext->height, 1);
picture_buf = (uint8_t*)(av_malloc(size));
pic = av_frame_alloc();
av_image_fill_arrays(pic->data, pic->linesize, picture_buf, AV_PIX_FMT_YUV420P, _avCodecContext->width, _avCodecContext->height, 1);
}

{ // main loop for grabbing
int got_frame = -1;
while(av_read_frame(_avFormatContext, &packet) >=0 && this->_bThreadRunning == true)
{
if(packet.stream_index == video_stream_index)
{
av_pkt_dump_log2(NULL, AV_LOG_TRACE, &packet, 0, stream);
int bytesDecoded  = avcodec_decode_video2(_avCodecContext, pic, &got_frame, &packet);



Log:
Initialisation:
FFMPEG - Before avformat_find_stream_info() pos: 0 bytes read:14600 seeks:0
FFMPEG - All info found
FFMPEG - 0: start_time: 0.000 duration: -9223372036854.775
FFMPEG - stream: start_time: 0.000 duration: -9223372036854.775 bitrate=335232 kb/s
FFMPEG - After avformat_find_stream_info() pos: 1676160 bytes read:1690680 seeks:0 frames:1
FFMPEG - Input #0, rawvideo, from 'tcp://192.168.1.200:50000':
FFMPEG -   Duration:
FFMPEG - N/A
FFMPEG - , start:
FFMPEG - 0.000000
FFMPEG - , bitrate:
FFMPEG - 335232 kb/s
FFMPEG -
FFMPEG -     Stream #0:0
FFMPEG - , 1, 1/25
FFMPEG - : Video: rawvideo (I420 / 0x30323449), yuv420p, 1552x720, 335232 kb/s
FFMPEG - ,
FFMPEG - 25 tbr,
FFMPEG - 25 tbn,
FFMPEG - 25 tbc
FFMPEG -
Packet information:
FFMPEG - stream #0:
FFMPEG -   keyframe=1
FFMPEG -   duration=0.040
FFMPEG -   dts=
FFMPEG - 0.000
FFMPEG -   pts=
FFMPEG - 0.000
FFMPEG -
FFMPEG -   size=1676160


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20161222/8e87bc6f/attachment.html>


More information about the Libav-user mailing list