Recherche avancée

Médias (91)

Autres articles (81)

  • Des sites réalisés avec MediaSPIP

    2 mai 2011, par

    Cette page présente quelques-uns des sites fonctionnant sous MediaSPIP.
    Vous pouvez bien entendu ajouter le votre grâce au formulaire en bas de page.

  • Keeping control of your media in your hands

    13 avril 2011, par

    The vocabulary used on this site and around MediaSPIP in general, aims to avoid reference to Web 2.0 and the companies that profit from media-sharing.
    While using MediaSPIP, you are invited to avoid using words like "Brand", "Cloud" and "Market".
    MediaSPIP is designed to facilitate the sharing of creative media online, while allowing authors to retain complete control of their work.
    MediaSPIP aims to be accessible to as many people as possible and development is based on expanding the (...)

  • Participer à sa traduction

    10 avril 2011

    Vous pouvez nous aider à améliorer les locutions utilisées dans le logiciel ou à traduire celui-ci dans n’importe qu’elle nouvelle langue permettant sa diffusion à de nouvelles communautés linguistiques.
    Pour ce faire, on utilise l’interface de traduction de SPIP où l’ensemble des modules de langue de MediaSPIP sont à disposition. ll vous suffit de vous inscrire sur la liste de discussion des traducteurs pour demander plus d’informations.
    Actuellement MediaSPIP n’est disponible qu’en français et (...)

Sur d’autres sites (10635)

  • I want to save a video with effects applied on it. OnSucccess is not calling [duplicate]

    10 novembre 2016, par shriya

    This question already has an answer here :

    This is command string which i want to process.

    String[] command = new String[]"ffmpeg -y -i " + old_video_path + " -strict experimental -vf curves=vintage -s 240x320 -r 30 -aspect 4:3 -ab 48000 /storage/emulated/0/video.mp4" ;
    executeFFmpeg(command) ;

    private void executeFFmpeg(String[] cmd) {
       try {
           ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

               @Override
               public void onStart() {
                   Log.e("Progress", "onStart");
               }

               @Override
               public void onProgress(String message) {
                   Log.e("Progress", "onProgress");
               }

               @Override
               public void onSuccess(String message) {
                   Log.e("Progress", "onSuccess");
               }

               @Override
               public void onFailure(String message) {
                   Log.e("Progress", "onFailure" + message);
               }

               @Override
               public void onFinish() {

                   Log.e("Progress", "onFinish");

               }
           });
       } catch (FFmpegCommandAlreadyRunningException e) {
           // Handle if FFmpeg is already running
       }
    }

    in Log i am getting onProcess call and onFininsh call. How do i write code to save this video in sdcard and where ?

  • FFmpeg VAAPI : GOP Size Setting Not Applied During Encoding

    17 octobre 2024, par sun tony

    I'm working on a video transcoding project using FFmpeg with VAAPI hardware acceleration, and I'm encountering an issue where the gop_size parameter is not being respected during encoding. Despite setting the gop_size to 150 in the encoder context, the output video does not have the expected GOP structure. This problem only occurs when using VAAPI for hardware acceleration—when I switch to software decoding or CUDA, the GOP size is applied correctly.

    


    Here’s a simplified version of the relevant code where I set the gop_size :

    


    encoder_ctx->gop_size = 150;


    


    I'm using FFmpeg's VAAPI for hardware-accelerated encoding, and everything else works as expected, except for this GOP size issue. Has anyone encountered this problem, or is there something specific to VAAPI that I'm missing ?

    


    Environment :

    


      

    • FFmpeg version : (6.0)
    • 


    • VAAPI (Intel GPU)
    • 


    • Encoder : H.264
    • 


    


    #include &#xA;#include &#xA;extern "C"&#xA;{&#xA;#include <libavutil></libavutil>hwcontext.h>&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavformat></libavformat>avformat.h>&#xA;}&#xA;static AVFormatContext* ifmt_ctx = NULL, * ofmt_ctx = NULL;&#xA;static AVBufferRef* hw_device_ctx = NULL;&#xA;static AVCodecContext* decoder_ctx = NULL, * encoder_ctx = NULL;&#xA;static int video_stream = -1;&#xA;static AVStream* ost;&#xA;static int initialized = 0;&#xA;&#xA;static enum AVPixelFormat get_vaapi_format(AVCodecContext* ctx,&#xA;    const enum AVPixelFormat* pix_fmts)&#xA;{&#xA;    const enum AVPixelFormat* p;&#xA;&#xA;    for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p&#x2B;&#x2B;) {   &#xA;         if (*p == AV_PIX_FMT_VAAPI)&#xA;            return *p;&#xA;    }&#xA;&#xA;    fprintf(stderr, "Unable to decode this file using VA-API.\n");&#xA;    return AV_PIX_FMT_NONE;&#xA;}&#xA;&#xA;static int open_input_file(const char* filename)&#xA;{&#xA;    int ret;&#xA;    const AVCodec* decoder = NULL;&#xA;    AVStream* video = NULL;&#xA;    char err_buf[AV_ERROR_MAX_STRING_SIZE] = { 0, };&#xA;&#xA;    if ((ret = avformat_open_input(&amp;ifmt_ctx, filename, NULL, NULL)) &lt; 0) {&#xA;        av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;        fprintf(stderr, "Cannot open input file &#x27;%s&#x27;, Error code: %s\n", filename, err_buf);&#xA;        return ret;&#xA;    }&#xA;&#xA;    if ((ret = avformat_find_stream_info(ifmt_ctx, NULL)) &lt; 0) {&#xA;        av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;        fprintf(stderr, "Cannot find input stream information. Error code: %s\n", err_buf);&#xA;        return ret;&#xA;    }&#xA;&#xA;    ret = av_find_best_stream(ifmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &amp;decoder, 0);&#xA;    if (ret &lt; 0) {&#xA;        av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;        fprintf(stderr, "Cannot find a video stream in the input file. Error code: %s\n", err_buf);&#xA;        return ret;&#xA;    }&#xA;    video_stream = ret;&#xA;&#xA;    if (!(decoder_ctx = avcodec_alloc_context3(decoder)))&#xA;        return AVERROR(ENOMEM);&#xA;&#xA;    video = ifmt_ctx->streams[video_stream];&#xA;    if ((ret = avcodec_parameters_to_context(decoder_ctx, video->codecpar)) &lt; 0) {&#xA;&#xA;        av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;        fprintf(stderr, "avcodec_parameters_to_context error. Error code: %s\n", err_buf);&#xA;        return ret;&#xA;    }&#xA;&#xA;    decoder_ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx);&#xA;    if (!decoder_ctx->hw_device_ctx) {&#xA;        fprintf(stderr, "A hardware device reference create failed.\n");&#xA;        return AVERROR(ENOMEM);&#xA;    }&#xA;    decoder_ctx->get_format = get_vaapi_format;&#xA;&#xA;    if ((ret = avcodec_open2(decoder_ctx, decoder, NULL)) &lt; 0){&#xA;    &#xA;        av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;        fprintf(stderr, "Failed to open codec for decoding.Error code: %s\n", err_buf);&#xA;    }&#xA;      &#xA;    return ret;&#xA;}&#xA;&#xA;static int encode_write(AVPacket* enc_pkt, AVFrame* frame)&#xA;{&#xA;    int ret = 0;&#xA;    char err_buf[AV_ERROR_MAX_STRING_SIZE] = { 0, };&#xA;    av_packet_unref(enc_pkt);&#xA;&#xA;    if ((ret = avcodec_send_frame(encoder_ctx, frame)) &lt; 0) {&#xA;        av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;        fprintf(stderr, "Error during encoding. Error code: %s\n", err_buf);&#xA;        goto end;&#xA;    }&#xA;    while (1) {&#xA;        ret = avcodec_receive_packet(encoder_ctx, enc_pkt);&#xA;        if (ret)&#xA;            break;&#xA;&#xA;        enc_pkt->stream_index = 0;&#xA;        av_packet_rescale_ts(enc_pkt, ifmt_ctx->streams[video_stream]->time_base,&#xA;            ofmt_ctx->streams[0]->time_base);&#xA;        ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);&#xA;        if (ret &lt; 0) {&#xA;            av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;            fprintf(stderr, "Error during writing data to output file. Error code: %s\n", err_buf);&#xA;            return -1;&#xA;        }&#xA;    }&#xA;&#xA;end:&#xA;    if (ret == AVERROR_EOF)&#xA;        return 0;&#xA;    ret = ((ret == AVERROR(EAGAIN)) ? 0 : -1);&#xA;    return ret;&#xA;}&#xA;&#xA;static int dec_enc(AVPacket* pkt, const AVCodec* enc_codec)&#xA;{&#xA;    AVFrame* frame;&#xA;    AVDictionary* opts = NULL;&#xA;&#xA;    int ret = 0;&#xA;    char err_buf[AV_ERROR_MAX_STRING_SIZE] = { 0, };&#xA;    ret = avcodec_send_packet(decoder_ctx, pkt);&#xA;    if (ret &lt; 0) {&#xA;        av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;        fprintf(stderr, "Error during decoding.Error code : %s\n", err_buf);&#xA;        return ret;&#xA;    }&#xA;&#xA;    while (ret >= 0) {&#xA;        if (!(frame = av_frame_alloc()))&#xA;            return AVERROR(ENOMEM);&#xA;&#xA;        ret = avcodec_receive_frame(decoder_ctx, frame);&#xA;        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {&#xA;            av_frame_free(&amp;frame);&#xA;            return 0;&#xA;        }&#xA;        else if (ret &lt; 0) {&#xA;            av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;            fprintf(stderr, "Error while decoding.Error code : %s\n", err_buf);&#xA;            goto fail;&#xA;        }&#xA;&#xA;        if (!initialized) {&#xA;            /* we need to ref hw_frames_ctx of decoder to initialize encoder&#x27;s codec.&#xA;               Only after we get a decoded frame, can we obtain its hw_frames_ctx */&#xA;            encoder_ctx->hw_frames_ctx = av_buffer_ref(decoder_ctx->hw_frames_ctx);&#xA;            if (!encoder_ctx->hw_frames_ctx) {&#xA;                ret = AVERROR(ENOMEM);&#xA;                goto fail;&#xA;            }&#xA;            /* set AVCodecContext Parameters for encoder, here we keep them stay&#xA;             * the same as decoder.&#xA;             * xxx: now the sample can&#x27;t handle resolution change case.&#xA;             */&#xA;            encoder_ctx->time_base = av_inv_q(decoder_ctx->framerate);&#xA;            encoder_ctx->pix_fmt = AV_PIX_FMT_VAAPI;&#xA;            encoder_ctx->width = decoder_ctx->width;&#xA;            encoder_ctx->height = decoder_ctx->height;&#xA;            encoder_ctx->gop_size = 150;&#xA;            av_dict_set(&amp;opts, "g", "150", 0); // gop_size 설정&#xA;&#xA;            if ((ret = avcodec_open2(encoder_ctx, enc_codec, &amp;opts)) &lt; 0) {&#xA;                av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;                fprintf(stderr, "Failed to open encode codec. Error code : %s\n", err_buf);&#xA;                goto fail;&#xA;            }&#xA;&#xA;            if (!(ost = avformat_new_stream(ofmt_ctx, enc_codec))) {&#xA;                fprintf(stderr, "Failed to allocate stream for output format.\n");&#xA;                ret = AVERROR(ENOMEM);&#xA;                goto fail;&#xA;            }&#xA;&#xA;            ost->time_base = encoder_ctx->time_base;&#xA;            ret = avcodec_parameters_from_context(ost->codecpar, encoder_ctx);&#xA;            if (ret &lt; 0) {&#xA;                av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;                fprintf(stderr, "Failed to copy the stream parameters. Error code : %s\n", err_buf);&#xA;                goto fail;&#xA;            }&#xA;&#xA;            /* write the stream header */&#xA;            if ((ret = avformat_write_header(ofmt_ctx, NULL)) &lt; 0) {&#xA;                av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;                fprintf(stderr, "Error while writing stream header. Error code : %s\n", err_buf);&#xA;                goto fail;&#xA;            }&#xA;&#xA;            initialized = 1;&#xA;        }&#xA;&#xA;        if ((ret = encode_write(pkt, frame)) &lt; 0)&#xA;            fprintf(stderr, "Error during encoding and writing.\n");&#xA;&#xA;    fail:&#xA;        av_frame_free(&amp;frame);&#xA;        if (ret &lt; 0)&#xA;            return ret;&#xA;    }&#xA;    return 0;&#xA;}&#xA;&#xA;int main(int argc, char** argv)&#xA;{&#xA;    const AVCodec* enc_codec;&#xA;    int ret = 0;&#xA;    AVPacket* dec_pkt;&#xA;    char err_buf[AV_ERROR_MAX_STRING_SIZE] = { 0, };&#xA;&#xA;    if (argc != 4) {&#xA;        fprintf(stderr, "Usage: %s <input file="file" /> <encode codec="codec"> <output file="file">\n"&#xA;            "The output format is guessed according to the file extension.\n"&#xA;            "\n", argv[0]);&#xA;        return -1;&#xA;    }&#xA;&#xA;    ret = av_hwdevice_ctx_create(&amp;hw_device_ctx, AV_HWDEVICE_TYPE_VAAPI, NULL, NULL, 0);&#xA;    if (ret &lt; 0) {&#xA;        av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;        fprintf(stderr, "Failed to create a VAAPI device. Error code : %s\n", err_buf);&#xA;        return -1;&#xA;    }&#xA;&#xA;    dec_pkt = av_packet_alloc();&#xA;    if (!dec_pkt) {&#xA;        fprintf(stderr, "Failed to allocate decode packet\n");&#xA;        goto end;&#xA;    }&#xA;&#xA;    if ((ret = open_input_file(argv[1])) &lt; 0)&#xA;        goto end;&#xA;&#xA;    if (!(enc_codec = avcodec_find_encoder_by_name(argv[2]))) {&#xA;        fprintf(stderr, "Could not find encoder &#x27;%s&#x27;\n", argv[2]);&#xA;        ret = -1;&#xA;        goto end;&#xA;    }&#xA;&#xA;    if ((ret = (avformat_alloc_output_context2(&amp;ofmt_ctx, NULL, NULL, argv[3]))) &lt; 0) {&#xA;        av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;        fprintf(stderr, "Failed to deduce output format from file extension. Error code : %s\n", err_buf);&#xA;        goto end;&#xA;    }&#xA;&#xA;    if (!(encoder_ctx = avcodec_alloc_context3(enc_codec))) {&#xA;        ret = AVERROR(ENOMEM);&#xA;        goto end;&#xA;    }&#xA;&#xA;    ret = avio_open(&amp;ofmt_ctx->pb, argv[3], AVIO_FLAG_WRITE);&#xA;    if (ret &lt; 0) {&#xA;        av_strerror(ret, err_buf, AV_ERROR_MAX_STRING_SIZE);&#xA;        fprintf(stderr, "Cannot open output file. Error code : %s\n", err_buf);&#xA;        goto end;&#xA;    }&#xA;&#xA;    /* read all packets and only transcoding video */&#xA;    while (ret >= 0) {&#xA;        if ((ret = av_read_frame(ifmt_ctx, dec_pkt)) &lt; 0)&#xA;            break;&#xA;&#xA;        if (video_stream == dec_pkt->stream_index)&#xA;            ret = dec_enc(dec_pkt, enc_codec);&#xA;&#xA;        av_packet_unref(dec_pkt);&#xA;    }&#xA;&#xA;    /* flush decoder */&#xA;    av_packet_unref(dec_pkt);&#xA;    ret = dec_enc(dec_pkt, enc_codec);&#xA;&#xA;    /* flush encoder */&#xA;    ret = encode_write(dec_pkt, NULL);&#xA;&#xA;    /* write the trailer for output stream */&#xA;    av_write_trailer(ofmt_ctx);&#xA;&#xA;end:&#xA;    avformat_close_input(&amp;ifmt_ctx);&#xA;    avformat_close_input(&amp;ofmt_ctx);&#xA;    avcodec_free_context(&amp;decoder_ctx);&#xA;    avcodec_free_context(&amp;encoder_ctx);&#xA;    av_buffer_unref(&amp;hw_device_ctx);&#xA;    av_packet_free(&amp;dec_pkt);&#xA;    return ret;&#xA;}&#xA;</output></encode>

    &#xA;

  • avcodec/ffv1enc : Store run1start_mul_index instead of computing

    25 mars, par Michael Niedermayer
    avcodec/ffv1enc : Store run1start_mul_index instead of computing
    

    There is a special case I missed, its simpler to just store

    Sponsored-by : Sovereign Tech Fund
    Signed-off-by : Michael Niedermayer <michael@niedermayer.cc>

    • [DH] libavcodec/ffv1enc.c