MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / extract_mpeg4_header

Function extract_mpeg4_header

ffserver.c:3546–3592  ·  view source on GitHub ↗

specific mpeg4 handling : we extract the raw parameters */

Source from the content-addressed store, hash-verified

3544
3545/* specific mpeg4 handling : we extract the raw parameters */
3546static void extract_mpeg4_header(AVFormatContext *infile)
3547{
3548 int mpeg4_count, i, size;
3549 AVPacket pkt;
3550 AVStream *st;
3551 const uint8_t *p;
3552
3553 mpeg4_count = 0;
3554 for(i=0;i<infile->nb_streams;i++) {
3555 st = infile->streams[i];
3556 if (st->codec->codec_id == CODEC_ID_MPEG4 &&
3557 st->codec->extradata_size == 0) {
3558 mpeg4_count++;
3559 }
3560 }
3561 if (!mpeg4_count)
3562 return;
3563
3564 printf("MPEG4 without extra data: trying to find header in %s\n", infile->filename);
3565 while (mpeg4_count > 0) {
3566 if (av_read_packet(infile, &pkt) < 0)
3567 break;
3568 st = infile->streams[pkt.stream_index];
3569 if (st->codec->codec_id == CODEC_ID_MPEG4 &&
3570 st->codec->extradata_size == 0) {
3571 av_freep(&st->codec->extradata);
3572 /* fill extradata with the header */
3573 /* XXX: we make hard suppositions here ! */
3574 p = pkt.data;
3575 while (p < pkt.data + pkt.size - 4) {
3576 /* stop when vop header is found */
3577 if (p[0] == 0x00 && p[1] == 0x00 &&
3578 p[2] == 0x01 && p[3] == 0xb6) {
3579 size = p - pkt.data;
3580 // av_hex_dump_log(infile, AV_LOG_DEBUG, pkt.data, size);
3581 st->codec->extradata = av_malloc(size);
3582 st->codec->extradata_size = size;
3583 memcpy(st->codec->extradata, pkt.data, size);
3584 break;
3585 }
3586 p++;
3587 }
3588 mpeg4_count--;
3589 }
3590 av_free_packet(&pkt);
3591 }
3592}
3593
3594/* compute the needed AVStream for each file */
3595static void build_file_streams(void)

Callers 1

build_file_streamsFunction · 0.85

Calls 4

av_read_packetFunction · 0.85
av_freepFunction · 0.85
av_mallocFunction · 0.85
av_free_packetFunction · 0.85

Tested by

no test coverage detected