Recherche avancée

Médias (1)

Mot : - Tags -/biomaping

Autres articles (32)

  • L’utiliser, en parler, le critiquer

    10 avril 2011

    La première attitude à adopter est d’en parler, soit directement avec les personnes impliquées dans son développement, soit autour de vous pour convaincre de nouvelles personnes à l’utiliser.
    Plus la communauté sera nombreuse et plus les évolutions seront rapides ...
    Une liste de discussion est disponible pour tout échange entre utilisateurs.

  • D’autres logiciels intéressants

    12 avril 2011, par

    On ne revendique pas d’être les seuls à faire ce que l’on fait ... et on ne revendique surtout pas d’être les meilleurs non plus ... Ce que l’on fait, on essaie juste de le faire bien, et de mieux en mieux...
    La liste suivante correspond à des logiciels qui tendent peu ou prou à faire comme MediaSPIP ou que MediaSPIP tente peu ou prou à faire pareil, peu importe ...
    On ne les connais pas, on ne les a pas essayé, mais vous pouvez peut être y jeter un coup d’oeil.
    Videopress
    Site Internet : (...)

  • Librairies et logiciels spécifiques aux médias

    10 décembre 2010, par

    Pour un fonctionnement correct et optimal, plusieurs choses sont à prendre en considération.
    Il est important, après avoir installé apache2, mysql et php5, d’installer d’autres logiciels nécessaires dont les installations sont décrites dans les liens afférants. Un ensemble de librairies multimedias (x264, libtheora, libvpx) utilisées pour l’encodage et le décodage des vidéos et sons afin de supporter le plus grand nombre de fichiers possibles. Cf. : ce tutoriel ; FFMpeg avec le maximum de décodeurs et (...)

Sur d’autres sites (6749)

  • Embedding Metadata to H.264 encoded file

    7 septembre 2012, par kerim yucel

    I am currently developing an application which produces certain metadata with respect to preview frames coming from the camera. I can see this metadata being produced properly and I have no problems here.

    However, I have to embed this metadata to these frames of interest (frames are processed by a native algorithm to produce this metadata). I am using ffmpeg with x264 to encode the frames into H.264. I have checked x264.h and some documentations but failed to find what I seek.

    My question is ; is there any unused portion of H.264 syntax that I can embed my metadata to encoded frames ?

    I hope I was clear enough. Thanks in advance.

  • how to analyze the binary data of these h.264 packets and organize a h.264 stream to decode them use ffmpeg ?

    27 mars 2012, par 丝地 陈

    Much appreciation to some help with the following issue :
    the h.264 packets attached below are received from a decoder,but I am not sure about the details, e.g. the transfer protocol .I've searched some topics similar to this and read the articles of analysis on this topic from the author Cipi and others.Thanks a lot .
    but still i can't resolve to analyze the data of these packets .so I issue this problem and hope to get some help.
    I'm able to ffmpeg and the first try I've done is to dump this packets to a tmp file and open it use the av_open_inputfile ,but some time the problem is the Codec parameters can't found. so I'm hoping to organize the h264 stream and decode it use the ffmpeg .so How ?

    Attached:2012-03-21 09:22:37.171 MScope[3006:18f03] received data: <000001ba 66dbf7a3 840100a3 dbfeffff 04354f8b 000001e0 00128c80 0729b6fd e8e1fffc 00000001 09300000 000001e0 00aa8c00 03fffffc 00000001 419a1840 c20837cb ecc1177e e7ead1fc db167e27 a150bf97 dc4736f8 ce12d81f 42fc65ff 607a1f62 89e4f431 5ddfae4f 40fc2bec 5d096c7f 89e6bf0a f27b1077 93d03087 11ebacfc 39e86b1c 27ff2756 97bec73f 37a02370 d7b14b40 7d163f89 d0bd39f9 eb8b1fde 188cefa1 425c97ef 936b5cf5 b1fe7eb1 45f0e638 17382919 1f0c932f f0deab3a ed7ffcbd 3f929f09 735f939f 2e8be16e 7ad01ce3 3e1dbcb0>
    2012-03-21 09:22:37.171 MScope[3006:18f03] 220
    2012-03-21 09:22:37.202 MScope[3006:18f03] received data: <000001c0 005a8c80 0729b6fd ebcdfffc 1c416a02 d447004f ff16c1bc 2a0eb902 4c185085 04e660cb 3595856a 3eccb10a 761db750 3fb0171e 1c382a62 cf9ff10a ff37e750 55c16fad 22c1933f 03f00878 73521346 4c748898 9d9859a0 a573ada3>
    2012-03-21 09:22:37.202 MScope[3006:18f03] 96
    2012-03-21 09:22:37.211 MScope[3006:18f03] received data: <000001ba 66dbfc14 040100a3 dbfeffff 04354f8c 000001e0 00128c80 0729b6ff 0501fffc 00000001 09300000 000001e0 00e28c00 03fffffc 00000001 419a1880 c40833d5 a2f9bdfc bde3fac5 08f7ee33 ab447119 07fec5e5 d9fe5b17 0a704b8d 177de307 d7c64c4a cfb5a158 687c2bc4 ec5f327e e85c1872 502e4eef cdcb60df 1363a6e5 df2f27b9 386f746f 2c644bd2 a2c4f7b0 7ae6df7c bd8a4eec ff977df0 e6c0b58f 0b8ff0a7 2f7ae08f b3f4672d ecbe4f75 c37d8ebe 83e6e6bf f7ecc673 76055c57 998beb9b 6079797b c670e740 f87a2ff1 bec150b4 bb04df59 44a718ff 86265adf a12e07da 7ffe5e87 f268058a eac44f27 bf9281f3 f2f6389e b57cda2f d5a4e1cb fd6457f8 fe4d9e7e 6d82cbde f9e00000>
    2012-03-21 09:22:37.212 MScope[3006:18f03] 276
    2012-03-21 09:22:37.242 MScope[3006:17f03] received data: <000001c0 005a8c80 0729b6ff 07edfffc a83864c2 4e7d4e20 8ae819c6 03724270 7e5730d9 6648f9c8 b2e966d7 bc814c21 06306342 3c05ffe3 5840fcc2 2d2ae65b 1f231694 c8c8b7a2 0ad5080a 4fc3452d 332e9a30 1a3af1e0 b970ad62 a76927c4>
    2012-03-21 09:22:37.242 MScope[3006:17f03] 96
    2012-03-21 09:22:37.251 MScope[3006:18f03] received data: <000001ba 66dbfc84 840100a3 dbfeffff 04354f8d 000001e0 00128c80 0729b6ff 2121fffc 00000001 09300000 000001e0 00fa8c00 03fffffc 00000001 419a18c0 c608d7ff ffffffff e5f27fd5 5a2aa5f7 3556292a 6e945f5e 967c4757 89efd097 5e847847 d88545e8 7f97b053 75e8ee3b d02a03ec 5f825ec1 a07d80ab e5d0b0a7 7a02fdd8 b88e4d0b 35e2b928 7dc6785b 5c57a176 2158a9b9 ba17c9d0 a5ef61e2 7bdf1379 fac52f0b 7760f4eb 28dffe17 f761f5d8 be2388d1 ecf89eef c9c2f616 80ba12fd 963fbd1d 35797872 c541a025 c547f11d ec1e7e1b a7d7d9d9 cfc27b17 d88dcb7e 23bbf5c1 2632507c abaf572f 7ae4bf24 9579facb e18bd2c6 c2c3ced9 df10fff0 dfa3604b b1fd70d6 c0f5b2fc 56feaf11 d5af86f7 d765f372 76296f17 cf59c4e4 19f0b736 81632000>
    2012-03-21 09:22:37.251 MScope[3006:18f03] 300
    2012-03-21 09:22:37.282 MScope[3006:17f03] received data: <000001c0 005a8c80 0729b6ff 240dfffc 2e403ec4 2c07bc91 dea5816a fd1335b9 807cd133 4d0a12ac 876514ce 3883236b c0c17c9f 2b93ff26 d83827cc d30bf10a ca0262f5 09cad6ff 81fc2949 90de1ba6 11d98d2a 8dd5e80a e952f45e a4a0e711>
    2012-03-21 09:22:37.282 MScope[3006:17f03] 96
    2012-03-21 09:22:37.293 MScope[3006:17f03] received data: <000001ba 66dbfcf5 040100a3 dbfeffff 04354f8e 000001bc 0052f5ff 0024400e 484b0001 0c3aa503 2000ffff ffff4112 484b0000 00000000 00000000 00000000 00000024 1be00010 420e0000 60000160 0120111f ff001c20 92c0000c 430a0050 ff00fa03 00fa03ff 7c67884a 000001e0 00128c80 0729b6ff 3d41fffc 00000001 09100000 000001e0 001e8c00 03fffffc 00000001 6742800d 888b40b0 4b420000 0e100002 bf200800 000001e0 000e8c00 03fffffc 00000001 68ce3880 000001e0 253e8c00 03fffffc 00000001 65888008 0002e1f0 87e3e160 001021a1 e0002079 f5eaabd1 80def5ad ec1bc438 f10f7bbc 40904989 1c78adee f726e7dd a4dcfbbc 9b93bcf9 fff870a4 43cb65ed e5f97aff 08c7f510 3ce7c6de 3c3f72b2 f76f9cd1 fe3c3ff5 7103e5e7 3ebd7aae fdffffd4 5d6aafb7 d576f1f0 ffb8ac43 e99cf6f6 fd755d42 d84e2239 fff2c357 bd6b08e0 016317b0 91a8eb7a 18bec15f be000e13 b8cd2ed1 88a11360 250fd11b aa269986 2dffe034 9de244ca 1f4a2bf6 a03404c2 8aebc2cd bb012c7b 08cf5936 cd290fff 01a6ed52 fce1b482 ff6a58f7 3019ed40 4fabc400 0080b59a 5045138e 2394b709 5cfb905d 17771f4c ed199f0e 400021c6 6a934a0d edfbe012 5cb14bf0 06288cd2 dff7fe01 c3800877 0249cb92 6ca17482 1ffb02b8 bf314562 1e93d5e9 0226b833 bbeef4b9 c0e0409d c66977d8 8a1136f7 087e88dd 43e99852 4dfff684 ef122650 fa4105fe d8078128 a2a01b3a 229f9738 089c4a96 c49b5305 822612c5 b2529a5f f61144e3 88e52587 87f9f7a0 5d1f05d2 6cc4327f 7c3c30ff 0ef6b1ee 272da862 4f578092 c2eff5d9 67901b5a 3d40370a d561de23 7d7fd7fb e3168a50 5ebbca21 092c7800 1b046172 c0070995 3a84bd87 512fdfbc 62f18a0b b79742b1 86f863d1 0ae997ed 8bffff0d 0940abf5 30ea6ade 6f18b652 82f4de63 95e4ecb8 6c0001bb 419926c6 b00fb1f9 89849d59 bffaffd1 f1e11806 0170158f 6119ab7d b34a41bf fed0ddaa 5f9436b8 b7fed6b1 ee6023da 81e64f57 88001000 40213204 09d46693 7d88a3ac 5ee10fd3 0ba87d2b 0a49bffe b1a80854 dea31059 bb56201f a2351d89 c59ffeff 6c01711a a4d282e3 beff7de1 778a5f80 2484fa95 4e4d83cb 8f1034cb 96340f64 7f64d8a8 b7ad9651 712ec6b1 67ffbfd0 4ba7f00f 0fdcb540 05717065 7b5465b4 25e60c01 c7e2b86d a8ca7269 e00a1eaa ca98c1ef 60c6f885 ab1113ff d3afe21e aac1b2b2 dc9d7ffc 534cf3e6 3f15c36d 5653938f 000f0361 2ab4deb7 5b097f7e 7a000240 6b40cf05 de43d558 3655e5b9 3af19674 020bd93a 4dbba3b7 ef8d8895 5b87c403 805f913a 8cb26fb1 147589dc 21fa6175 0fa56149 2fffda13 bc49b285 d20827f6 c0783510 4402e744 51f2ed09 de24d942 eb887fec 0ae2f4ce 7310549e af481328 c3b79eff 0b9c0dd8 4e2618ee 5258785f 9f7a0ba2 e1f5f657 3277c648 23245c04 c83a92c4 9b530782 641d4962 4da9bf5b f807e10d c04ccc9c 62307fac 29a60001 8046932c 09820010 51505e80 01d0f556 54c60b7b 4513e216 a8446fff 4fefada2 412adcc3 956f1951 e7000081 c300014d 9121bf46 9d67e440 007022cf 9d8c0008 1452e998 1a47867e c2d45b16 f3626bf8 43e01b87 58003509 94764dbf 3e907092 79ae081d 31c4bb46 69e737dd 8b1ea663 9f9045bc d5e02801 616c9ba6 714f53f1 bfffa004 d05e5a18 d35d4600 01b0451b 2c0ac2f8 ec731444 9eaf61c0 3c21df00 041bba2e 4d9c2cd5 8d647806 001c191a f217aac8 bf6ebf26 0661e728 b3ad2c70 d6b801d0 8ab2d607 7567a0dc 18545ea1 3a9c24d3 ef3480d0 859e766e d89b7002 87ea32be cbc01e38 3b8904b6 85c20ab7 ea331800 20068064 9801f63f 3131a396 37dd84c0 e83aa118 6505d9e6 b2607710 7562f167 abd80098 e2ae6dc9 63acb7ff bcb00043 d2949eb4 2d059ff7 c806010f 0c2fa6c1 a946df28 843a4f7f fc068119 f17063a7 f9e96bac 960c44ce 2350b376 bc896424 4f57a775 00617aac 1f6eb2dc 8c683dac 8c82e729 887376b8 b436405c 9add43ae 1ede44b2 1227efd3 abf8059b 0474de09 7774ad25 8131c45d 5b16ba99 7ffbc1ab cc000300 8d2e5bf0 f8618760 c002c4ca 9c33af62 d2fadf80 0110fd46 55d97ec8 bea68d21 b7565455 e9c31aa0 65af0015 2d3ce021 456810b2 51944db3 fddeee9b 8b54196e 65fb65dc 07e38601 c001f1e8 632947b5 69082fff d81bb54f 9425b896 bfed6b1e a6066ad0 34a9eaf1 80008004 90527a04 09d44593 3d88a32c 4ee10fd3 1d482d2b 08497ffe f45f288b dbbe3dc9 154f31e8 8ea9afda 2a8200b8 8b47d287 c77bfefb 82ef15fe 0107f295 461ff1ad 4b09b3ee 64c26788 e3918de0 bbc57f80 41bca551 87fc3186 3d4b77f2 e977ff80 601c3db8 5e1d8e62 8893d5e0 521e8773 9ca729ea f000593b c49b28f6 e737f605 717a6739 88729eaf 48132883 b79deecb 9c49a8e0 263b1c86 3a0ea702 613d686a d07510d3 221e6870 1320a84a bcda983c 4120aa4b 126d4ccb 35da8dfc badfff00 c02e02b1 e8632945 b569082f ffde63d1 1d5375da 2fc1a811 ca4001f5 183f6d77 087e98ea 41695842 4bfff07b 70bc3b1c c5339eaf 0290f42b 9ce517cf 57acc838 37e1b78e dbec6594 e851312a 4cbffde3 0cd065f4 b38098ec 7208b41d 4e04c27a 50b6a0ea c4d03ff4 b7f0e002 1d4002c9 de24d947 b739bfb0 2b8bf239 ccc2f9ea f4813288 3b79deec b9c2d600 813a88b7 cf6228cb 3f7087e9 8ea41695 8424bfff 684ef34d 942eb9cf fdb01e09 441101f1 a7ffc5ce 02641509 579b5305 82641d89 54fa6972 f246c273 20677212 a342fcfb d0be5c3e b6c8e64e eb9f8e9a 5ba3b0c3 ffc39469 702e5d36 7d68ec13 e9537ffd 6a12c196 85fd7eb5 f7ffff7d f5f76d55 bffffeeb aad5557a ac2d80d7 6472c7ff 65eaf7ad 65e4ce44 4e6fd87c 03feb6a4 b07ee538 03678a66 d3c2adda 560ef825 919bd03f 6150cc6c a8b3f229 3d8e032c 6aa5fcc3 182ce001 00e18006 a7ec5187 6a65f6d2 7cf0fd38 4c3c81b9 a203cd47 dc5ef2cf b76badc4 e1b70631 5427809e 70add3da 573a5f08 b596b08e ae9ad931 6165c21f 99813f89 af0b609c 2990c1be 21ffaaac 1afd1715 34f05304 e13c0377 53d3ff8b e373bacf 1763b1b8 4f01d3f2 e2d47c6d f4338259 f6bb7615 71508fa3 b1560108 61fea0b7 c32c87f7 b8754cc9 5ae6b0ed 3322ac3c 21ff55fc 9c0ebf07 cd31ba9d 73778a3a 641b29d1 aa27c103 1a51fa81 4cd09e53 b47dbed9 f7fc6334 27b097d2 aeb4886b fc14c3b2 84f1e69d 2319adfa e32e33fe 3540c8a1 3c8ce75b fe0cd2de 7e67c0e9 77387d78 7ffea2c2 255307be cf9d5791 8ae3e1ff 797d34cb cbe6b6e5 545f01ff fd78a6f5 8baaa88f 52fc5582 e921ffff bd5755cd d7955c21 f080807e bd570ed1 a9c00080 de46a1a8 3c952d1c bf5dbffe 018075d5 753662b5 16773057 1f20ef34 2e9a7b65 dffe01f0 415860ce 9ea028b4 5e696823 9b3ffef2 c3e001f0 8781f698 5d0ca532 ca4669f6 45b68cac 8c879acf 58047991 d83bf4d3 eb460597 0dd82063 4ad7f00f ffeba517 7aaae76a 8b9daad4 b4135aa5 33972b8c ff77f01a 2196a9f7 a13c0084 c4b72067 ee45d6dd 84ece8ab 20896587 7a29684d 34fdcfb5 b45572c3 a3596756 3fffea01 d6ee1470 73f23c40 414c7976 28f9af2f 8b8310df d9096e32 d0c25dfc 7ffb9061 3a4119f9 66583fd4 a57b5ad0 2faad4b4 388db69e e6231fff f5870306 d68bc10d 7884883a 3774d25f f4c1dc83 d96881aa 6bdff0ff acd5e94f a3ac1c70 4f731594 e4419a7e 4a9d019b ffff960e b7a656aa f4c52994 d67e3047 8963414c 2a1b4234 fab9bb44 6bdfc3ff 8631dbc6 90439720 b987ffff eb2bfac7 9eb16412 3ffffcd5 5d5557a7 37ffff75 55d5757a a7ac38a7 ab091476 c0210843 0f99901d 8ed04273 fd6ee0a6 10d35a20 abaf126b 63df37b3 36ce3462 7379aad9 6efbf4ff fe001f8e 8657d1df 8d8eadf8 7951d85a a8dcb6d7 b9203b51 9ddea6e1 6296ba69 b9d8937a 2e4b15c5 d9f957a7 1f100fff d70e7890 0677c46a 2315fa73 41f538a8 7fb251ef e0e4c3d1 563c5a98 eb328853 30607ef4 3f81fd72 1e6ae3bf fff85ebd 00cd260e ea58a46f 9320d59a 4cc60a32 2e5e27f5 63080d95 9e843194 1fffebff>
  • How to fix a segmentaion fault in a C program ? [closed]

    13 janvier 2012, par ipegasus

    Possible Duplicate :
    Segmentation fault

    Currently I am upgrading an open source program used for HTTP streaming. It needs to support the latest FFMPEG.
    The code compiles fine with no warnings although I am getting a segmentation fault error.
    I would like to know how to fix the issue ? and / or the best way to debug ? Please find attached a portion of the code due to size. I will try to add the project to github :) Thanks in advance !

    Sample Usage

    # segmenter --i out.ts --l 10 --o stream.m3u8 --d segments --f stream

    Makefile

    FFLIBS=`pkg-config --libs libavformat libavcodec libavutil`
    FFFLAGS=`pkg-config --cflags libavformat libavcodec libavutil`

    all:
       gcc -Wall -g segmenter.c -o segmenter ${FFFLAGS} ${FFLIBS}

    segmenter.c

    /*
    * Copyright (c) 2009 Chase Douglas
    *
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License version 2
    * as published by the Free Software Foundation.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    */
    #include
    #include
    #include
    #include
    #include
    #include "libavformat/avformat.h"

    #include "libavformat/avio.h"

    #include <sys></sys>stat.h>

    #include "segmenter.h"
    #include "libavformat/avformat.h"

    #define IMAGE_ID3_SIZE 9171

    void printUsage() {
       fprintf(stderr, "\nExample: segmenter --i infile --d baseDir --f baseFileName --o playListFile.m3u8 --l 10 \n");
       fprintf(stderr, "\nOptions: \n");
       fprintf(stderr, "--i <infile>.\n");
       fprintf(stderr, "--o <outfile>.\n");
       fprintf(stderr, "--d basedir, the base directory for files.\n");
       fprintf(stderr, "--f baseFileName, output files will be baseFileName-#.\n");
       fprintf(stderr, "--l segment length, the length of each segment.\n");
       fprintf(stderr, "--a,  audio only decode for &lt; 64k streams.\n");
       fprintf(stderr, "--v,  video only decode for &lt; 64k streams.\n");
       fprintf(stderr, "--version, print version details and exit.\n");
       fprintf(stderr, "\n\n");
    }

    void ffmpeg_version() {
       // output build and version numbers
       fprintf(stderr, "  libavutil version:   %s\n", AV_STRINGIFY(LIBAVUTIL_VERSION));
       fprintf(stderr, "  libavutil build:     %d\n", LIBAVUTIL_BUILD);
       fprintf(stderr, "  libavcodec version:  %s\n", AV_STRINGIFY(LIBAVCODEC_VERSION));
       fprintf(stdout, "  libavcodec build:    %d\n", LIBAVCODEC_BUILD);
       fprintf(stderr, "  libavformat version: %s\n", AV_STRINGIFY(LIBAVFORMAT_VERSION));
       fprintf(stderr, "  libavformat build:   %d\n", LIBAVFORMAT_BUILD);
       fprintf(stderr, "  built on " __DATE__ " " __TIME__);
    #ifdef __GNUC__
       fprintf(stderr, ", gcc: " __VERSION__ "\n");
    #else
       fprintf(stderr, ", using a non-gcc compiler\n");
    #endif
    }


    static AVStream *add_output_stream(AVFormatContext *output_format_context, AVStream *input_stream) {
       AVCodecContext *input_codec_context;
       AVCodecContext *output_codec_context;
       AVStream *output_stream;

       output_stream = avformat_new_stream(output_format_context, 0);
       if (!output_stream) {
           fprintf(stderr, "Segmenter error: Could not allocate stream\n");
           exit(1);
       }

       input_codec_context = input_stream->codec;
       output_codec_context = output_stream->codec;

       output_codec_context->codec_id = input_codec_context->codec_id;
       output_codec_context->codec_type = input_codec_context->codec_type;
       output_codec_context->codec_tag = input_codec_context->codec_tag;
       output_codec_context->bit_rate = input_codec_context->bit_rate;
       output_codec_context->extradata = input_codec_context->extradata;
       output_codec_context->extradata_size = input_codec_context->extradata_size;

       if (av_q2d(input_codec_context->time_base) * input_codec_context->ticks_per_frame > av_q2d(input_stream->time_base) &amp;&amp; av_q2d(input_stream->time_base) &lt; 1.0 / 1000) {
           output_codec_context->time_base = input_codec_context->time_base;
           output_codec_context->time_base.num *= input_codec_context->ticks_per_frame;
       } else {
           output_codec_context->time_base = input_stream->time_base;
       }

       switch (input_codec_context->codec_type) {
    #ifdef USE_OLD_FFMPEG
           case CODEC_TYPE_AUDIO:
    #else
           case AVMEDIA_TYPE_AUDIO:
    #endif
               output_codec_context->channel_layout = input_codec_context->channel_layout;
               output_codec_context->sample_rate = input_codec_context->sample_rate;
               output_codec_context->channels = input_codec_context->channels;
               output_codec_context->frame_size = input_codec_context->frame_size;
               if ((input_codec_context->block_align == 1 &amp;&amp; input_codec_context->codec_id == CODEC_ID_MP3) || input_codec_context->codec_id == CODEC_ID_AC3) {
                   output_codec_context->block_align = 0;
               } else {
                   output_codec_context->block_align = input_codec_context->block_align;
               }
               break;
    #ifdef USE_OLD_FFMPEG
           case CODEC_TYPE_VIDEO:
    #else
           case AVMEDIA_TYPE_VIDEO:
    #endif
               output_codec_context->pix_fmt = input_codec_context->pix_fmt;
               output_codec_context->width = input_codec_context->width;
               output_codec_context->height = input_codec_context->height;
               output_codec_context->has_b_frames = input_codec_context->has_b_frames;

               if (output_format_context->oformat->flags &amp; AVFMT_GLOBALHEADER) {
                   output_codec_context->flags |= CODEC_FLAG_GLOBAL_HEADER;
               }
               break;
           default:
               break;
       }

       return output_stream;
    }

    int write_index_file(const char index[], const char tmp_index[], const unsigned int planned_segment_duration, const unsigned int actual_segment_duration[],
           const char output_directory[], const char output_prefix[], const char output_file_extension[],
           const unsigned int first_segment, const unsigned int last_segment) {
       FILE *index_fp;
       char *write_buf;
       unsigned int i;

       index_fp = fopen(tmp_index, "w");
       if (!index_fp) {
           fprintf(stderr, "Could not open temporary m3u8 index file (%s), no index file will be created\n", tmp_index);
           return -1;
       }

       write_buf = malloc(sizeof (char) * 1024);
       if (!write_buf) {
           fprintf(stderr, "Could not allocate write buffer for index file, index file will be invalid\n");
           fclose(index_fp);
           return -1;
       }

       unsigned int maxDuration = planned_segment_duration;

       for (i = first_segment; i &lt;= last_segment; i++)
           if (actual_segment_duration[i] > maxDuration)
               maxDuration = actual_segment_duration[i];



       snprintf(write_buf, 1024, "#EXTM3U\n#EXT-X-TARGETDURATION:%u\n", maxDuration);

       if (fwrite(write_buf, strlen(write_buf), 1, index_fp) != 1) {
           fprintf(stderr, "Could not write to m3u8 index file, will not continue writing to index file\n");
           free(write_buf);
           fclose(index_fp);
           return -1;
       }

       for (i = first_segment; i &lt;= last_segment; i++) {
           snprintf(write_buf, 1024, "#EXTINF:%u,\n%s-%u%s\n", actual_segment_duration[i], output_prefix, i, output_file_extension);
           if (fwrite(write_buf, strlen(write_buf), 1, index_fp) != 1) {
               fprintf(stderr, "Could not write to m3u8 index file, will not continue writing to index file\n");
               free(write_buf);
               fclose(index_fp);
               return -1;
           }
       }

       snprintf(write_buf, 1024, "#EXT-X-ENDLIST\n");
       if (fwrite(write_buf, strlen(write_buf), 1, index_fp) != 1) {
           fprintf(stderr, "Could not write last file and endlist tag to m3u8 index file\n");
           free(write_buf);
           fclose(index_fp);
           return -1;
       }

       free(write_buf);
       fclose(index_fp);

       return rename(tmp_index, index);
    }

    int main(int argc, const char *argv[]) {
       //input parameters
       char inputFilename[MAX_FILENAME_LENGTH], playlistFilename[MAX_FILENAME_LENGTH], baseDirName[MAX_FILENAME_LENGTH], baseFileName[MAX_FILENAME_LENGTH];
       char baseFileExtension[5]; //either "ts", "aac" or "mp3"
       int segmentLength, outputStreams, verbosity, version;



       char currentOutputFileName[MAX_FILENAME_LENGTH];
       char tempPlaylistName[MAX_FILENAME_LENGTH];


       //these are used to determine the exact length of the current segment
       double prev_segment_time = 0;
       double segment_time;
       unsigned int actual_segment_durations[2048];
       double packet_time = 0;

       //new variables to keep track of output size
       double output_bytes = 0;

       unsigned int output_index = 1;
       AVOutputFormat *ofmt;
       AVFormatContext *ic = NULL;
       AVFormatContext *oc;
       AVStream *video_st = NULL;
       AVStream *audio_st = NULL;
       AVCodec *codec;
       int video_index;
       int audio_index;
       unsigned int first_segment = 1;
       unsigned int last_segment = 0;
       int write_index = 1;
       int decode_done;
       int ret;
       int i;

       unsigned char id3_tag[128];
       unsigned char * image_id3_tag;

       size_t id3_tag_size = 73;
       int newFile = 1; //a boolean value to flag when a new file needs id3 tag info in it

       if (parseCommandLine(inputFilename, playlistFilename, baseDirName, baseFileName, baseFileExtension, &amp;outputStreams, &amp;segmentLength, &amp;verbosity, &amp;version, argc, argv) != 0)
           return 0;

       if (version) {
           ffmpeg_version();
           return 0;
       }


       fprintf(stderr, "%s %s\n", playlistFilename, tempPlaylistName);


       image_id3_tag = malloc(IMAGE_ID3_SIZE);
       if (outputStreams == OUTPUT_STREAM_AUDIO)
           build_image_id3_tag(image_id3_tag);
       build_id3_tag((char *) id3_tag, id3_tag_size);

       snprintf(tempPlaylistName, strlen(playlistFilename) + strlen(baseDirName) + 1, "%s%s", baseDirName, playlistFilename);
       strncpy(playlistFilename, tempPlaylistName, strlen(tempPlaylistName));
       strncpy(tempPlaylistName, playlistFilename, MAX_FILENAME_LENGTH);
       strncat(tempPlaylistName, ".", 1);

       //decide if this is an aac file or a mpegts file.
       //postpone deciding format until later
       /*  ifmt = av_find_input_format("mpegts");
       if (!ifmt)
       {
       fprintf(stderr, "Could not find MPEG-TS demuxer.\n");
       exit(1);
       } */

       av_log_set_level(AV_LOG_DEBUG);

       av_register_all();
       ret = avformat_open_input(&amp;ic, inputFilename, NULL, NULL);
       if (ret != 0) {
           fprintf(stderr, "Could not open input file %s. Error %d.\n", inputFilename, ret);
           exit(1);
       }

       if (avformat_find_stream_info(ic, NULL) &lt; 0) {
           fprintf(stderr, "Could not read stream information.\n");
           exit(1);
       }

       oc = avformat_alloc_context();
       if (!oc) {
           fprintf(stderr, "Could not allocate output context.");
           exit(1);
       }

       video_index = -1;
       audio_index = -1;

       for (i = 0; i &lt; ic->nb_streams &amp;&amp; (video_index &lt; 0 || audio_index &lt; 0); i++) {
           switch (ic->streams[i]->codec->codec_type) {

    #ifdef USE_OLD_FFMPEG
               case CODEC_TYPE_VIDEO:
    #else
               case AVMEDIA_TYPE_VIDEO:
    #endif
                   video_index = i;
                   ic->streams[i]->discard = AVDISCARD_NONE;
                   if (outputStreams &amp; OUTPUT_STREAM_VIDEO)
                       video_st = add_output_stream(oc, ic->streams[i]);
                   break;
    #ifdef USE_OLD_FFMPEG
               case CODEC_TYPE_AUDIO:
    #else
               case AVMEDIA_TYPE_AUDIO:
    #endif
                   audio_index = i;
                   ic->streams[i]->discard = AVDISCARD_NONE;
                   if (outputStreams &amp; OUTPUT_STREAM_AUDIO)
                       audio_st = add_output_stream(oc, ic->streams[i]);
                   break;
               default:
                   ic->streams[i]->discard = AVDISCARD_ALL;
                   break;
           }
       }

       if (video_index == -1) {
           fprintf(stderr, "Stream must have video component.\n");
           exit(1);
       }

       //now that we know the audio and video output streams
       //we can decide on an output format.
       if (outputStreams == OUTPUT_STREAM_AUDIO) {
           //the audio output format should be the same as the audio input format
           switch (ic->streams[audio_index]->codec->codec_id) {
               case CODEC_ID_MP3:
                   fprintf(stderr, "Setting output audio to mp3.");
                   strncpy(baseFileExtension, ".mp3", strlen(".mp3"));
                   ofmt = av_guess_format("mp3", NULL, NULL);
                   break;
               case CODEC_ID_AAC:
                   fprintf(stderr, "Setting output audio to aac.");
                   ofmt = av_guess_format("adts", NULL, NULL);
                   break;
               default:
                   fprintf(stderr, "Codec id %d not supported.\n", ic->streams[audio_index]->id);
           }
           if (!ofmt) {
               fprintf(stderr, "Could not find audio muxer.\n");
               exit(1);
           }
       } else {
           ofmt = av_guess_format("mpegts", NULL, NULL);
           if (!ofmt) {
               fprintf(stderr, "Could not find MPEG-TS muxer.\n");
               exit(1);
           }
       }
       oc->oformat = ofmt;

       if (outputStreams &amp; OUTPUT_STREAM_VIDEO &amp;&amp; oc->oformat->flags &amp; AVFMT_GLOBALHEADER) {
           oc->flags |= CODEC_FLAG_GLOBAL_HEADER;
       }


       /*  Deprecated: pass the options to avformat_write_header directly.
           if (av_set_parameters(oc, NULL) &lt; 0) {
               fprintf(stderr, "Invalid output format parameters.\n");
               exit(1);
           }
        */

       av_dump_format(oc, 0, baseFileName, 1);


       //open the video codec only if there is video data
       if (video_index != -1) {
           if (outputStreams &amp; OUTPUT_STREAM_VIDEO)
               codec = avcodec_find_decoder(video_st->codec->codec_id);
           else
               codec = avcodec_find_decoder(ic->streams[video_index]->codec->codec_id);
           if (!codec) {
               fprintf(stderr, "Could not find video decoder, key frames will not be honored.\n");
           }

           if (outputStreams &amp; OUTPUT_STREAM_VIDEO)
               ret = avcodec_open2(video_st->codec, codec, NULL);
           else
               avcodec_open2(ic->streams[video_index]->codec, codec, NULL);
           if (ret &lt; 0) {
               fprintf(stderr, "Could not open video decoder, key frames will not be honored.\n");
           }
       }

       snprintf(currentOutputFileName, strlen(baseDirName) + strlen(baseFileName) + strlen(baseFileExtension) + 10, "%s%s-%u%s", baseDirName, baseFileName, output_index++, baseFileExtension);

       if (avio_open(&amp;oc->pb, currentOutputFileName, URL_WRONLY) &lt; 0) {
           fprintf(stderr, "Could not open &#39;%s&#39;.\n", currentOutputFileName);
           exit(1);
       }
       newFile = 1;

       int r = avformat_write_header(oc,NULL);
       if (r) {
           fprintf(stderr, "Could not write mpegts header to first output file.\n");
           debugReturnCode(r);
           exit(1);
       }

       //no segment info is written here. This just creates the shell of the playlist file
       write_index = !write_index_file(playlistFilename, tempPlaylistName, segmentLength, actual_segment_durations, baseDirName, baseFileName, baseFileExtension, first_segment, last_segment);

       do {
           AVPacket packet;

           decode_done = av_read_frame(ic, &amp;packet);

           if (decode_done &lt; 0) {
               break;
           }

           if (av_dup_packet(&amp;packet) &lt; 0) {
               fprintf(stderr, "Could not duplicate packet.");
               av_free_packet(&amp;packet);
               break;
           }

           //this time is used to check for a break in the segments
           //  if (packet.stream_index == video_index &amp;&amp; (packet.flags &amp; PKT_FLAG_KEY))
           //  {
           //    segment_time = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;        
           //  }
    #if USE_OLD_FFMPEG
           if (packet.stream_index == video_index &amp;&amp; (packet.flags &amp; PKT_FLAG_KEY))
    #else
           if (packet.stream_index == video_index &amp;&amp; (packet.flags &amp; AV_PKT_FLAG_KEY))
    #endif
           {
               segment_time = (double) packet.pts * ic->streams[video_index]->time_base.num / ic->streams[video_index]->time_base.den;
           }
           //  else if (video_index &lt; 0)
           //  {
           //      segment_time = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;
           //  }

           //get the most recent packet time
           //this time is used when the time for the final segment is printed. It may not be on the edge of
           //of a keyframe!
           if (packet.stream_index == video_index)
               packet_time = (double) packet.pts * ic->streams[video_index]->time_base.num / ic->streams[video_index]->time_base.den; //(double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;
           else if (outputStreams &amp; OUTPUT_STREAM_AUDIO)
               packet_time = (double) audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;
           else
               continue;
           //start looking for segment splits for videos one half second before segment duration expires. This is because the
           //segments are split on key frames so we cannot expect all segments to be split exactly equally.
           if (segment_time - prev_segment_time >= segmentLength - 0.5) {
               fprintf(stderr, "looking to print index file at time %lf\n", segment_time);
               avio_flush(oc->pb);
               avio_close(oc->pb);

               if (write_index) {
                   actual_segment_durations[++last_segment] = (unsigned int) rint(segment_time - prev_segment_time);
                   write_index = !write_index_file(playlistFilename, tempPlaylistName, segmentLength, actual_segment_durations, baseDirName, baseFileName, baseFileExtension, first_segment, last_segment);
                   fprintf(stderr, "Writing index file at time %lf\n", packet_time);
               }

               struct stat st;
               stat(currentOutputFileName, &amp;st);
               output_bytes += st.st_size;

               snprintf(currentOutputFileName, strlen(baseDirName) + strlen(baseFileName) + strlen(baseFileExtension) + 10, "%s%s-%u%s", baseDirName, baseFileName, output_index++, baseFileExtension);
               if (avio_open(&amp;oc->pb, currentOutputFileName, URL_WRONLY) &lt; 0) {
                   fprintf(stderr, "Could not open &#39;%s&#39;\n", currentOutputFileName);
                   break;
               }

               newFile = 1;
               prev_segment_time = segment_time;
           }

           if (outputStreams == OUTPUT_STREAM_AUDIO &amp;&amp; packet.stream_index == audio_index) {
               if (newFile &amp;&amp; outputStreams == OUTPUT_STREAM_AUDIO) {
                   //add id3 tag info
                   //fprintf(stderr, "adding id3tag to file %s\n", currentOutputFileName);
                   //printf("%lf %lld %lld %lld %lld %lld %lf\n", segment_time, audio_st->pts.val, audio_st->cur_dts, audio_st->cur_pkt.pts, packet.pts, packet.dts, packet.dts * av_q2d(ic->streams[audio_index]->time_base) );
                   fill_id3_tag((char*) id3_tag, id3_tag_size, packet.dts);
                   avio_write(oc->pb, id3_tag, id3_tag_size);
                   avio_write(oc->pb, image_id3_tag, IMAGE_ID3_SIZE);
                   avio_flush(oc->pb);
                   newFile = 0;
               }

               packet.stream_index = 0; //only one stream in audio only segments
               ret = av_interleaved_write_frame(oc, &amp;packet);
           } else if (outputStreams &amp; OUTPUT_STREAM_VIDEO) {
               if (newFile) {
                   //fprintf(stderr, "New File: %lld %lld %lld\n", packet.pts, video_st->pts.val, audio_st->pts.val);
                   //printf("%lf %lld %lld %lld %lld %lld %lf\n", segment_time, audio_st->pts.val, audio_st->cur_dts, audio_st->cur_pkt.pts, packet.pts, packet.dts, packet.dts * av_q2d(ic->streams[audio_index]->time_base) );
                   newFile = 0;
               }
               if (outputStreams == OUTPUT_STREAM_VIDEO)
                   ret = av_write_frame(oc, &amp;packet);
               else
                   ret = av_interleaved_write_frame(oc, &amp;packet);
           }

           if (ret &lt; 0) {
               fprintf(stderr, "Warning: Could not write frame of stream.\n");
           } else if (ret > 0) {
               fprintf(stderr, "End of stream requested.\n");
               av_free_packet(&amp;packet);
               break;
           }

           av_free_packet(&amp;packet);
       } while (!decode_done);

       //make sure all packets are written and then close the last file.
       avio_flush(oc->pb);
       av_write_trailer(oc);

       if (video_st &amp;&amp; video_st->codec)
           avcodec_close(video_st->codec);

       if (audio_st &amp;&amp; audio_st->codec)
           avcodec_close(audio_st->codec);

       for (i = 0; i &lt; oc->nb_streams; i++) {
           av_freep(&amp;oc->streams[i]->codec);
           av_freep(&amp;oc->streams[i]);
       }

       avio_close(oc->pb);
       av_free(oc);

       struct stat st;
       stat(currentOutputFileName, &amp;st);
       output_bytes += st.st_size;


       if (write_index) {
           actual_segment_durations[++last_segment] = (unsigned int) rint(packet_time - prev_segment_time);

           //make sure that the last segment length is not zero
           if (actual_segment_durations[last_segment] == 0)
               actual_segment_durations[last_segment] = 1;

           write_index_file(playlistFilename, tempPlaylistName, segmentLength, actual_segment_durations, baseDirName, baseFileName, baseFileExtension, first_segment, last_segment);

       }

       write_stream_size_file(baseDirName, baseFileName, output_bytes * 8 / segment_time);

       return 0;
    }
    </outfile></infile>