pub fn fragment(mp4: &MP4, format: Format, frag: &FragmentSource) -> io::Result<Vec<u8>> {
    let track = mp4
        .movie()
        .track_by_id(frag.src_track_id)
        .ok_or_else(|| ioerr!(NotFound, "track not found"))?;
    let mut iter = track.sample_info_iter();
    let timescale = iter.timescale();
    let eol = if format == Format::Vtt {
        &b"\n"[..]
    } else {
        &b"\r\n"[..]
    };

    let mut buffer = Vec::new();
    let mut seq = frag.from_sample;
    iter.seek(frag.from_sample)?;

    for sample in iter {
        let mut data = mp4.data_ref(sample.fpos, sample.size as u64);
        match Tx3GTextSample::from_bytes(&mut data) {
            Ok(subt) => {
                if format == Format::Tx3g {
                    buffer.extend_from_slice(&data[..]);
                } else {
                    if format == Format::Vtt {
                        buffer.extend_from_slice(b"WEBVTT\n\n");
                    }
                    if subt.text.len() > 0 {
                        let cue = cue(format, timescale, None, sample, subt);
                        buffer.extend_from_slice(cue.as_bytes());
                        buffer.extend_from_slice(eol);
                    }
                }
            },
            Err(_) => {},
        }
        seq += 1;
        if seq > frag.to_sample {
            break;
        }
    }

    Ok(buffer)
}
/// Create a fragment containing the cue(s).
///
/// Outputs raw data. If this is to be sent in a CMAF container, it
/// still needs to be wrapped by a moof + mdat.
Create a fragment containing the cue(s).
Outputs raw data. If this is to be sent in a CMAF container, it
still needs to be wrapped by a moof + mdat.
Create a fragment containing the cue ( s ) . Outputs raw data . If this is to be sent in a CMAF container it still needs to be wrapped by a moof + mdat .
pub fn fragment(mp4: &MP4, format: Format, frag: &FragmentSource) -> io::Result<Vec<u8>> {
    let track = mp4
        .movie()
        .track_by_id(frag.src_track_id)
        .ok_or_else(|| ioerr!(NotFound, "track not found"))?;
    let mut iter = track.sample_info_iter();
    let timescale = iter.timescale();
    let eol = if format == Format::Vtt {
        &b"\n"[..]
    } else {
        &b"\r\n"[..]
    };
    let mut buffer = Vec::new();
    let mut seq = frag.from_sample;
    iter.seek(frag.from_sample)?;
    for sample in iter {
        let mut data = mp4.data_ref(sample.fpos, sample.size as u64);
        match Tx3GTextSample::from_bytes(&mut data) {
            Ok(subt) => {
                if format == Format::Tx3g {
                    buffer.extend_from_slice(&data[..]);
                } else {
                    if format == Format::Vtt {
                        buffer.extend_from_slice(b"WEBVTT\n\n");
                    }
                    if subt.text.len() > 0 {
                        let cue = cue(format, timescale, None, sample, subt);
                        buffer.extend_from_slice(cue.as_bytes());
                        buffer.extend_from_slice(eol);
                    }
                }
            },
            Err(_) => {},
        }
        seq += 1;
        if seq > frag.to_sample {
            break;
        }
    }
    Ok(buffer)
}
pub fn fragment ( mp4 : & MP4 , format : Format , frag : & FragmentSource ) -> io :: Result < Vec < u8 > > { let track = mp4 . movie ( ) . track_by_id ( frag . src_track_id ) . ok_or_else ( | | ioerr ! ( NotFound " " ) ) ? ; let mut iter = track . sample_info_iter ( ) ; let timescale = iter . timescale ( ) ; let eol = if format == Format :: Vtt { & b" \n " [ .. ] } else { & b" \r \n " [ .. ] } ; let mut buffer = Vec :: new ( ) ; let mut seq = frag . from_sample ; iter . seek ( frag . from_sample ) ? ; for sample in iter { let mut data = mp4 . data_ref ( sample . fpos , sample . size as u64 ) ; match Tx3GTextSample :: from_bytes ( & mut data ) { Ok ( subt ) => { if format == Format :: Tx3g { buffer . extend_from_slice ( & data [ .. ] ) ; } else { if format == Format :: Vtt { buffer . extend_from_slice ( b" \n \n " ) ; } if subt . text . len ( ) > 0 { let cue = cue ( format , timescale , None , sample , subt ) ; buffer . extend_from_slice ( cue . as_bytes ( ) ) ; buffer . extend_from_slice ( eol ) ; } } } , Err ( _ ) => { } , } seq += 1 ; if seq > frag . to_sample { break ; } } Ok ( buffer ) }
Create a fragment containing the cue(s).
Create a fragment containing the cue ( s ) .
mp4
&MP4
format
Format
frag
&FragmentSource
mp4
&MP4
format
Format
frag
&FragmentSource