📄 mp4.c
字号:
} break; } case( VLC_FOURCC( 's', '2', '6', '3' ) ): p_track->fmt.i_codec = VLC_FOURCC( 'h', '2', '6', '3' ); break; case( VLC_FOURCC( 't', 'e', 'x', 't' ) ): case( VLC_FOURCC( 't', 'x', '3', 'g' ) ): p_track->fmt.i_codec = VLC_FOURCC( 's', 'u', 'b', 't' ); /* FIXME: Not true, could be UTF-16 with a Byte Order Mark (0xfeff) */ /* FIXME UTF-8 doesn't work here ? */ if( p_track->b_mac_encoding ) p_track->fmt.subs.psz_encoding = strdup( "MAC" ); else p_track->fmt.subs.psz_encoding = strdup( "UTF-8" ); break; case VLC_FOURCC('y','v','1','2'): p_track->fmt.i_codec = VLC_FOURCC('Y','V','1','2'); break; case VLC_FOURCC('y','u','v','2'): p_track->fmt.i_codec = VLC_FOURCC('Y','U','Y','2'); break; case VLC_FOURCC('i','n','2','4'): /* in in24/in32 there's enda-atom to tell it's little-endian (if present) */ if( ( MP4_BoxGet( p_sample, "wave/enda" ) ) || ( MP4_BoxGet( p_sample, "enda" ) ) ) { p_track->fmt.i_codec = VLC_FOURCC('4','2','n','i'); } else { p_track->fmt.i_codec = p_sample->i_type; } break; default: p_track->fmt.i_codec = p_sample->i_type; break; } /* now see if esds is present and if so create a data packet with decoder_specific_info */#define p_decconfig p_esds->data.p_esds->es_descriptor.p_decConfigDescr if( ( ( p_esds = MP4_BoxGet( p_sample, "esds" ) ) || ( p_esds = MP4_BoxGet( p_sample, "wave/esds" ) ) )&& ( p_esds->data.p_esds )&& ( p_decconfig ) ) { /* First update information based on i_objectTypeIndication */ switch( p_decconfig->i_objectTypeIndication ) { case( 0x20 ): /* MPEG4 VIDEO */ p_track->fmt.i_codec = VLC_FOURCC( 'm','p','4','v' ); break; case( 0x40): p_track->fmt.i_codec = VLC_FOURCC( 'm','p','4','a' ); break; case( 0x60): case( 0x61): case( 0x62): case( 0x63): case( 0x64): case( 0x65): /* MPEG2 video */ p_track->fmt.i_codec = VLC_FOURCC( 'm','p','g','v' ); break; /* Theses are MPEG2-AAC */ case( 0x66): /* main profile */ case( 0x67): /* Low complexity profile */ case( 0x68): /* Scaleable Sampling rate profile */ p_track->fmt.i_codec = VLC_FOURCC( 'm','p','4','a' ); break; /* true MPEG 2 audio */ case( 0x69): p_track->fmt.i_codec = VLC_FOURCC( 'm','p','g','a' ); break; case( 0x6a): /* MPEG1 video */ p_track->fmt.i_codec = VLC_FOURCC( 'm','p','g','v' ); break; case( 0x6b): /* MPEG1 audio */ p_track->fmt.i_codec = VLC_FOURCC( 'm','p','g','a' ); break; case( 0x6c ): /* jpeg */ p_track->fmt.i_codec = VLC_FOURCC( 'j','p','e','g' ); break; case( 0x6d ): /* png */ p_track->fmt.i_codec = VLC_FOURCC( 'p','n','g',' ' ); break; case( 0x6e ): /* jpeg200 */ p_track->fmt.i_codec = VLC_FOURCC( 'M','J','2','C' ); break; case( 0xa3 ): /* vc1 */ p_track->fmt.i_codec = VLC_FOURCC( 'W','V','C','1' ); break; /* Private ID */ case( 0xe0 ): /* NeroDigital: dvd subs */ if( p_track->fmt.i_cat == SPU_ES ) { p_track->fmt.i_codec = VLC_FOURCC( 's','p','u',' ' ); if( p_track->i_width > 0 ) p_track->fmt.subs.spu.i_original_frame_width = p_track->i_width; if( p_track->i_height > 0 ) p_track->fmt.subs.spu.i_original_frame_height = p_track->i_height; break; } case( 0xe1 ): /* QCelp for 3gp */ if( p_track->fmt.i_cat == AUDIO_ES ) { p_track->fmt.i_codec = VLC_FOURCC( 'Q','c','l','p' ); } break; /* Fallback */ default: /* Unknown entry, but don't touch i_fourcc */ msg_Warn( p_demux, "unknown objectTypeIndication(0x%x) (Track[ID 0x%x])", p_decconfig->i_objectTypeIndication, p_track->i_track_ID ); break; } p_track->fmt.i_extra = p_decconfig->i_decoder_specific_info_len; if( p_track->fmt.i_extra > 0 ) { p_track->fmt.p_extra = malloc( p_track->fmt.i_extra ); memcpy( p_track->fmt.p_extra, p_decconfig->p_decoder_specific_info, p_track->fmt.i_extra ); } } else { switch( p_sample->i_type ) { /* qt decoder, send the complete chunk */ case VLC_FOURCC ('h', 'd', 'v', '1'): // HDV 720p30 case VLC_FOURCC ('h', 'd', 'v', '2'): // HDV 1080i60 case VLC_FOURCC ('h', 'd', 'v', '3'): // HDV 1080i50 case VLC_FOURCC ('h', 'd', 'v', '5'): // HDV 720p25 case VLC_FOURCC ('m', 'x', '5', 'n'): // MPEG2 IMX NTSC 525/60 50mb/s produced by FCP case VLC_FOURCC ('m', 'x', '5', 'p'): // MPEG2 IMX PAL 625/60 50mb/s produced by FCP case VLC_FOURCC ('m', 'x', '4', 'n'): // MPEG2 IMX NTSC 525/60 40mb/s produced by FCP case VLC_FOURCC ('m', 'x', '4', 'p'): // MPEG2 IMX PAL 625/60 40mb/s produced by FCP case VLC_FOURCC ('m', 'x', '3', 'n'): // MPEG2 IMX NTSC 525/60 30mb/s produced by FCP case VLC_FOURCC ('m', 'x', '3', 'p'): // MPEG2 IMX PAL 625/50 30mb/s produced by FCP case VLC_FOURCC ('x', 'd', 'v', '2'): // XDCAM HD 1080i60 case VLC_FOURCC ('A', 'V', 'm', 'p'): // AVID IMX PAL p_track->fmt.i_codec = VLC_FOURCC( 'm','p','g','v' ); break; /* qt decoder, send the complete chunk */ case VLC_FOURCC( 'S', 'V', 'Q', '3' ): case VLC_FOURCC( 'S', 'V', 'Q', '1' ): case VLC_FOURCC( 'V', 'P', '3', '1' ): case VLC_FOURCC( '3', 'I', 'V', '1' ): case VLC_FOURCC( 'Z', 'y', 'G', 'o' ): p_track->fmt.i_extra = p_sample->data.p_sample_vide->i_qt_image_description; if( p_track->fmt.i_extra > 0 ) { p_track->fmt.p_extra = malloc( p_track->fmt.i_extra ); memcpy( p_track->fmt.p_extra, p_sample->data.p_sample_vide->p_qt_image_description, p_track->fmt.i_extra); } break; case VLC_FOURCC( 'Q', 'D', 'M', 'C' ): case VLC_FOURCC( 'Q', 'D', 'M', '2' ): case VLC_FOURCC( 'Q', 'c', 'l', 'p' ): case VLC_FOURCC( 's', 'a', 'm', 'r' ): case VLC_FOURCC( 'a', 'l', 'a', 'c' ): p_track->fmt.i_extra = p_sample->data.p_sample_soun->i_qt_description; if( p_track->fmt.i_extra > 0 ) { p_track->fmt.p_extra = malloc( p_track->fmt.i_extra ); memcpy( p_track->fmt.p_extra, p_sample->data.p_sample_soun->p_qt_description, p_track->fmt.i_extra); } break; /* avc1: send avcC (h264 without annexe B, ie without start code)*/ case VLC_FOURCC( 'a', 'v', 'c', '1' ): { MP4_Box_t *p_avcC = MP4_BoxGet( p_sample, "avcC" ); if( p_avcC ) { p_track->fmt.i_extra = p_avcC->data.p_avcC->i_avcC; p_track->fmt.p_extra = malloc( p_avcC->data.p_avcC->i_avcC ); memcpy( p_track->fmt.p_extra, p_avcC->data.p_avcC->p_avcC, p_track->fmt.i_extra ); } else { msg_Err( p_demux, "missing avcC" ); } break; } case VLC_FOURCC('m','s',0x00,0x02): case VLC_FOURCC('m','s',0x00,0x11): p_track->fmt.audio.i_blockalign = p_sample->data.p_sample_soun->i_bytes_per_frame; break; default: break; } }#undef p_decconfig /* some last initialisation */ switch( p_track->fmt.i_cat ) { case VIDEO_ES: p_track->fmt.video.i_width = p_sample->data.p_sample_vide->i_width; p_track->fmt.video.i_height = p_sample->data.p_sample_vide->i_height; p_track->fmt.video.i_bits_per_pixel = p_sample->data.p_sample_vide->i_depth; /* fall on display size */ if( p_track->fmt.video.i_width <= 0 ) p_track->fmt.video.i_width = p_track->i_width; if( p_track->fmt.video.i_height <= 0 ) p_track->fmt.video.i_height = p_track->i_height; /* Find out apect ratio from display size */ if( p_track->i_width > 0 && p_track->i_height > 0 && /* Work-around buggy muxed files */ p_sample->data.p_sample_vide->i_width != p_track->i_width ) p_track->fmt.video.i_aspect = VOUT_ASPECT_FACTOR * p_track->i_width / p_track->i_height; /* Support for cropping (eg. in H263 files) */ p_track->fmt.video.i_visible_width = p_track->fmt.video.i_width; p_track->fmt.video.i_visible_height = p_track->fmt.video.i_height; /* Frame rate */ p_track->fmt.video.i_frame_rate = p_track->i_timescale; p_track->fmt.video.i_frame_rate_base = 1; if( p_track->fmt.video.i_frame_rate && (p_box = MP4_BoxGet( p_track->p_stbl, "stts" )) && p_box->data.p_stts->i_entry_count >= 1 ) { p_track->fmt.video.i_frame_rate_base = p_box->data.p_stts->i_sample_delta[0]; } break; case AUDIO_ES: p_track->fmt.audio.i_channels = p_sample->data.p_sample_soun->i_channelcount; p_track->fmt.audio.i_rate = p_sample->data.p_sample_soun->i_sampleratehi; p_track->fmt.i_bitrate = p_sample->data.p_sample_soun->i_channelcount * p_sample->data.p_sample_soun->i_sampleratehi * p_sample->data.p_sample_soun->i_samplesize; p_track->fmt.audio.i_bitspersample = p_sample->data.p_sample_soun->i_samplesize; if( p_track->i_sample_size != 0 && p_sample->data.p_sample_soun->i_qt_version == 1 && p_sample->data.p_sample_soun->i_sample_per_packet <= 0 ) { msg_Err( p_demux, "Invalid sample per packet value for qt_version 1" ); return VLC_EGENERIC; } break; default: break; } if( pp_es ) *pp_es = es_out_Add( p_demux->out, &p_track->fmt ); return VLC_SUCCESS;}/* given a time it return sample/chunk * it also update elst field of the track */static int TrackTimeToSampleChunk( demux_t *p_demux, mp4_track_t *p_track, int64_t i_start, uint32_t *pi_chunk, uint32_t *pi_sample ){ demux_sys_t *p_sys = p_demux->p_sys; MP4_Box_t *p_stss; uint64_t i_dts; unsigned int i_sample; unsigned int i_chunk; int i_index; /* FIXME see if it's needed to check p_track->i_chunk_count */ if( p_track->i_chunk_count == 0 ) return( VLC_EGENERIC ); /* handle elst (find the correct one) */ MP4_TrackSetELST( p_demux, p_track, i_start ); if( p_track->p_elst && p_track->p_elst->data.p_elst->i_entry_count > 0 ) { MP4_Box_data_elst_t *elst = p_track->p_elst->data.p_elst; int64_t i_mvt= i_start * p_sys->i_timescale / (int64_t)1000000; /* now calculate i_start for this elst */ /* offset */ i_start -= p_track->i_elst_time * INT64_C(1000000) / p_sys->i_timescale; if( i_start < 0 ) { *pi_chunk = 0; *pi_sample= 0; return VLC_SUCCESS; } /* to track time scale */ i_start = i_start * p_track->i_timescale / (int64_t)1000000; /* add elst offset */ if( ( elst->i_media_rate_integer[p_track->i_elst] > 0 || elst->i_media_rate_fraction[p_track->i_elst] > 0 ) && elst->i_media_time[p_track->i_elst] > 0 ) { i_start += elst->i_media_time[p_track->i_elst]; } msg_Dbg( p_demux, "elst (%d) gives %"PRId64"ms (movie)-> %"PRId64 "ms (track)", p_track->i_elst, i_mvt * 1000 / p_sys->i_timescale, i_start * 1000 / p_track->i_timescale ); } else { /* convert absolute time to in timescale unit */ i_start = i_start * p_track->i_timescale / (int64_t)1000000; } /* we start from sample 0/chunk 0, hope it won't take too much time */ /* *** find good chunk *** */ for( i_chunk = 0; ; i_chunk++ ) { if( i_chunk + 1 >= p_track->i_chunk_count ) { /* at the end and can't check if i_start in this chunk, it will be check while searching i_sample */ i_chunk = p_track->i_chunk_count - 1; break; } if( (uint64_t)i_start >= p_track->chunk[i_chunk].i_first_dts && (uint64_t)i_start < p_track->chunk[i_chunk + 1].i_first_dts ) { break; } } /* *** find sample in the chunk *** */ i_sample = p_track->chunk[i_chunk].i_sample_first; i_dts = p_track->chunk[i_chunk].i_first_dts; for( i_index = 0; i_sample < p_track->chunk[i_chunk].i_sample_count; ) { if( i_dts + p_track->chunk[i_chunk].p_sample_count_dts[i_index] * p_track->chunk[i_chunk].p_sample_delta_dts[i_index] < (uint64_t)i_start ) { i_dts += p_track->chunk[i_chunk].p_sample_count_dts[i_index] * p_track->chunk[i_chunk].p_sample_delta_dts[i_index]; i_sample += p_track->chunk[i_chunk].p_sample_count_dts[i_index]; i_index++; } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -