[FFmpeg-devel] [PATCH 2/2] qt-faststart - optimize the offset change loop

Michael Niedermayer michael at niedermayer.cc
Wed May 30 00:36:37 EEST 2018


On Tue, May 29, 2018 at 02:36:28PM +0000, Eran Kornblau wrote:
> Hi,
> 
> The attached is a slightly more optimized (and IMHO elegant) code for updating the stco/co64 offsets
> 
> Thanks
> 
> Eran

>  qt-faststart.c |   42 +++++++++++++++++++++++++-----------------
>  1 file changed, 25 insertions(+), 17 deletions(-)
> a0f95e960800141a0a666313f2f3d82a87a3309f  0002-qt-faststart-optimize-the-offset-change-loop.patch
> From 776244b79a8bcfb5732f39fbebb9cd7fc0092bcb Mon Sep 17 00:00:00 2001
> From: erankor <eran.kornblau at kaltura.com>
> Date: Tue, 29 May 2018 17:29:09 +0300
> Subject: [PATCH 2/2] qt-faststart - optimize the offset change loop
> 
> ---
>  tools/qt-faststart.c | 42 +++++++++++++++++++++++++-----------------
>  1 file changed, 25 insertions(+), 17 deletions(-)
> 
> diff --git a/tools/qt-faststart.c b/tools/qt-faststart.c
> index d0ae7245f3..2ddaf87e1b 100644
> --- a/tools/qt-faststart.c
> +++ b/tools/qt-faststart.c
> @@ -96,9 +96,11 @@ int main(int argc, char *argv[])
>      int64_t last_offset;
>      unsigned char *moov_atom = NULL;
>      unsigned char *ftyp_atom = NULL;
> +    unsigned char *ptr;
> +    unsigned char *end;
>      uint64_t moov_atom_size;
>      uint64_t ftyp_atom_size = 0;
> -    uint64_t i, j;
> +    uint64_t i;
>      uint32_t offset_count;
>      uint64_t current_offset;
>      int64_t start_offset = 0;
> @@ -253,13 +255,16 @@ int main(int argc, char *argv[])
>                  printf(" bad atom size/element count\n");
>                  goto error_out;
>              }
> -            for (j = 0; j < offset_count; j++) {
> -                current_offset  = BE_32(&moov_atom[i + 12 + j * 4]);
> +
> +            ptr = moov_atom + i + 12;
> +            end = ptr + offset_count * 4;
> +            while (ptr < end) {
> +                current_offset  = BE_32(ptr);
>                  current_offset += moov_atom_size;
> -                moov_atom[i + 12 + j * 4 + 0] = (current_offset >> 24) & 0xFF;
> -                moov_atom[i + 12 + j * 4 + 1] = (current_offset >> 16) & 0xFF;
> -                moov_atom[i + 12 + j * 4 + 2] = (current_offset >>  8) & 0xFF;
> -                moov_atom[i + 12 + j * 4 + 3] = (current_offset >>  0) & 0xFF;
> +                *ptr++ = (current_offset >> 24) & 0xFF;
> +                *ptr++ = (current_offset >> 16) & 0xFF;
> +                *ptr++ = (current_offset >>  8) & 0xFF;
> +                *ptr++ = (current_offset >>  0) & 0xFF;
>              }
>              i += atom_size - 4;
>          } else if (atom_type == CO64_ATOM) {
> @@ -274,17 +279,20 @@ int main(int argc, char *argv[])
>                  printf(" bad atom size/element count\n");
>                  goto error_out;
>              }
> -            for (j = 0; j < offset_count; j++) {
> -                current_offset  = BE_64(&moov_atom[i + 12 + j * 8]);
> +
> +            ptr = moov_atom + i + 12;
> +            end = ptr + offset_count * 8;
> +            while (ptr < end) {
> +                current_offset  = BE_64(ptr);
>                  current_offset += moov_atom_size;
> -                moov_atom[i + 12 + j * 8 + 0] = (current_offset >> 56) & 0xFF;
> -                moov_atom[i + 12 + j * 8 + 1] = (current_offset >> 48) & 0xFF;
> -                moov_atom[i + 12 + j * 8 + 2] = (current_offset >> 40) & 0xFF;
> -                moov_atom[i + 12 + j * 8 + 3] = (current_offset >> 32) & 0xFF;
> -                moov_atom[i + 12 + j * 8 + 4] = (current_offset >> 24) & 0xFF;
> -                moov_atom[i + 12 + j * 8 + 5] = (current_offset >> 16) & 0xFF;
> -                moov_atom[i + 12 + j * 8 + 6] = (current_offset >>  8) & 0xFF;
> -                moov_atom[i + 12 + j * 8 + 7] = (current_offset >>  0) & 0xFF;
> +                *ptr++ = (current_offset >> 56) & 0xFF;
> +                *ptr++ = (current_offset >> 48) & 0xFF;
> +                *ptr++ = (current_offset >> 40) & 0xFF;
> +                *ptr++ = (current_offset >> 32) & 0xFF;
> +                *ptr++ = (current_offset >> 24) & 0xFF;
> +                *ptr++ = (current_offset >> 16) & 0xFF;
> +                *ptr++ = (current_offset >>  8) & 0xFF;
> +                *ptr++ = (current_offset >>  0) & 0xFF;

can this be simplfified with
libavcodec/bytestream.h, libavutil/intreadwrite.h
or similar ?

[...]


-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Modern terrorism, a quick summary: Need oil, start war with country that
has oil, kill hundread thousand in war. Let country fall into chaos,
be surprised about raise of fundamantalists. Drop more bombs, kill more
people, be surprised about them taking revenge and drop even more bombs
and strip your own citizens of their rights and freedoms. to be continued
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180529/cdb42ce7/attachment.sig>


More information about the ffmpeg-devel mailing list