Recherche avancée

Médias (0)

Mot : - Tags -/xmlrpc

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

Autres articles (61)

  • Soumettre améliorations et plugins supplémentaires

    10 avril 2011

    Si vous avez développé une nouvelle extension permettant d’ajouter une ou plusieurs fonctionnalités utiles à MediaSPIP, faites le nous savoir et son intégration dans la distribution officielle sera envisagée.
    Vous pouvez utiliser la liste de discussion de développement afin de le faire savoir ou demander de l’aide quant à la réalisation de ce plugin. MediaSPIP étant basé sur SPIP, il est également possible d’utiliser le liste de discussion SPIP-zone de SPIP pour (...)

  • Contribute to translation

    13 avril 2011

    You can help us to improve the language used in the software interface to make MediaSPIP more accessible and user-friendly. You can also translate the interface into any language that allows it to spread to new linguistic communities.
    To do this, we use the translation interface of SPIP where the all the language modules of MediaSPIP are available. Just subscribe to the mailing list and request further informantion on translation.
    MediaSPIP is currently available in French and English (...)

  • Contribute to documentation

    13 avril 2011

    Documentation is vital to the development of improved technical capabilities.
    MediaSPIP welcomes documentation by users as well as developers - including : critique of existing features and functions articles contributed by developers, administrators, content producers and editors screenshots to illustrate the above translations of existing documentation into other languages
    To contribute, register to the project users’ mailing (...)

Sur d’autres sites (9167)

  • Issues with FFMPEG swresample and channel mapping

    19 mars 2024, par Joseph Katrinka

    Ive linked FFMPEG libs to a C++ project Im working on in VS2017 and have had mostly no problems with it so far.
Im currently trying to use it to extract audio from a movie file and save it as a wav file.
I managed to do this just fine, and my next step is to make a "split into mono". To make 2 mono wav files, one from the left channel and one from the right channel of a stereo file.
My code works for the orignal usecase, stereo to stereo (one wav file) and also works for when Im just doing the left, but when doing the right it fails.

    


    Exception thrown at 0x00007FF9603F2D20 (swresample-4.dll) in Matchbox.exe : 0xC0000005 : Access violation reading location 0x0000000000000000.

    


    This is the relevent code involved. It is failing inside the processing loop on line :
int ret = swr_convert_frame(swrCtx, resampledFrame, frame);

    


    /// FFMPEG init
    AVFormatContext* formatCtx = nullptr;
    AVCodecContext* codecCtx = nullptr;
    const AVCodec* codec = nullptr;
    SwrContext* swrCtx = nullptr;
    AVPacket* packet = nullptr;
    AVFrame* frame = nullptr;
    AVFrame* resampledFrame = nullptr;
    int audioStreamIndex = -1;

    int sampleRate;

    uint64_t in_channel_layout = AV_CH_LAYOUT_STEREO; /// we only care about stereo in for now
    uint64_t out_channel_layout = doMono ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;

    /// some redundancy in this stream setup/checking
    if (avformat_open_input(&formatCtx, movieFilePath.toRawUTF8(), nullptr, nullptr) < 0)
    {
        DBG("failed to open input file");
        return false;
    }
    if (avformat_find_stream_info(formatCtx, nullptr) < 0)
    {
        DBG("failed to find stream info");
        return false;
    }

    for (unsigned i = 0; i < formatCtx->nb_streams; i++) {
        if (formatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
        {
            audioStreamIndex = i;
            break;
        }
    }
    if (audioStreamIndex == -1)
    {
        DBG("audio stream not found");
        return false;
    }

    codec = avcodec_find_decoder(formatCtx->streams[audioStreamIndex]->codecpar->codec_id);
    if (!codec)
    {
        DBG("decoder not found for audio stream");
        return false;
    }

    codecCtx = avcodec_alloc_context3(codec);
    if (avcodec_parameters_to_context(codecCtx, formatCtx->streams[audioStreamIndex]->codecpar) < 0)
    {
        DBG("failed to copy codec params to codec context");
        return false;
    }
    if (avcodec_open2(codecCtx, codec, nullptr) < 0)
    {
        DBG("failed to open codec");
        return false;
    }

    if (codecCtx->channels != 2)
    {
        DBG("unsupported channel layout");
        return false;
    }

    if (!codecCtx->channel_layout)
    {
        codecCtx->channel_layout = av_get_default_channel_layout(codecCtx->channels);
    }

    sampleRate = codecCtx->sample_rate; /// using this later for timecode calculation

    packet = av_packet_alloc();
    frame = av_frame_alloc();
    resampledFrame = av_frame_alloc();

    /// the input frame requires this info
    frame->format = codecCtx->sample_fmt;
    frame->channel_layout = codecCtx->channel_layout;
    frame->sample_rate = codecCtx->sample_rate;

    // does the resampled frame really need this?
    resampledFrame->format = AV_SAMPLE_FMT_S16;
    resampledFrame->channel_layout = out_channel_layout;
    resampledFrame->sample_rate = codecCtx->sample_rate;

    if (!packet || !frame || !resampledFrame)
    {
        DBG("failed to allocate packed or frame");
        return false;
    }

    /// Set up swrCtx for channel mapping if we need it
    swrCtx = swr_alloc();
    av_opt_set_int(swrCtx, "in_channel_layout", codecCtx->channel_layout, 0);
    av_opt_set_int(swrCtx, "out_channel_layout", out_channel_layout, 0);
    av_opt_set_int(swrCtx, "in_sample_rate", codecCtx->sample_rate, 0);
    av_opt_set_int(swrCtx, "out_sample_rate", codecCtx->sample_rate, 0);
    av_opt_set_sample_fmt(swrCtx, "in_sample_fmt", codecCtx->sample_fmt, 0);
    av_opt_set_sample_fmt(swrCtx, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);

    /// channel mapping if we are doing mono
    if (doMono)
    {
        DBG("WE ARE DOING MONO");
        int in_channel_map[2];
        if (useLeft)
        {
            DBG("WE ARE DOING LEFT");
            in_channel_map[0] = AV_CH_FRONT_LEFT;
        }
        else
        {
            DBG("WE ARE DOING RIGHT");
            in_channel_map[0] = AV_CH_FRONT_RIGHT;
        }
        in_channel_map[1] = -1;
        swr_set_channel_mapping(swrCtx, in_channel_map);
    }
    

    if (swr_init(swrCtx) < 0)
    {
        DBG("failed to init resampler");
        return false;
    }

    AVFormatContext* outFormatCtx = nullptr;
    avformat_alloc_output_context2(&outFormatCtx, nullptr, nullptr, wavFilePath.toRawUTF8());
    if (!outFormatCtx)
    {
        DBG("failed to allocate output format context");
        return false;
    }

    AVStream* outStream = avformat_new_stream(outFormatCtx, nullptr);
    if (!outStream)
    {
        DBG("failed to create new stream for output");
        return false;
    }

    AVCodecContext* outCodecCtx = avcodec_alloc_context3(avcodec_find_encoder(AV_CODEC_ID_PCM_S16LE));
    if (!outCodecCtx)
    {
        DBG("failed to allocate output codec context");
        return false;
    }

    outCodecCtx->sample_rate = codecCtx->sample_rate;
    outCodecCtx->channel_layout = out_channel_layout;
    outCodecCtx->channels = doMono ? 1 : 2;
    outCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16;
    outCodecCtx->bit_rate = 192000;
    outCodecCtx->time_base = (AVRational{ 1, outCodecCtx->sample_rate });

    if (avcodec_open2(outCodecCtx, avcodec_find_encoder(AV_CODEC_ID_PCM_S16LE), nullptr) < 0)
    {
        DBG("failed to open output codec");
        return false;
    }

    outStream->time_base = outCodecCtx->time_base;
    if (avcodec_parameters_from_context(outStream->codecpar, outCodecCtx) < 0)
    {
        DBG("failed to copy codec params from context to stream");
        return false;
    }

    if (!(outFormatCtx->oformat->flags & AVFMT_NOFILE))
    {
        if (avio_open(&outFormatCtx->pb, wavFilePath.toRawUTF8(), AVIO_FLAG_WRITE) < 0)
        {
            DBG("failed to open output file");
            return false;
        }
    }

    if (avformat_write_header(outFormatCtx, nullptr) < 0)
    {
        DBG("failed to write header to output file");
        return false;
    }

    int64_t total_samples = 0;

    while (av_read_frame(formatCtx, packet) >= 0)
    {
        if (packet->stream_index == audioStreamIndex)
        {
            if (avcodec_send_packet(codecCtx, packet) < 0)
            {
                DBG("failed secnding packet to decoder");
                av_packet_unref(packet);
                continue;
            }
            while (avcodec_receive_frame(codecCtx, frame) == 0)
            {
                int ret = swr_convert_frame(swrCtx, resampledFrame, frame);
                if (ret < 0)
                {
                    char errBuf[AV_ERROR_MAX_STRING_SIZE];
                    av_strerror(ret, errBuf, sizeof(errBuf));
                    DBG("Error resampling frame: " + std::string(errBuf));
                    continue;
                }

                resampledFrame->pts = av_rescale_q(total_samples, (AVRational{ 1, outCodecCtx->sample_rate }), outCodecCtx->time_base);
                total_samples += resampledFrame->nb_samples;

                AVPacket outPacket;
                av_init_packet(&outPacket);
                if (avcodec_send_frame(outCodecCtx, resampledFrame) < 0)
                {
                    DBG("error sending frame to decoder");
                    continue;
                }
                while (avcodec_receive_packet(outCodecCtx, &outPacket) == 0)
                {
                    outPacket.stream_index = outStream->index;
                    if (av_interleaved_write_frame(outFormatCtx, &outPacket) < 0)
                    {
                        av_packet_unref(&outPacket);
                        DBG("error writing packet to output file");
                        return false;
                    }
                    av_packet_unref(&outPacket);
                }
            }
        }
        av_packet_unref(packet);
    }

    /// trailer and cleanup
    av_write_trailer(outFormatCtx);

    avcodec_close(outCodecCtx);
    avcodec_close(codecCtx);
    avformat_close_input(&formatCtx);
    av_packet_free(&packet);
    av_frame_free(&frame);
    av_frame_free(&resampledFrame);
    swr_free(&swrCtx);
    if (!(outFormatCtx->oformat->flags & AVFMT_NOFILE)) avio_closep(&outFormatCtx->pb);
    avformat_free_context(outFormatCtx);


    


    Ive tried some debugging to see if the the values of either of the frames were unexpected or to see if the SwrContext might be unsual but did not manage anything. The thing I dont understand is the distinction that would cause this to fail for the right but not for when Im just doing the left.

    


  • ffmpeg live stream transcoding. A/V sync issues on fast camera movement

    21 août 2020, par Kelsnare
      

    1. I create a webrtc peer connection with my server(only stun)
    2. 


    3. Using pion webrtc for the server
    4. 


    5. I write the received RTP packets as VP8 and opus streams, as described here, to two pipes (the writers ; created with os.Pipe() in golang)
    6. 


    7. The read ends of these two pipes are received by ffmpeg as inputs (via exec.Command.ExtraFiles) for transcoding using libx264 and aac into a single stream. The command :
    8. 


    


    ffmpeg -re -i pipe:3 -re -r pipe:4 -c:a aac -af aresample=48000 -c:v libx264 -x264-params keyint=48:min-keyint=24 -profile:v main -preset ultrafast -tune zerolatency -crf 20 -fflags genpts -avoid_negative_ts make_zero -vsync vfr -map 0:0,0:0 -map 1:0,0:0 -f matroska -strict -2 pipe:5


    


      

    1. The above command outputs to a pipe(:5) the read end of which is being taken as input by the following :
    2. 


    


    ffmpeg -hide_banner -y -re -i pipe:3 -sn -vf scale=-1:'min(ih,360)' -c:v libx264 -pix_fmt yuv420p -ca aac -b:a 128k -b:v 1400k -maxrate 1498k -bufsize 2100k -hls_time 1 -hls_playlist_type event -hls_base_url /workdir/streamID/360p -hls_segment_filename /workdir/streamID/360p/360_%%03d.ts -f hls /workdir/streamID/360p.m3u8


    


      

    1. This works fine as long as there are no movements of my webcam. The moment that happens the video speed suddenly increases for a split second and audio delay gets introduced. This delay keeps increasing each time I shake my webcam.
    2. 


    


    The first command in point 4 above - if written to a file separately will be absolutely fine, in terms of a/v sync, even with vigorous camera shaking. The weird audio delay is only when transcoding for hls output irrespective of whether I'm actually viewing it live or playing it back later.

    


    This is my first time working with ffmpeg/hls/webrtc - would be really helpful if I could be pointed in the correct direction at least to be able to debug this or even know why this happens. Any and all help is greatly appreciated

    


  • Issues with using FFmpeg to generate MPEG-DASH files

    26 septembre 2022, par Tina J

    I am using the following ffmpeg command to generate MPEG DASH files and manifest. I use single_file 1 to have a single file for each representation ; so no chunking. But IDK why when I want to play the manifest using ExoPlayer, the video doesn't play from the beginning (rather it starts from around 50s).

    


    ffmpeg -re -i .\video-h264.mkv -map 0 -map 0 -c:a aac -c:v libx264 -b:v:0 800k -b:v:1 300k -s:v:1 320x170 -profile:v:1 baseline -profile:v:0 main -bf 1 -keyint_min 120 -g 120 -sc_threshold 0 -b_strategy 0 -ar:a:1 22050 -use_timeline 1 -single_file 1 -use_template 1 -window_size 5 -adaptation_sets "id=0,streams=v id=1,streams=a" -f dash out.mpd


    


    What is wrong with this ? Is the manifest correct ? Here is the generated mpd :

    


    &lt;?xml version="1.0" encoding="utf-8"?>&#xA;<mpd xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediapresentationduration="PT1M20.1S" maxsegmentduration="PT5.0S" minbuffertime="PT16.0S">&#xA;    <programinformation>&#xA;    </programinformation>&#xA;    <servicedescription>&#xA;    </servicedescription>&#xA;    <period start="PT48.0S">&#xA;        <adaptationset contenttype="video" startwithsap="1" segmentalignment="true" bitstreamswitching="true" framerate="30/1" maxwidth="960" maxheight="540" par="517072:290799" lang="eng">&#xA;            <representation mimetype="video/mp4" codecs="avc1.4d401f" bandwidth="800000" width="960" height="540" sar="32317:32311">&#xA;                <baseurl>out-stream0.mp4</baseurl>&#xA;                <segmentlist timescale="1000000" duration="5000000" startnumber="7">&#xA;                    <initialization range="0-832"></initialization>&#xA;                    <segmenturl mediarange="4800141-5599188" indexrange="4800141-4800192"></segmenturl>&#xA;                    <segmenturl mediarange="5599189-6243069" indexrange="5599189-5599240"></segmenturl>&#xA;                    <segmenturl mediarange="6243070-7224302" indexrange="6243070-6243121"></segmenturl>&#xA;                    <segmenturl mediarange="7224303-8138118" indexrange="7224303-7224354"></segmenturl>&#xA;                    <segmenturl mediarange="8138119-8232111" indexrange="8138119-8138170"></segmenturl>&#xA;                </segmentlist>&#xA;            </representation>&#xA;            <representation mimetype="video/mp4" codecs="avc1.42c00d" bandwidth="300000" width="320" height="170" sar="549389:581598">&#xA;                <baseurl>out-stream2.mp4</baseurl>&#xA;                <segmentlist timescale="1000000" duration="5000000" startnumber="7">&#xA;                    <initialization range="0-832"></initialization>&#xA;                    <segmenturl mediarange="1782920-2005667" indexrange="1782920-1782971"></segmenturl>&#xA;                    <segmenturl mediarange="2005668-2229412" indexrange="2005668-2005719"></segmenturl>&#xA;                    <segmenturl mediarange="2229413-2615209" indexrange="2229413-2229464"></segmenturl>&#xA;                    <segmenturl mediarange="2615210-2975346" indexrange="2615210-2615261"></segmenturl>&#xA;                    <segmenturl mediarange="2975347-2999288" indexrange="2975347-2975398"></segmenturl>&#xA;                </segmentlist>&#xA;            </representation>&#xA;        </adaptationset>&#xA;        <adaptationset contenttype="audio" startwithsap="1" segmentalignment="true" bitstreamswitching="true" lang="eng">&#xA;            <representation mimetype="audio/mp4" codecs="mp4a.40.2" bandwidth="69000" audiosamplingrate="44100">&#xA;                <audiochannelconfiguration schemeiduri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="1"></audiochannelconfiguration>&#xA;                <baseurl>out-stream1.mp4</baseurl>&#xA;                <segmentlist timescale="1000000" duration="5000000" startnumber="12">&#xA;                    <initialization range="0-764"></initialization>&#xA;                    <segmenturl mediarange="491493-536039" indexrange="491493-491544"></segmenturl>&#xA;                    <segmenturl mediarange="536040-580657" indexrange="536040-536091"></segmenturl>&#xA;                    <segmenturl mediarange="580658-625158" indexrange="580658-580709"></segmenturl>&#xA;                    <segmenturl mediarange="625159-669825" indexrange="625159-625210"></segmenturl>&#xA;                    <segmenturl mediarange="669826-713289" indexrange="669826-669877"></segmenturl>&#xA;                </segmentlist>&#xA;            </representation>&#xA;            <representation mimetype="audio/mp4" codecs="mp4a.40.2" bandwidth="69000" audiosamplingrate="22050">&#xA;                <audiochannelconfiguration schemeiduri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="1"></audiochannelconfiguration>&#xA;                <baseurl>out-stream3.mp4</baseurl>&#xA;                <segmentlist timescale="1000000" duration="5000000" startnumber="12">&#xA;                    <initialization range="0-764"></initialization>&#xA;                    <segmenturl mediarange="486188-530059" indexrange="486188-486239"></segmenturl>&#xA;                    <segmenturl mediarange="530060-574175" indexrange="530060-530111"></segmenturl>&#xA;                    <segmenturl mediarange="574176-618922" indexrange="574176-574227"></segmenturl>&#xA;                    <segmenturl mediarange="618923-663118" indexrange="618923-618974"></segmenturl>&#xA;                    <segmenturl mediarange="663119-706121" indexrange="663119-663170"></segmenturl>&#xA;                </segmentlist>&#xA;            </representation>&#xA;        </adaptationset>&#xA;    </period>&#xA;</mpd>&#xA;

    &#xA;