Recherche avancée

Médias (0)

Mot : - Tags -/protocoles

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (81)

  • Mediabox : ouvrir les images dans l’espace maximal pour l’utilisateur

    8 février 2011, par

    La visualisation des images est restreinte par la largeur accordée par le design du site (dépendant du thème utilisé). Elles sont donc visibles sous un format réduit. Afin de profiter de l’ensemble de la place disponible sur l’écran de l’utilisateur, il est possible d’ajouter une fonctionnalité d’affichage de l’image dans une boite multimedia apparaissant au dessus du reste du contenu.
    Pour ce faire il est nécessaire d’installer le plugin "Mediabox".
    Configuration de la boite multimédia
    Dès (...)

  • Ajouter des informations spécifiques aux utilisateurs et autres modifications de comportement liées aux auteurs

    12 avril 2011, par

    La manière la plus simple d’ajouter des informations aux auteurs est d’installer le plugin Inscription3. Il permet également de modifier certains comportements liés aux utilisateurs (référez-vous à sa documentation pour plus d’informations).
    Il est également possible d’ajouter des champs aux auteurs en installant les plugins champs extras 2 et Interface pour champs extras.

  • Automated installation script of MediaSPIP

    25 avril 2011, par

    To overcome the difficulties mainly due to the installation of server side software dependencies, an "all-in-one" installation script written in bash was created to facilitate this step on a server with a compatible Linux distribution.
    You must have access to your server via SSH and a root account to use it, which will install the dependencies. Contact your provider if you do not have that.
    The documentation of the use of this installation script is available here.
    The code of this (...)

Sur d’autres sites (4845)

  • avformat/utils : fix stream ordering for program ID stream specifiers

    19 mai 2019, par Marton Balint
    avformat/utils : fix stream ordering for program ID stream specifiers
    

    Fixes a regression introduced in dbfd042983eed8586d4048795c00af820f5b6b1f.

    Signed-off-by : Marton Balint <cus@passwd.hu>

    • [DH] doc/fftools-common-opts.texi
    • [DH] libavformat/utils.c
  • How to concat mp4 files using libffmpeg in c program ?

    1er août 2013, par chichien

    I know ffmpeg command line is easy, but how to programmatically implement? I'm not good at this,here is some code from internet, it is used to convert .mp4 to .ts,and i made some changes,but the audio stream problem persists:

    #include
    #include
    #include
    #include

    #include "libavformat/avformat.h"
    #include "libavcodec/avcodec.h"
    #include "libavutil/avutil.h"
    #include "libavutil/rational.h"
    #include "libavdevice/avdevice.h"
    #include "libavutil/mathematics.h"
    #include "libswscale/swscale.h"

    static AVStream* add_output_stream(AVFormatContext* output_format_context, AVStream* input_stream)
    {

       AVCodecContext* input_codec_context = NULL;
       AVCodecContext* output_codec_context = NULL;

       AVStream* output_stream = NULL;
       output_stream = av_new_stream(output_format_context, 0);
       if (!output_stream)
       {
           printf("Call av_new_stream function failed\n");
           return NULL;
       }

       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)
       {
       case AVMEDIA_TYPE_AUDIO:
           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;
       case AVMEDIA_TYPE_VIDEO:
           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;
    }

    //[[** from ffmpeg.c
    static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc){
       int ret;

       while(bsfc){
           AVPacket new_pkt= *pkt;
           int a= av_bitstream_filter_filter(bsfc, avctx, NULL,
                                             &amp;new_pkt.data, &amp;new_pkt.size,
                                             pkt->data, pkt->size,
                                             pkt->flags &amp; AV_PKT_FLAG_KEY);
           if(a>0){
               av_free_packet(pkt);
               new_pkt.destruct= av_destruct_packet;
           } else if(a&lt;0){
               fprintf(stderr, "%s failed for stream %d, codec %s\n",
                       bsfc->filter->name, pkt->stream_index,
                       avctx->codec ? avctx->codec->name : "copy");
               //print_error("", a);
               //if (exit_on_error)
               //    ffmpeg_exit(1);
           }
           *pkt= new_pkt;

           bsfc= bsfc->next;
       }

       ret= av_interleaved_write_frame(s, pkt);
       if(ret &lt; 0){
           //print_error("av_interleaved_write_frame()", ret);
           fprintf(stderr, "av_interleaved_write_frame(%d)\n", ret);
           exit(1);
       }
    }
    //]]**

    int main(int argc, char* argv[])
    {

       const char* input;
       const char* output;
       const char* output_prefix = NULL;
       char* segment_duration_check = 0;
       const char* index = NULL;
       char* tmp_index = NULL;
       const char* http_prefix = NULL;
       long max_tsfiles = NULL;
       double prev_segment_time = 0;
       double segment_duration = 0;

       AVInputFormat* ifmt = NULL;
       AVOutputFormat* ofmt = NULL;
       AVFormatContext* ic = NULL;
       AVFormatContext* oc = NULL;
       AVStream* video_st = NULL;
       AVStream* audio_st = NULL;
       AVCodec* codec = NULL;
       AVDictionary* pAVDictionary = NULL;

       long frame_count = 0;

       if (argc != 3) {
           fprintf(stderr, "Usage: %s inputfile outputfile\n", argv[0]);
           exit(1);
       }

       input = argv[1];
       output = argv[2];

       av_register_all();

       char szError[256] = {0};
       int nRet = avformat_open_input(&amp;ic, input, ifmt, &amp;pAVDictionary);
       if (nRet != 0)
       {
           av_strerror(nRet, szError, 256);
           printf(szError);
           printf("\n");
           printf("Call avformat_open_input function failed!\n");
           return 0;
       }

       if (av_find_stream_info(ic) &lt; 0)
       {
           printf("Call av_find_stream_info function failed!\n");
           return 0;
       }

       ofmt = av_guess_format("mpegts", NULL, NULL);
       if (!ofmt)
       {
           printf("Call av_guess_format function failed!\n");
           return 0;
       }

       oc = avformat_alloc_context();
       if (!oc)
       {
           printf("Call av_guess_format function failed!\n");
           return 0;
       }
       oc->oformat = ofmt;

       int video_index = -1, audio_index = -1;
       for (unsigned int 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)
           {
           case AVMEDIA_TYPE_VIDEO:
               video_index = i;
               ic->streams[i]->discard = AVDISCARD_NONE;
               video_st = add_output_stream(oc, ic->streams[i]);
               break;
           case AVMEDIA_TYPE_AUDIO:
               audio_index = i;
               ic->streams[i]->discard = AVDISCARD_NONE;
               audio_st = add_output_stream(oc, ic->streams[i]);
               break;
           default:
               ic->streams[i]->discard = AVDISCARD_ALL;
               break;
           }
       }
       codec = avcodec_find_decoder(video_st->codec->codec_id);
       if (codec == NULL)
       {
           printf("Call avcodec_find_decoder function failed!\n");
           return 0;
       }

       if (avcodec_open(video_st->codec, codec) &lt; 0)
       {
           printf("Call avcodec_open function failed !\n");
           return 0;
       }

       if (avio_open(&amp;oc->pb, output, AVIO_FLAG_WRITE) &lt; 0)
       {
           return 0;
       }

       if (avformat_write_header(oc, &amp;pAVDictionary))
       {
           printf("Call avformat_write_header function failed.\n");
           return 0;
       }

       //[[++
       AVBitStreamFilterContext *bsfc = av_bitstream_filter_init("h264_mp4toannexb");
       //AVBitStreamFilterContext *absfc = av_bitstream_filter_init("aac_adtstoasc");
       if (!bsfc) {
           fprintf(stderr, "bsf init error!\n");
           return -1;
       }
       //]]++

       int decode_done = 0;
       do
       {
           double segment_time = 0;
           AVPacket packet;

           decode_done = av_read_frame(ic, &amp;packet);
           if (decode_done &lt; 0)
               break;

           if (av_dup_packet(&amp;packet) &lt; 0)
           {
               printf("Call av_dup_packet function failed\n");
               av_free_packet(&amp;packet);
               break;
           }

           //[[**
           if (packet.stream_index == audio_index) {
               segment_time = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;
               nRet = av_interleaved_write_frame(oc, &amp;packet);  
           } else if (packet.stream_index == video_index) {
               if (packet.flags &amp; AV_PKT_FLAG_KEY) {
                   segment_time = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;
               } else {
                   segment_time = prev_segment_time;
               }
               //nRet = av_interleaved_write_frame(oc, &amp;packet);  
               write_frame(oc, &amp;packet, video_st->codec, bsfc);
           }
           //]]**

           if (nRet &lt; 0)
           {
               printf("Call av_interleaved_write_frame function failed: %d\n", nRet);
           }
           else if (nRet > 0)
           {
               printf("End of stream requested\n");
               av_free_packet(&amp;packet);
               break;
           }
           av_free_packet(&amp;packet);
           frame_count++;
       }while(!decode_done);

       av_write_trailer(oc);
       printf("frame_count = %d\n", frame_count);

       av_bitstream_filter_close(bsfc);  
       avcodec_close(video_st->codec);
       for(unsigned int k = 0; k &lt; oc->nb_streams; k++)
       {
           av_freep(&amp;oc->streams[k]->codec);
           av_freep(&amp;oc->streams[k]);
       }
       av_free(oc);
       //getchar();
       return 0;
    }

    Compile this code, to got an executable file named muxts, and then :

    $ ./muxts vid1.mp4 vid1.ts

    No error message printed,but the audio stream was unsynchronized and noise。Check the .ts file using ffmpeg :

    $ ffmpeg -i vid1.ts
    ffmpeg version 0.8.14-tessus, Copyright (c) 2000-2013 the FFmpeg developers
     built on Jul 29 2013 17:05:18 with llvm_gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
     configuration: --prefix=/usr/local --arch=x86_64 --as=yasm --extra-version=tessus --enable-gpl --enable-nonfree --enable-version3 --disable-ffplay --enable-libvorbis --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-bzlib --enable-zlib --enable-postproc --enable-filters --enable-runtime-cpudetect --enable-debug=3 --disable-optimizations
     libavutil    51.  9. 1 / 51.  9. 1
     libavcodec   53.  8. 0 / 53.  8. 0
     libavformat  53.  5. 0 / 53.  5. 0
     libavdevice  53.  1. 1 / 53.  1. 1
     libavfilter   2. 23. 0 /  2. 23. 0
     libswscale    2.  0. 0 /  2.  0. 0
     libpostproc  51.  2. 0 / 51.  2. 0

    Seems stream 0 codec frame rate differs from container frame rate: 180000.00 (180000/1) -> 90000.00 (180000/2)
    Input #0, mpegts, from &#39;vid1.ts&#39;:
     Duration: 00:00:03.75, start: 0.000000, bitrate: 3656 kb/s
     Program 1
       Metadata:
         service_name    : Service01
         service_provider: FFmpeg
       Stream #0.0[0x100]: Video: h264 (Baseline), yuv420p, 640x480, 90k tbr, 90k tbn, 180k tbc
       Stream #0.1[0x101]: Audio: aac, 48000 Hz, mono, s16, 190 kb/s
    At least one output file must be specified

    What should i do ?

    If this issue fixed , how can i concat multi .ts files into single .mp4 file ?

  • How can I fix a segmentation fault in a C program ? [duplicate]

    31 mars 2023, par ipegasus
    &#xA;

    Possible Duplicate :
    &#xA;Segmentation fault

    &#xA;

    &#xA;

    Currently I am upgrading an open source program used for HTTP streaming. It needs to support the latest FFmpeg.&#xA;The code compiles fine without any warnings, although I am getting a segmentation fault error.

    &#xA;

    How can I fix the issue ? And / or, what is 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 :)

    &#xA;

    Sample Usage

    &#xA;

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

    &#xA;

    Makefile

    &#xA;

    FFLIBS=`pkg-config --libs libavformat libavcodec libavutil`&#xA;FFFLAGS=`pkg-config --cflags libavformat libavcodec libavutil`&#xA;&#xA;all:&#xA;    gcc -Wall -g segmenter.c -o segmenter ${FFFLAGS} ${FFLIBS}&#xA;

    &#xA;

    segmenter.c

    &#xA;

    /*&#xA; * Copyright (c) 2009 Chase Douglas&#xA; *&#xA; * This program is free software; you can redistribute it and/or&#xA; * modify it under the terms of the GNU General Public License version 2&#xA; * as published by the Free Software Foundation.&#xA; *&#xA; * This program is distributed in the hope that it will be useful,&#xA; * but WITHOUT ANY WARRANTY; without even the implied warranty of&#xA; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&#xA; * GNU General Public License for more details.&#xA; *&#xA; * You should have received a copy of the GNU General Public License&#xA; * along with this program; if not, write to the Free Software&#xA; * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.&#xA; */&#xA;#include &#xA;#include &#xA;#include &#xA;#include &#xA;#include &#xA;#include "libavformat/avformat.h"&#xA;&#xA;#include "libavformat/avio.h"&#xA;&#xA;#include <sys></sys>stat.h>&#xA;&#xA;#include "segmenter.h"&#xA;#include "libavformat/avformat.h"&#xA;&#xA;#define IMAGE_ID3_SIZE 9171&#xA;&#xA;void printUsage() {&#xA;    fprintf(stderr, "\nExample: segmenter --i infile --d baseDir --f baseFileName --o playListFile.m3u8 --l 10 \n");&#xA;    fprintf(stderr, "\nOptions: \n");&#xA;    fprintf(stderr, "--i <infile>.\n");&#xA;    fprintf(stderr, "--o <outfile>.\n");&#xA;    fprintf(stderr, "--d basedir, the base directory for files.\n");&#xA;    fprintf(stderr, "--f baseFileName, output files will be baseFileName-#.\n");&#xA;    fprintf(stderr, "--l segment length, the length of each segment.\n");&#xA;    fprintf(stderr, "--a,  audio only decode for &lt; 64k streams.\n");&#xA;    fprintf(stderr, "--v,  video only decode for &lt; 64k streams.\n");&#xA;    fprintf(stderr, "--version, print version details and exit.\n");&#xA;    fprintf(stderr, "\n\n");&#xA;}&#xA;&#xA;void ffmpeg_version() {&#xA;    // output build and version numbers&#xA;    fprintf(stderr, "  libavutil version:   %s\n", AV_STRINGIFY(LIBAVUTIL_VERSION));&#xA;    fprintf(stderr, "  libavutil build:     %d\n", LIBAVUTIL_BUILD);&#xA;    fprintf(stderr, "  libavcodec version:  %s\n", AV_STRINGIFY(LIBAVCODEC_VERSION));&#xA;    fprintf(stdout, "  libavcodec build:    %d\n", LIBAVCODEC_BUILD);&#xA;    fprintf(stderr, "  libavformat version: %s\n", AV_STRINGIFY(LIBAVFORMAT_VERSION));&#xA;    fprintf(stderr, "  libavformat build:   %d\n", LIBAVFORMAT_BUILD);&#xA;    fprintf(stderr, "  built on " __DATE__ " " __TIME__);&#xA;#ifdef __GNUC__&#xA;    fprintf(stderr, ", gcc: " __VERSION__ "\n");&#xA;#else&#xA;    fprintf(stderr, ", using a non-gcc compiler\n");&#xA;#endif&#xA;}&#xA;&#xA;&#xA;static AVStream *add_output_stream(AVFormatContext *output_format_context, AVStream *input_stream) {&#xA;    AVCodecContext *input_codec_context;&#xA;    AVCodecContext *output_codec_context;&#xA;    AVStream *output_stream;&#xA;&#xA;    output_stream = avformat_new_stream(output_format_context, 0);&#xA;    if (!output_stream) {&#xA;        fprintf(stderr, "Segmenter error: Could not allocate stream\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    input_codec_context = input_stream->codec;&#xA;    output_codec_context = output_stream->codec;&#xA;&#xA;    output_codec_context->codec_id = input_codec_context->codec_id;&#xA;    output_codec_context->codec_type = input_codec_context->codec_type;&#xA;    output_codec_context->codec_tag = input_codec_context->codec_tag;&#xA;    output_codec_context->bit_rate = input_codec_context->bit_rate;&#xA;    output_codec_context->extradata = input_codec_context->extradata;&#xA;    output_codec_context->extradata_size = input_codec_context->extradata_size;&#xA;&#xA;    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) {&#xA;        output_codec_context->time_base = input_codec_context->time_base;&#xA;        output_codec_context->time_base.num *= input_codec_context->ticks_per_frame;&#xA;    } else {&#xA;        output_codec_context->time_base = input_stream->time_base;&#xA;    }&#xA;&#xA;    switch (input_codec_context->codec_type) {&#xA;#ifdef USE_OLD_FFMPEG&#xA;        case CODEC_TYPE_AUDIO:&#xA;#else&#xA;        case AVMEDIA_TYPE_AUDIO:&#xA;#endif&#xA;            output_codec_context->channel_layout = input_codec_context->channel_layout;&#xA;            output_codec_context->sample_rate = input_codec_context->sample_rate;&#xA;            output_codec_context->channels = input_codec_context->channels;&#xA;            output_codec_context->frame_size = input_codec_context->frame_size;&#xA;            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) {&#xA;                output_codec_context->block_align = 0;&#xA;            } else {&#xA;                output_codec_context->block_align = input_codec_context->block_align;&#xA;            }&#xA;            break;&#xA;#ifdef USE_OLD_FFMPEG&#xA;        case CODEC_TYPE_VIDEO:&#xA;#else&#xA;        case AVMEDIA_TYPE_VIDEO:&#xA;#endif&#xA;            output_codec_context->pix_fmt = input_codec_context->pix_fmt;&#xA;            output_codec_context->width = input_codec_context->width;&#xA;            output_codec_context->height = input_codec_context->height;&#xA;            output_codec_context->has_b_frames = input_codec_context->has_b_frames;&#xA;&#xA;            if (output_format_context->oformat->flags &amp; AVFMT_GLOBALHEADER) {&#xA;                output_codec_context->flags |= CODEC_FLAG_GLOBAL_HEADER;&#xA;            }&#xA;            break;&#xA;        default:&#xA;            break;&#xA;    }&#xA;&#xA;    return output_stream;&#xA;}&#xA;&#xA;int write_index_file(const char index[], const char tmp_index[], const unsigned int planned_segment_duration, const unsigned int actual_segment_duration[],&#xA;        const char output_directory[], const char output_prefix[], const char output_file_extension[],&#xA;        const unsigned int first_segment, const unsigned int last_segment) {&#xA;    FILE *index_fp;&#xA;    char *write_buf;&#xA;    unsigned int i;&#xA;&#xA;    index_fp = fopen(tmp_index, "w");&#xA;    if (!index_fp) {&#xA;        fprintf(stderr, "Could not open temporary m3u8 index file (%s), no index file will be created\n", tmp_index);&#xA;        return -1;&#xA;    }&#xA;&#xA;    write_buf = malloc(sizeof (char) * 1024);&#xA;    if (!write_buf) {&#xA;        fprintf(stderr, "Could not allocate write buffer for index file, index file will be invalid\n");&#xA;        fclose(index_fp);&#xA;        return -1;&#xA;    }&#xA;&#xA;    unsigned int maxDuration = planned_segment_duration;&#xA;&#xA;    for (i = first_segment; i &lt;= last_segment; i&#x2B;&#x2B;)&#xA;        if (actual_segment_duration[i] > maxDuration)&#xA;            maxDuration = actual_segment_duration[i];&#xA;&#xA;&#xA;&#xA;    snprintf(write_buf, 1024, "#EXTM3U\n#EXT-X-TARGETDURATION:%u\n", maxDuration);&#xA;&#xA;    if (fwrite(write_buf, strlen(write_buf), 1, index_fp) != 1) {&#xA;        fprintf(stderr, "Could not write to m3u8 index file, will not continue writing to index file\n");&#xA;        free(write_buf);&#xA;        fclose(index_fp);&#xA;        return -1;&#xA;    }&#xA;&#xA;    for (i = first_segment; i &lt;= last_segment; i&#x2B;&#x2B;) {&#xA;        snprintf(write_buf, 1024, "#EXTINF:%u,\n%s-%u%s\n", actual_segment_duration[i], output_prefix, i, output_file_extension);&#xA;        if (fwrite(write_buf, strlen(write_buf), 1, index_fp) != 1) {&#xA;            fprintf(stderr, "Could not write to m3u8 index file, will not continue writing to index file\n");&#xA;            free(write_buf);&#xA;            fclose(index_fp);&#xA;            return -1;&#xA;        }&#xA;    }&#xA;&#xA;    snprintf(write_buf, 1024, "#EXT-X-ENDLIST\n");&#xA;    if (fwrite(write_buf, strlen(write_buf), 1, index_fp) != 1) {&#xA;        fprintf(stderr, "Could not write last file and endlist tag to m3u8 index file\n");&#xA;        free(write_buf);&#xA;        fclose(index_fp);&#xA;        return -1;&#xA;    }&#xA;&#xA;    free(write_buf);&#xA;    fclose(index_fp);&#xA;&#xA;    return rename(tmp_index, index);&#xA;}&#xA;&#xA;int main(int argc, const char *argv[]) {&#xA;    //input parameters&#xA;    char inputFilename[MAX_FILENAME_LENGTH], playlistFilename[MAX_FILENAME_LENGTH], baseDirName[MAX_FILENAME_LENGTH], baseFileName[MAX_FILENAME_LENGTH];&#xA;    char baseFileExtension[5]; //either "ts", "aac" or "mp3"&#xA;    int segmentLength, outputStreams, verbosity, version;&#xA;&#xA;&#xA;&#xA;    char currentOutputFileName[MAX_FILENAME_LENGTH];&#xA;    char tempPlaylistName[MAX_FILENAME_LENGTH];&#xA;&#xA;&#xA;    //these are used to determine the exact length of the current segment&#xA;    double prev_segment_time = 0;&#xA;    double segment_time;&#xA;    unsigned int actual_segment_durations[2048];&#xA;    double packet_time = 0;&#xA;&#xA;    //new variables to keep track of output size&#xA;    double output_bytes = 0;&#xA;&#xA;    unsigned int output_index = 1;&#xA;    AVOutputFormat *ofmt;&#xA;    AVFormatContext *ic = NULL;&#xA;    AVFormatContext *oc;&#xA;    AVStream *video_st = NULL;&#xA;    AVStream *audio_st = NULL;&#xA;    AVCodec *codec;&#xA;    int video_index;&#xA;    int audio_index;&#xA;    unsigned int first_segment = 1;&#xA;    unsigned int last_segment = 0;&#xA;    int write_index = 1;&#xA;    int decode_done;&#xA;    int ret;&#xA;    int i;&#xA;&#xA;    unsigned char id3_tag[128];&#xA;    unsigned char * image_id3_tag;&#xA;&#xA;    size_t id3_tag_size = 73;&#xA;    int newFile = 1; //a boolean value to flag when a new file needs id3 tag info in it&#xA;&#xA;    if (parseCommandLine(inputFilename, playlistFilename, baseDirName, baseFileName, baseFileExtension, &amp;outputStreams, &amp;segmentLength, &amp;verbosity, &amp;version, argc, argv) != 0)&#xA;        return 0;&#xA;&#xA;    if (version) {&#xA;        ffmpeg_version();&#xA;        return 0;&#xA;    }&#xA;&#xA;&#xA;    fprintf(stderr, "%s %s\n", playlistFilename, tempPlaylistName);&#xA;&#xA;&#xA;    image_id3_tag = malloc(IMAGE_ID3_SIZE);&#xA;    if (outputStreams == OUTPUT_STREAM_AUDIO)&#xA;        build_image_id3_tag(image_id3_tag);&#xA;    build_id3_tag((char *) id3_tag, id3_tag_size);&#xA;&#xA;    snprintf(tempPlaylistName, strlen(playlistFilename) &#x2B; strlen(baseDirName) &#x2B; 1, "%s%s", baseDirName, playlistFilename);&#xA;    strncpy(playlistFilename, tempPlaylistName, strlen(tempPlaylistName));&#xA;    strncpy(tempPlaylistName, playlistFilename, MAX_FILENAME_LENGTH);&#xA;    strncat(tempPlaylistName, ".", 1);&#xA;&#xA;    //decide if this is an aac file or a mpegts file.&#xA;    //postpone deciding format until later&#xA;    /*    ifmt = av_find_input_format("mpegts");&#xA;    if (!ifmt)&#xA;    {&#xA;    fprintf(stderr, "Could not find MPEG-TS demuxer.\n");&#xA;    exit(1);&#xA;    } */&#xA;&#xA;    av_log_set_level(AV_LOG_DEBUG);&#xA;&#xA;    av_register_all();&#xA;    ret = avformat_open_input(&amp;ic, inputFilename, NULL, NULL);&#xA;    if (ret != 0) {&#xA;        fprintf(stderr, "Could not open input file %s. Error %d.\n", inputFilename, ret);&#xA;        exit(1);&#xA;    }&#xA;&#xA;    if (avformat_find_stream_info(ic, NULL) &lt; 0) {&#xA;        fprintf(stderr, "Could not read stream information.\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    oc = avformat_alloc_context();&#xA;    if (!oc) {&#xA;        fprintf(stderr, "Could not allocate output context.");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    video_index = -1;&#xA;    audio_index = -1;&#xA;&#xA;    for (i = 0; i &lt; ic->nb_streams &amp;&amp; (video_index &lt; 0 || audio_index &lt; 0); i&#x2B;&#x2B;) {&#xA;        switch (ic->streams[i]->codec->codec_type) {&#xA;&#xA;#ifdef USE_OLD_FFMPEG&#xA;            case CODEC_TYPE_VIDEO:&#xA;#else&#xA;            case AVMEDIA_TYPE_VIDEO:&#xA;#endif&#xA;                video_index = i;&#xA;                ic->streams[i]->discard = AVDISCARD_NONE;&#xA;                if (outputStreams &amp; OUTPUT_STREAM_VIDEO)&#xA;                    video_st = add_output_stream(oc, ic->streams[i]);&#xA;                break;&#xA;#ifdef USE_OLD_FFMPEG&#xA;            case CODEC_TYPE_AUDIO:&#xA;#else&#xA;            case AVMEDIA_TYPE_AUDIO:&#xA;#endif&#xA;                audio_index = i;&#xA;                ic->streams[i]->discard = AVDISCARD_NONE;&#xA;                if (outputStreams &amp; OUTPUT_STREAM_AUDIO)&#xA;                    audio_st = add_output_stream(oc, ic->streams[i]);&#xA;                break;&#xA;            default:&#xA;                ic->streams[i]->discard = AVDISCARD_ALL;&#xA;                break;&#xA;        }&#xA;    }&#xA;&#xA;    if (video_index == -1) {&#xA;        fprintf(stderr, "Stream must have video component.\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    //now that we know the audio and video output streams&#xA;    //we can decide on an output format.&#xA;    if (outputStreams == OUTPUT_STREAM_AUDIO) {&#xA;        //the audio output format should be the same as the audio input format&#xA;        switch (ic->streams[audio_index]->codec->codec_id) {&#xA;            case CODEC_ID_MP3:&#xA;                fprintf(stderr, "Setting output audio to mp3.");&#xA;                strncpy(baseFileExtension, ".mp3", strlen(".mp3"));&#xA;                ofmt = av_guess_format("mp3", NULL, NULL);&#xA;                break;&#xA;            case CODEC_ID_AAC:&#xA;                fprintf(stderr, "Setting output audio to aac.");&#xA;                ofmt = av_guess_format("adts", NULL, NULL);&#xA;                break;&#xA;            default:&#xA;                fprintf(stderr, "Codec id %d not supported.\n", ic->streams[audio_index]->id);&#xA;        }&#xA;        if (!ofmt) {&#xA;            fprintf(stderr, "Could not find audio muxer.\n");&#xA;            exit(1);&#xA;        }&#xA;    } else {&#xA;        ofmt = av_guess_format("mpegts", NULL, NULL);&#xA;        if (!ofmt) {&#xA;            fprintf(stderr, "Could not find MPEG-TS muxer.\n");&#xA;            exit(1);&#xA;        }&#xA;    }&#xA;    oc->oformat = ofmt;&#xA;&#xA;    if (outputStreams &amp; OUTPUT_STREAM_VIDEO &amp;&amp; oc->oformat->flags &amp; AVFMT_GLOBALHEADER) {&#xA;        oc->flags |= CODEC_FLAG_GLOBAL_HEADER;&#xA;    }&#xA;&#xA;&#xA;    /*  Deprecated: pass the options to avformat_write_header directly.&#xA;        if (av_set_parameters(oc, NULL) &lt; 0) {&#xA;            fprintf(stderr, "Invalid output format parameters.\n");&#xA;            exit(1);&#xA;        }&#xA;     */&#xA;&#xA;    av_dump_format(oc, 0, baseFileName, 1);&#xA;&#xA;&#xA;    //open the video codec only if there is video data&#xA;    if (video_index != -1) {&#xA;        if (outputStreams &amp; OUTPUT_STREAM_VIDEO)&#xA;            codec = avcodec_find_decoder(video_st->codec->codec_id);&#xA;        else&#xA;            codec = avcodec_find_decoder(ic->streams[video_index]->codec->codec_id);&#xA;        if (!codec) {&#xA;            fprintf(stderr, "Could not find video decoder, key frames will not be honored.\n");&#xA;        }&#xA;&#xA;        if (outputStreams &amp; OUTPUT_STREAM_VIDEO)&#xA;            ret = avcodec_open2(video_st->codec, codec, NULL);&#xA;        else&#xA;            avcodec_open2(ic->streams[video_index]->codec, codec, NULL);&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Could not open video decoder, key frames will not be honored.\n");&#xA;        }&#xA;    }&#xA;&#xA;    snprintf(currentOutputFileName, strlen(baseDirName) &#x2B; strlen(baseFileName) &#x2B; strlen(baseFileExtension) &#x2B; 10, "%s%s-%u%s", baseDirName, baseFileName, output_index&#x2B;&#x2B;, baseFileExtension);&#xA;&#xA;    if (avio_open(&amp;oc->pb, currentOutputFileName, URL_WRONLY) &lt; 0) {&#xA;        fprintf(stderr, "Could not open &#x27;%s&#x27;.\n", currentOutputFileName);&#xA;        exit(1);&#xA;    }&#xA;    newFile = 1;&#xA;&#xA;    int r = avformat_write_header(oc,NULL);&#xA;    if (r) {&#xA;        fprintf(stderr, "Could not write mpegts header to first output file.\n");&#xA;        debugReturnCode(r);&#xA;        exit(1);&#xA;    }&#xA;&#xA;    //no segment info is written here. This just creates the shell of the playlist file&#xA;    write_index = !write_index_file(playlistFilename, tempPlaylistName, segmentLength, actual_segment_durations, baseDirName, baseFileName, baseFileExtension, first_segment, last_segment);&#xA;&#xA;    do {&#xA;        AVPacket packet;&#xA;&#xA;        decode_done = av_read_frame(ic, &amp;packet);&#xA;&#xA;        if (decode_done &lt; 0) {&#xA;            break;&#xA;        }&#xA;&#xA;        if (av_dup_packet(&amp;packet) &lt; 0) {&#xA;            fprintf(stderr, "Could not duplicate packet.");&#xA;            av_free_packet(&amp;packet);&#xA;            break;&#xA;        }&#xA;&#xA;        //this time is used to check for a break in the segments&#xA;        //    if (packet.stream_index == video_index &amp;&amp; (packet.flags &amp; PKT_FLAG_KEY))&#xA;        //    {&#xA;        //    segment_time = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;&#xA;        //    }&#xA;#if USE_OLD_FFMPEG&#xA;        if (packet.stream_index == video_index &amp;&amp; (packet.flags &amp; PKT_FLAG_KEY))&#xA;#else&#xA;        if (packet.stream_index == video_index &amp;&amp; (packet.flags &amp; AV_PKT_FLAG_KEY))&#xA;#endif&#xA;        {&#xA;            segment_time = (double) packet.pts * ic->streams[video_index]->time_base.num / ic->streams[video_index]->time_base.den;&#xA;        }&#xA;        //  else if (video_index &lt; 0)&#xA;        //    {&#xA;        //        segment_time = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;&#xA;        //    }&#xA;&#xA;        //get the most recent packet time&#xA;        //this time is used when the time for the final segment is printed. It may not be on the edge of&#xA;        //of a keyframe!&#xA;        if (packet.stream_index == video_index)&#xA;            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;&#xA;        else if (outputStreams &amp; OUTPUT_STREAM_AUDIO)&#xA;            packet_time = (double) audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;&#xA;        else&#xA;            continue;&#xA;        //start looking for segment splits for videos one half second before segment duration expires. This is because the&#xA;        //segments are split on key frames so we cannot expect all segments to be split exactly equally.&#xA;        if (segment_time - prev_segment_time >= segmentLength - 0.5) {&#xA;            fprintf(stderr, "looking to print index file at time %lf\n", segment_time);&#xA;            avio_flush(oc->pb);&#xA;            avio_close(oc->pb);&#xA;&#xA;            if (write_index) {&#xA;                actual_segment_durations[&#x2B;&#x2B;last_segment] = (unsigned int) rint(segment_time - prev_segment_time);&#xA;                write_index = !write_index_file(playlistFilename, tempPlaylistName, segmentLength, actual_segment_durations, baseDirName, baseFileName, baseFileExtension, first_segment, last_segment);&#xA;                fprintf(stderr, "Writing index file at time %lf\n", packet_time);&#xA;            }&#xA;&#xA;            struct stat st;&#xA;            stat(currentOutputFileName, &amp;st);&#xA;            output_bytes &#x2B;= st.st_size;&#xA;&#xA;            snprintf(currentOutputFileName, strlen(baseDirName) &#x2B; strlen(baseFileName) &#x2B; strlen(baseFileExtension) &#x2B; 10, "%s%s-%u%s", baseDirName, baseFileName, output_index&#x2B;&#x2B;, baseFileExtension);&#xA;            if (avio_open(&amp;oc->pb, currentOutputFileName, URL_WRONLY) &lt; 0) {&#xA;                fprintf(stderr, "Could not open &#x27;%s&#x27;\n", currentOutputFileName);&#xA;                break;&#xA;            }&#xA;&#xA;            newFile = 1;&#xA;            prev_segment_time = segment_time;&#xA;        }&#xA;&#xA;        if (outputStreams == OUTPUT_STREAM_AUDIO &amp;&amp; packet.stream_index == audio_index) {&#xA;            if (newFile &amp;&amp; outputStreams == OUTPUT_STREAM_AUDIO) {&#xA;                //add id3 tag info&#xA;                //fprintf(stderr, "adding id3tag to file %s\n", currentOutputFileName);&#xA;                //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) );&#xA;                fill_id3_tag((char*) id3_tag, id3_tag_size, packet.dts);&#xA;                avio_write(oc->pb, id3_tag, id3_tag_size);&#xA;                avio_write(oc->pb, image_id3_tag, IMAGE_ID3_SIZE);&#xA;                avio_flush(oc->pb);&#xA;                newFile = 0;&#xA;            }&#xA;&#xA;            packet.stream_index = 0; //only one stream in audio only segments&#xA;            ret = av_interleaved_write_frame(oc, &amp;packet);&#xA;        } else if (outputStreams &amp; OUTPUT_STREAM_VIDEO) {&#xA;            if (newFile) {&#xA;                //fprintf(stderr, "New File: %lld %lld %lld\n", packet.pts, video_st->pts.val, audio_st->pts.val);&#xA;                //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) );&#xA;                newFile = 0;&#xA;            }&#xA;            if (outputStreams == OUTPUT_STREAM_VIDEO)&#xA;                ret = av_write_frame(oc, &amp;packet);&#xA;            else&#xA;                ret = av_interleaved_write_frame(oc, &amp;packet);&#xA;        }&#xA;&#xA;        if (ret &lt; 0) {&#xA;            fprintf(stderr, "Warning: Could not write frame of stream.\n");&#xA;        } else if (ret > 0) {&#xA;            fprintf(stderr, "End of stream requested.\n");&#xA;            av_free_packet(&amp;packet);&#xA;            break;&#xA;        }&#xA;&#xA;        av_free_packet(&amp;packet);&#xA;    } while (!decode_done);&#xA;&#xA;    //make sure all packets are written and then close the last file.&#xA;    avio_flush(oc->pb);&#xA;    av_write_trailer(oc);&#xA;&#xA;    if (video_st &amp;&amp; video_st->codec)&#xA;        avcodec_close(video_st->codec);&#xA;&#xA;    if (audio_st &amp;&amp; audio_st->codec)&#xA;        avcodec_close(audio_st->codec);&#xA;&#xA;    for (i = 0; i &lt; oc->nb_streams; i&#x2B;&#x2B;) {&#xA;        av_freep(&amp;oc->streams[i]->codec);&#xA;        av_freep(&amp;oc->streams[i]);&#xA;    }&#xA;&#xA;    avio_close(oc->pb);&#xA;    av_free(oc);&#xA;&#xA;    struct stat st;&#xA;    stat(currentOutputFileName, &amp;st);&#xA;    output_bytes &#x2B;= st.st_size;&#xA;&#xA;&#xA;    if (write_index) {&#xA;        actual_segment_durations[&#x2B;&#x2B;last_segment] = (unsigned int) rint(packet_time - prev_segment_time);&#xA;&#xA;        //make sure that the last segment length is not zero&#xA;        if (actual_segment_durations[last_segment] == 0)&#xA;            actual_segment_durations[last_segment] = 1;&#xA;&#xA;        write_index_file(playlistFilename, tempPlaylistName, segmentLength, actual_segment_durations, baseDirName, baseFileName, baseFileExtension, first_segment, last_segment);&#xA;&#xA;    }&#xA;&#xA;    write_stream_size_file(baseDirName, baseFileName, output_bytes * 8 / segment_time);&#xA;&#xA;    return 0;&#xA;}&#xA;</outfile></infile>

    &#xA;