Recherche avancée

Médias (29)

Mot : - Tags -/Musique

Autres articles (82)

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • Submit bugs and patches

    13 avril 2011

    Unfortunately a software is never perfect.
    If you think you have found a bug, report it using our ticket system. Please to help us to fix it by providing the following information : the browser you are using, including the exact version as precise an explanation as possible of the problem if possible, the steps taken resulting in the problem a link to the site / page in question
    If you think you have solved the bug, fill in a ticket and attach to it a corrective patch.
    You may also (...)

Sur d’autres sites (12005)

  • How to Transcode ALL Audio streams from input to output using ffmpeg ?

    24 novembre 2022, par user1940163

    I have an input MPEG TS file 'unit_test.ts'. This file has following content (shown by ffprobe) :

    


    Input #0, mpegts, from 'unit_test.ts':
  Duration: 00:00:57.23, start: 73674.049844, bitrate: 2401 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x31]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(progressive), 852x480 [SAR 640:639 DAR 16:9], Closed Captions, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
    Stream #0:1[0x34](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:2[0x35](spa): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s


    


    I want to convert it into another MPEG TS file. Requirement is that the Video stream of the input should be directly copied to the output whereas ALL the audio streams should be transcoded "aac" format.

    


    I tried this command :

    


    ffmpeg -i unit_test.ts  -map 0 -c copy -c:a aac maud_test.ts

    


    It converted it into 'maud_test.ts' with following contents (shown by ffprobe)

    


    Input #0, mpegts, from 'maud_test.ts':
  Duration: 00:00:57.25, start: 1.400000, bitrate: 2211 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(progressive), 852x480 [SAR 640:639 DAR 16:9], Closed Captions, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
    Stream #0:1[0x101](eng): Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, 6 channels, fltp, 391 kb/s
    Stream #0:2[0x102](spa): Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 133 kb/s


    


    So it appeared as if the command worked....However when I play the maud_test.ts file in vlc player I can see both audio streams listed in the menu ; but Stream 1 (eng) remains silent............whereas Stream 2 (spa) has proper audio. (Original TS file has both audio streams properly audible)

    


    I have tried this with different input files and have seen that same problem occurs in each case.

    


    What that I am doing is not right ?

    


    How should I get this done ? (I can write explicit stream by stream map and channel arguments to get that done ; however I want the command line to be generic, in that the input file could be having any configuration with one Video and several Audios with different formats. The configuration will not be known beforehand.)

    


  • Error submitting the frame for encoding when submitting NV12 texture

    6 mai 2022, par Caio Augusto

    I'm trying to encode D3D11 NV12 Texture on QSV encoder but getting [h264_qsv @ 00000244ce6f50c0] Error submitting the frame for encoding.

    


    Main :

    


    int width = 1920;
int height = 1080;
FILE* outfile;

fopen_s(&outfile, "D:\\Sources\\D3D11QSV\\x64\\Debug\\outfile.264", "wb");

const AVCodec* codec = avcodec_find_encoder_by_name("h264_qsv");
AVCodecContext* ctx = avcodec_alloc_context3(codec);

ctx->width = width;
ctx->height = height;
ctx->time_base = AVRational{ 1, 60 };
ctx->framerate = AVRational{ 60, 1 };
ctx->slices = 1;

ctx->sw_pix_fmt = AV_PIX_FMT_NV12;
ctx->pix_fmt = AV_PIX_FMT_NV12;
ctx->bit_rate = 400000;
ctx->gop_size = 10;
ctx->max_b_frames = 1;

auto status = avcodec_open2(ctx, codec, NULL);
if (status < 0) {
    std::cout << "Open codec error!\n";
}

AVFrame* sw_frame = av_frame_alloc();
sw_frame->format = ctx->sw_pix_fmt;
sw_frame->width = ctx->width;
sw_frame->height = ctx->height;
status = av_frame_get_buffer(sw_frame, 0);

fill_frame(sw_frame, ctx);


    


    Filling the frame :

    


    auto ret = 0;

if (ret < 0) {
    fprintf(stderr, "Could not allocate the video frame data\n");
    exit(1);
}

int i, y, x, c = 0;
for (i = 0; i < 60; i++) {
    fflush(stdout);

    ret = av_frame_make_writable(frame);
    
    auto texture = create_texture();
    auto desc = (AVD3D11FrameDescriptor*)frame->buf[0]->data;
    desc->texture = (ID3D11Texture2D*)texture;
    desc->index = 0;

    frame->data[0] = (std::uint8_t*)texture;
    frame->data[1] = 0;
    frame->linesize[0] = width * 4;

    frame->pts = i;

    encode(frame, ctx);
}


    


    Creating Texture :

    


    D3D11_TEXTURE2D_DESC const desc = CD3D11_TEXTURE2D_DESC(
    DXGI_FORMAT_NV12,           // HoloLens PV camera format, common for video sources
    width,                    // Width of the video frames
    height,                   // Height of the video frames
    1,                          // Number of textures in the array
    1,                          // Number of miplevels in each texture
    D3D11_BIND_SHADER_RESOURCE, // We read from this texture in the shader
    D3D11_USAGE_DYNAMIC,        // Because we'll be copying from CPU memory
    D3D11_CPU_ACCESS_WRITE      // We only need to write into the texture
);

ID3D11Device* pd3dDevice = create_d3d11_device();

ID3D11Texture2D* pTexture = NULL;
HRESULT err = pd3dDevice->CreateTexture2D(&desc, nullptr, &pTexture);


if (SUCCEEDED(err)) {
    D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = CD3D11_SHADER_RESOURCE_VIEW_DESC(
        pTexture,
        D3D11_SRV_DIMENSION_TEXTURE2D,
        DXGI_FORMAT_R8_UNORM
    );

    ID3D11ShaderResourceView* texSRV = NULL;

    err = pd3dDevice->CreateShaderResourceView(pTexture,
        &SRVDesc, &texSRV);

    D3D11_SHADER_RESOURCE_VIEW_DESC const chrominancePlaneDesc = CD3D11_SHADER_RESOURCE_VIEW_DESC(
        pTexture,
        D3D11_SRV_DIMENSION_TEXTURE2D,
        DXGI_FORMAT_R8G8_UNORM
    );

    ID3D11ShaderResourceView* m_chrominanceView = NULL;

    err = pd3dDevice->CreateShaderResourceView(pTexture,
        &chrominancePlaneDesc, &m_chrominanceView);

}

if (FAILED(err))
{
    fprintf(stderr, "Error creating texture\n");
    exit(1);
}

return pTexture;


    


    Creating D3D11 device :

    


        ID3D11Device* dev11 = NULL;
    ID3D11DeviceContext* devcon11 = NULL;

    D3D_FEATURE_LEVEL featureLevels[]{
   D3D_FEATURE_LEVEL_11_1,
   D3D_FEATURE_LEVEL_11_0,
   D3D_FEATURE_LEVEL_10_1,
   D3D_FEATURE_LEVEL_10_0,
   D3D_FEATURE_LEVEL_9_3,
   D3D_FEATURE_LEVEL_9_2,
   D3D_FEATURE_LEVEL_9_1
    };


    int err = D3D11CreateDevice(
        nullptr,
        D3D_DRIVER_TYPE_HARDWARE,
        nullptr,
        D3D11_CREATE_DEVICE_VIDEO_SUPPORT,
        featureLevels, sizeof(featureLevels) / sizeof(D3D_FEATURE_LEVEL),
        D3D11_SDK_VERSION,
        &dev11,
        nullptr,
        &devcon11);

    return dev11;


    


    Encoding :

    


    auto status = 0;

status = avcodec_send_frame(ctx, frame); //error happening here

AVPacket* pkt;

pkt = av_packet_alloc();

if (status < 0) {
    fprintf(stderr, "Error sending a frame for encoding\n");
    exit(1);
}

while (status >= 0) {
    status = avcodec_receive_packet(ctx, pkt);
    if (status == AVERROR(EAGAIN) || status == AVERROR_EOF)
        return;
    else if (status < 0) {
        fprintf(stderr, "Error during encoding\n");
        exit(1);
    }

    printf("Write packet \n", pkt->pts, pkt->size);
    fwrite(pkt->data, 1, pkt->size, outfile);
    av_packet_unref(pkt);
}


    


    Everything runs well until encoding the frame. I have tried sending a dummy nv12 data (not a d3d11 texture) and it works well.

    


  • FFMPEG and STB_Image Create awful Picture

    9 février 2023, par murage kibicho

    I was learning how to use the FFMPEG C api and I was trying to encode a jpeg into a MPEG file. I load the JPEG into (unsigned char *) using the stb-image library. Then I create a (uint8_t *) and copy my rgb values. Finally, I convert RGB to YUV420 using sws_scale. However, a portion of my image blurs out when I perform the encoding.Bad Image
/
This is the original imageoriginal image

    
Perhaps I allocate my frame buffer incorrectly ?

    


    ret = av_frame_get_buffer(frame, 0);


    


    
This is my entire program

    


    #define STB_IMAGE_IMPLEMENTATION&#xA;#include "stb_image.h"&#xA;#define STB_IMAGE_WRITE_IMPLEMENTATION&#xA;#include "stb_image_write.h"&#xA;#define STB_IMAGE_RESIZE_IMPLEMENTATION&#xA;#include "stb_image_resize.h"&#xA;#include &#xA;&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavutil></libavutil>opt.h>&#xA;#include <libavutil></libavutil>imgutils.h>&#xA;#include <libswscale></libswscale>swscale.h>&#xA;//gcc stack.c -lm -o stack.o `pkg-config --cflags --libs libavformat libavcodec libswresample libswscale libavutil` &amp;&amp; ./stack.o&#xA;&#xA;/*&#xA;int i : pts of current frame&#xA;*/&#xA;void PictureToFrame(int i, AVFrame *frame, int height, int width)&#xA;{&#xA;    //Use stb image to get rgb values&#xA;        char *fileName = "profil.jpeg";&#xA;        int imageHeight = 0;&#xA;        int imageWidth = 0;&#xA;        int colorChannels = 0;&#xA;        int arrayLength = 0;&#xA;    unsigned char *image = stbi_load(fileName,&amp;imageWidth,&amp;imageHeight,&amp;colorChannels,0);&#xA;    &#xA;    printf("(height: %d, width: %d)\n",imageHeight, imageWidth);&#xA;    assert(colorChannels == 3 &amp;&amp; imageHeight == height &amp;&amp; imageWidth == width);&#xA;    &#xA;    //Convert unsigned char * to uint8_t *&#xA;    arrayLength = imageHeight * imageWidth * colorChannels;&#xA;    uint8_t *rgb = calloc(arrayLength, sizeof(uint8_t));&#xA;    int j = arrayLength-1;&#xA;    for(int i = 0; i &lt; arrayLength; i&#x2B;&#x2B;)&#xA;    {&#xA;        rgb[i] = (uint8_t) image[i];&#xA;        }&#xA;        &#xA;        //Use SwsContext to scale RGB to YUV420P and write to frame&#xA;        const int in_linesize[1] = { 3* imageWidth};&#xA;        struct SwsContext *sws_context = NULL;&#xA;        sws_context = sws_getCachedContext(sws_context,&#xA;            imageWidth, imageHeight, AV_PIX_FMT_RGB24,&#xA;            imageWidth, imageHeight, AV_PIX_FMT_YUV420P,&#xA;            0, 0, 0, 0);&#xA;        sws_scale(sws_context, (const uint8_t * const *)&amp;rgb, in_linesize, 0,&#xA;            imageHeight, frame->data, frame->linesize);&#xA;        //Save frame pts&#xA;        frame->pts = i;&#xA;        &#xA;        //Free alloc&#x27;d data&#xA;        stbi_image_free(image);&#xA;        sws_freeContext(sws_context);&#xA;        free(rgb);&#xA;}&#xA;static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt, FILE *outfile)&#xA;{&#xA;    int returnValue;&#xA;    /* send the frame to the encoder */&#xA;    if(frame)&#xA;    {&#xA;        printf("Send frame %3"PRId64"\n", frame->pts);&#xA;    }&#xA;        returnValue = avcodec_send_frame(enc_ctx, frame);&#xA;    if(returnValue &lt; 0)&#xA;    {&#xA;        printf("Error sending a frame for encoding\n");&#xA;        return;&#xA;    }&#xA;    while(returnValue >= 0)&#xA;    {&#xA;        returnValue = avcodec_receive_packet(enc_ctx, pkt);&#xA;        if(returnValue == AVERROR(EAGAIN) || returnValue == AVERROR_EOF)&#xA;        {&#xA;            return;&#xA;        }&#xA;        else if(returnValue &lt; 0)&#xA;        {&#xA;            printf("Error during encoding\n");&#xA;            return;&#xA;        }&#xA;&#xA;        printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size);&#xA;        fwrite(pkt->data, 1, pkt->size, outfile);&#xA;        av_packet_unref(pkt);&#xA;    }&#xA;}&#xA;&#xA;&#xA;int main(int argc, char **argv)&#xA;{&#xA;    const char *filename, *codec_name;&#xA;    const AVCodec *codec;&#xA;    AVCodecContext *c= NULL;&#xA;    int i, ret, x, y;&#xA;    FILE *f;&#xA;    AVFrame *frame;&#xA;    AVPacket *pkt;&#xA;    uint8_t endcode[] = { 0, 0, 1, 0xb7 };&#xA;&#xA;    filename = "outo.mp4";&#xA;    codec_name = "mpeg1video";//"mpeg1video";//"libx264";&#xA;&#xA;&#xA;    /* find the mpeg1video encoder */&#xA;    codec = avcodec_find_encoder_by_name(codec_name);&#xA;    if(!codec)&#xA;    {&#xA;        printf("Error finding codec\n");&#xA;    return 0;&#xA;    }&#xA;&#xA;    c = avcodec_alloc_context3(codec);&#xA;    if(!c)&#xA;    {&#xA;        printf("Error allocating c\n");&#xA;    return 0;&#xA;    }&#xA;&#xA;    pkt = av_packet_alloc();&#xA;    if(!pkt)&#xA;    {&#xA;        printf("Error allocating pkt\n");&#xA;    return 0;&#xA;    }&#xA;&#xA;    /* put sample parameters */&#xA;    c->bit_rate = 400000;&#xA;    /* resolution must be a multiple of two */&#xA;    c->width = 800;&#xA;    c->height = 800;&#xA;    /* frames per second */&#xA;    c->time_base = (AVRational){1, 25};&#xA;    c->framerate = (AVRational){25, 1};&#xA;    c->gop_size = 10;&#xA;    c->max_b_frames = 1;&#xA;    c->pix_fmt = AV_PIX_FMT_YUV420P;&#xA;&#xA;    if(codec->id == AV_CODEC_ID_H264)&#xA;    {&#xA;        av_opt_set(c->priv_data, "preset", "slow", 0);&#xA;    }&#xA;        &#xA;&#xA;    /* open it */&#xA;    ret = avcodec_open2(c, codec, NULL);&#xA;    if(ret &lt; 0) &#xA;    {&#xA;        printf("Error opening codec\n");&#xA;    return 0;&#xA;    }&#xA;&#xA;    f = fopen(filename, "wb");&#xA;    if(!f)&#xA;    {&#xA;         printf("Error opening file\n");&#xA;     return 0;&#xA;    }&#xA;&#xA;    frame = av_frame_alloc();&#xA;    if(!frame)&#xA;    {&#xA;        printf("Error allocating frame\n");&#xA;    return 0;&#xA;    }&#xA;    frame->format = c->pix_fmt;&#xA;    frame->width  = c->width;&#xA;    frame->height = c->height;&#xA;&#xA;    //I suspect this is the problem&#xA;    ret = av_frame_get_buffer(frame, 0);&#xA;    if(ret &lt; 0)&#xA;    {&#xA;        fprintf(stderr, "Could not allocate the video frame data\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* encode 25 frames*/&#xA;    for(i = 0; i &lt; 25; i&#x2B;&#x2B;) &#xA;    {&#xA;&#xA;        /* make sure the frame data is writable */&#xA;        ret = av_frame_make_writable(frame);&#xA;        if(ret &lt; 0)&#xA;        {&#xA;            return 0;&#xA;        }&#xA;        //FIll Frame with picture data&#xA;        PictureToFrame(i, frame, c->height, c->width);&#xA;&#xA;        /* encode the image */&#xA;        encode(c, frame, pkt, f);&#xA;    }&#xA;&#xA;    /* flush the encoder */&#xA;    encode(c, NULL, pkt, f);&#xA;&#xA;    /* add sequence end code to have a real MPEG file */&#xA;    if (codec->id == AV_CODEC_ID_MPEG1VIDEO || codec->id == AV_CODEC_ID_MPEG2VIDEO)&#xA;        fwrite(endcode, 1, sizeof(endcode), f);&#xA;    fclose(f);&#xA;&#xA;    avcodec_free_context(&amp;c);&#xA;    av_frame_free(&amp;frame);&#xA;    av_packet_free(&amp;pkt);&#xA;&#xA;    return 0;&#xA;}&#xA;&#xA;

    &#xA;