Skip to content

Commit d262e40

Browse files
committed
Merge branch 'alastor0325-master'
2 parents eb4a65b + 9c72671 commit d262e40

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed

mp4parse/src/boxes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ box_database!(
146146
AVCConfigurationBox 0x6176_6343, // "avcC"
147147
H263SampleEntry 0x7332_3633, // "s263"
148148
H263SpecificBox 0x6432_3633, // "d263"
149+
HEV1SampleEntry 0x6865_7631, // "hev1"
150+
HVC1SampleEntry 0x6876_6331, // "hvc1"
151+
HEVCConfigurationBox 0x6876_6343, // "hvcC"
149152
MP4AudioSampleEntry 0x6d70_3461, // "mp4a"
150153
MP4VideoSampleEntry 0x6d70_3476, // "mp4v"
151154
#[cfg(feature = "3gpp")]

mp4parse/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,7 @@ pub enum VideoCodecSpecific {
11611161
AV1Config(AV1ConfigBox),
11621162
ESDSConfig(TryVec<u8>),
11631163
H263Config(TryVec<u8>),
1164+
HEVCConfig(TryVec<u8>),
11641165
}
11651166

11661167
#[derive(Debug)]
@@ -2060,6 +2061,7 @@ pub enum CodecType {
20602061
LPCM, // QT
20612062
ALAC,
20622063
H263,
2064+
HEVC, // 23008-2
20632065
#[cfg(feature = "3gpp")]
20642066
AMRNB,
20652067
#[cfg(feature = "3gpp")]
@@ -5456,6 +5458,7 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleEntry>
54565458
BoxType::AV1SampleEntry => CodecType::AV1,
54575459
BoxType::ProtectedVisualSampleEntry => CodecType::EncryptedVideo,
54585460
BoxType::H263SampleEntry => CodecType::H263,
5461+
BoxType::HEV1SampleEntry | BoxType::HVC1SampleEntry => CodecType::HEVC,
54595462
_ => {
54605463
debug!("Unsupported video codec, box {:?} found", name);
54615464
CodecType::Unknown
@@ -5567,6 +5570,23 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleEntry>
55675570
debug!("{:?} (sinf)", sinf);
55685571
protection_info.push(sinf)?;
55695572
}
5573+
BoxType::HEVCConfigurationBox => {
5574+
if (name != BoxType::HEV1SampleEntry
5575+
&& name != BoxType::HVC1SampleEntry
5576+
&& name != BoxType::ProtectedVisualSampleEntry)
5577+
|| codec_specific.is_some()
5578+
{
5579+
return Status::StsdBadVideoSampleEntry.into();
5580+
}
5581+
let hvcc_size = b
5582+
.head
5583+
.size
5584+
.checked_sub(b.head.offset)
5585+
.expect("offset invalid");
5586+
let hvcc = read_buf(&mut b.content, hvcc_size)?;
5587+
debug!("{:?} (hvcc)", hvcc);
5588+
codec_specific = Some(VideoCodecSpecific::HEVCConfig(hvcc));
5589+
}
55705590
_ => {
55715591
debug!("Unsupported video codec, box {:?} found", b.head.name);
55725592
skip_box_content(&mut b)?;

mp4parse/tests/hevc_white_frame.mp4

3.28 KB
Binary file not shown.

mp4parse/tests/public.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ static AVIF_CORRUPT_IMAGES_DIR: &str = "tests/corrupt";
215215
// The 1 frame h263 3gp file can be generated by ffmpeg with command
216216
// "ffmpeg -i [input file] -f 3gp -vcodec h263 -vf scale=176x144 -frames:v 1 -an output.3gp"
217217
static VIDEO_H263_3GP: &str = "tests/bbb_sunflower_QCIF_30fps_h263_noaudio_1f.3gp";
218+
// The 1 frame hevc mp4 file generated by ffmpeg with command
219+
// "ffmpeg -f lavfi -i color=c=white:s=640x480 -c:v libx265 -frames:v 1 -pix_fmt yuv420p hevc_white_frame.mp4"
220+
static VIDEO_HEVC_MP4: &str = "tests/hevc_white_frame.mp4";
218221
// The 1 frame AMR-NB 3gp file can be generated by ffmpeg with command
219222
// "ffmpeg -i [input file] -f 3gp -acodec amr_nb -ar 8000 -ac 1 -frames:a 1 -vn output.3gp"
220223
#[cfg(feature = "3gpp")]
@@ -286,6 +289,10 @@ fn public_api() {
286289
mp4::VideoCodecSpecific::H263Config(ref _h263) => {
287290
"H263"
288291
}
292+
mp4::VideoCodecSpecific::HEVCConfig(ref hevc) => {
293+
assert!(!hevc.is_empty());
294+
"HEVC"
295+
}
289296
},
290297
"AVC"
291298
);
@@ -1435,6 +1442,32 @@ fn public_video_h263() {
14351442
}
14361443
}
14371444

1445+
#[test]
1446+
fn public_video_hevc() {
1447+
let mut fd = File::open(VIDEO_HEVC_MP4).expect("Unknown file");
1448+
let mut buf = Vec::new();
1449+
fd.read_to_end(&mut buf).expect("File error");
1450+
1451+
let mut c = Cursor::new(&buf);
1452+
let context = mp4::read_mp4(&mut c).expect("read_mp4 failed");
1453+
for track in context.tracks {
1454+
let stsd = track.stsd.expect("expected an stsd");
1455+
let v = match stsd.descriptions.first().expect("expected a SampleEntry") {
1456+
mp4::SampleEntry::Video(ref v) => v,
1457+
_ => panic!("expected a VideoSampleEntry"),
1458+
};
1459+
assert_eq!(v.codec_type, mp4::CodecType::HEVC);
1460+
assert_eq!(v.width, 640);
1461+
assert_eq!(v.height, 480);
1462+
let _codec_specific = match &v.codec_specific {
1463+
mp4::VideoCodecSpecific::HEVCConfig(_) => true,
1464+
_ => {
1465+
panic!("expected a HEVCConfig",);
1466+
}
1467+
};
1468+
}
1469+
}
1470+
14381471
#[test]
14391472
#[cfg(feature = "3gpp")]
14401473
fn public_audio_amrnb() {

mp4parse_capi/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub enum Mp4parseCodec {
100100
Ec3,
101101
Alac,
102102
H263,
103+
Hevc,
103104
#[cfg(feature = "3gpp")]
104105
AMRNB,
105106
#[cfg(feature = "3gpp")]
@@ -962,6 +963,7 @@ fn mp4parse_get_track_video_info_safe(
962963
VideoCodecSpecific::AV1Config(_) => Mp4parseCodec::Av1,
963964
VideoCodecSpecific::AVCConfig(_) => Mp4parseCodec::Avc,
964965
VideoCodecSpecific::H263Config(_) => Mp4parseCodec::H263,
966+
VideoCodecSpecific::HEVCConfig(_) => Mp4parseCodec::Hevc,
965967
#[cfg(feature = "mp4v")]
966968
VideoCodecSpecific::ESDSConfig(_) => Mp4parseCodec::Mp4v,
967969
#[cfg(not(feature = "mp4v"))]
@@ -978,7 +980,9 @@ fn mp4parse_get_track_video_info_safe(
978980
VideoCodecSpecific::AV1Config(ref config) => {
979981
sample_info.extra_data.set_data(&config.raw_config);
980982
}
981-
VideoCodecSpecific::AVCConfig(ref data) | VideoCodecSpecific::ESDSConfig(ref data) => {
983+
VideoCodecSpecific::AVCConfig(ref data)
984+
| VideoCodecSpecific::ESDSConfig(ref data)
985+
| VideoCodecSpecific::HEVCConfig(ref data) => {
982986
sample_info.extra_data.set_data(data);
983987
}
984988
_ => {}

0 commit comments

Comments
 (0)