Recherche avancée

Médias (1)

Mot : - Tags -/artwork

Autres articles (99)

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    The zip file provided here only contains the sources of MediaSPIP in its standalone version.
    To get a working installation, you must manually install all-software dependencies on the server.
    If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)

  • Multilang : améliorer l’interface pour les blocs multilingues

    18 février 2011, par

    Multilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
    Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela.

  • L’agrémenter visuellement

    10 avril 2011

    MediaSPIP est basé sur un système de thèmes et de squelettes. Les squelettes définissent le placement des informations dans la page, définissant un usage spécifique de la plateforme, et les thèmes l’habillage graphique général.
    Chacun peut proposer un nouveau thème graphique ou un squelette et le mettre à disposition de la communauté.

Sur d’autres sites (12957)

  • FFMPEG Encoding Issues

    16 octobre 2014, par madprogrammer2015

    I am having issues encoding screen captures, into a h.264 file for viewing. The program below is cobbled together from examples here and here. The first example, uses an older version of the ffmpeg api. So I tried to update that example for use in my program. The file is created and has something written to it, but when I view the file. The encoded images are all distorted. I am able to run the video encoding example from the ffmpeg api successfully. This is my first time posting, so if I missed anything please let me know.

    I appreciate any assistance that is given.

    My program :

    #include
    #include <string>
    #include <sstream>
    #include
    #include <iostream>
    #include

    extern "C"{
    #include
    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavutil></libavutil>imgutils.h>
    #include <libswscale></libswscale>swscale.h>
    #include <libavutil></libavutil>opt.h>
    }

    using namespace std;

    void ScreenShot(const char* BmpName, uint8_t *frame)
    {
       HWND DesktopHwnd = GetDesktopWindow();
       RECT DesktopParams;
       HDC DevC = GetDC(DesktopHwnd);
       GetWindowRect(DesktopHwnd,&amp;DesktopParams);
       DWORD Width = DesktopParams.right - DesktopParams.left;
       DWORD Height = DesktopParams.bottom - DesktopParams.top;

       DWORD FileSize = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+(sizeof(RGBTRIPLE)+1*(Width*Height*4));
       char *BmpFileData = (char*)GlobalAlloc(0x0040,FileSize);

       PBITMAPFILEHEADER BFileHeader = (PBITMAPFILEHEADER)BmpFileData;
       PBITMAPINFOHEADER  BInfoHeader = (PBITMAPINFOHEADER)&amp;BmpFileData[sizeof(BITMAPFILEHEADER)];

       BFileHeader->bfType = 0x4D42; // BM
       BFileHeader->bfSize = sizeof(BITMAPFILEHEADER);
       BFileHeader->bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);

       BInfoHeader->biSize = sizeof(BITMAPINFOHEADER);
       BInfoHeader->biPlanes = 1;
       BInfoHeader->biBitCount = 32;
       BInfoHeader->biCompression = BI_RGB;
       BInfoHeader->biHeight = Height;
       BInfoHeader->biWidth = Width;

       RGBTRIPLE *Image = (RGBTRIPLE*)&amp;BmpFileData[sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)];
       RGBTRIPLE color;
       //pPixels = (RGBQUAD **)new RGBQUAD[sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)];
       int start = clock();

       HDC CaptureDC = CreateCompatibleDC(DevC);
       HBITMAP CaptureBitmap = CreateCompatibleBitmap(DevC,Width,Height);
       SelectObject(CaptureDC,CaptureBitmap);
       BitBlt(CaptureDC,0,0,Width,Height,DevC,0,0,SRCCOPY|CAPTUREBLT);
       GetDIBits(CaptureDC,CaptureBitmap,0,Height,frame,(LPBITMAPINFO)BInfoHeader, DIB_RGB_COLORS);

       int end = clock();

       cout &lt;&lt; "it took " &lt;&lt; end - start &lt;&lt; " to capture a frame" &lt;&lt; endl;

       DWORD Junk;
       HANDLE FH = CreateFileA(BmpName,GENERIC_WRITE,FILE_SHARE_WRITE,0,CREATE_ALWAYS,0,0);
       WriteFile(FH,BmpFileData,FileSize,&amp;Junk,0);
       CloseHandle(FH);
       GlobalFree(BmpFileData);
    }

    void video_encode_example(const char *filename, int codec_id)
    {
       AVCodec *codec;
       AVCodecContext *c= NULL;
       int i, ret, x, y, got_output;
       FILE *f;
       AVFrame *frame;
       AVPacket pkt;
       uint8_t endcode[] = { 0, 0, 1, 0xb7 };

       printf("Encode video file %s\n", filename);

       /* find the mpeg1 video encoder */
       codec = avcodec_find_encoder(AV_CODEC_ID_H264);
       if (!codec) {
           fprintf(stderr, "Codec not found\n");
           cin.get();
           exit(1);
       }

       c = avcodec_alloc_context3(codec);
       if (!c) {
           fprintf(stderr, "Could not allocate video codec context\n");
           cin.get();
           exit(1);
       }

       /* put sample parameters */
       c->bit_rate = 400000;
       /* resolution must be a multiple of two */
       c->width = 352;
       c->height = 288;
       /* frames per second */
       c->time_base.num=1;
       c->time_base.den = 25;
       c->gop_size = 10; /* emit one intra frame every ten frames */
       c->max_b_frames=1;
       c->pix_fmt = AV_PIX_FMT_YUV420P;

       if(codec_id == AV_CODEC_ID_H264)
           av_opt_set(c->priv_data, "preset", "slow", 0);

       /* open it */
       if (avcodec_open2(c, codec, NULL) &lt; 0) {
           fprintf(stderr, "Could not open codec\n");
           exit(1);
       }

       f = fopen(filename, "wb");
       if (!f) {
           fprintf(stderr, "Could not open %s\n", filename);
           exit(1);
       }

       frame = av_frame_alloc();
       if (!frame) {
           fprintf(stderr, "Could not allocate video frame\n");
           exit(1);
       }

       frame->format = c->pix_fmt;
       frame->width  = c->width;
       frame->height = c->height;

       /* the image can be allocated by any means and av_image_alloc() is
       just the most convenient way if av_malloc() is to be used */
       ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height, c->pix_fmt, 32);

       if (ret &lt; 0) {
           fprintf(stderr, "Could not allocate raw picture buffer\n");
           exit(1);
       }

       /* encode 1 second of video */
       for(i=0;i&lt;250;i++) {
           av_init_packet(&amp;pkt);
           pkt.data = NULL;    // packet data will be allocated by the encoder
           pkt.size = 0;

           fflush(stdout);
           /* prepare a dummy image */
           /* Y */
           for(y=0;yheight;y++) {
               for(x=0;xwidth;x++) {
                   frame->data[0][y * frame->linesize[0] + x] = x + y + i * 3;
               }
           }

           /* Cb and Cr */
           for(y=0;yheight/2;y++) {
               for(x=0;xwidth/2;x++) {
                   frame->data[1][y * frame->linesize[1] + x] = 128 + y + i * 2;
                   frame->data[2][y * frame->linesize[2] + x] = 64 + x + i * 5;
               }
           }

           frame->pts = i;

           /* encode the image */
           ret = avcodec_encode_video2(c, &amp;pkt, frame, &amp;got_output);
           if (ret &lt; 0) {
               fprintf(stderr, "Error encoding frame\n");
               exit(1);
           }

           if (got_output) {
               printf("Write frame %3d (size=%5d)\n", i, pkt.size);
               fwrite(pkt.data, 1, pkt.size, f);
               av_free_packet(&amp;pkt);
           }
       }

       /* get the delayed frames */
       for (got_output = 1; got_output; i++) {
           fflush(stdout);

           ret = avcodec_encode_video2(c, &amp;pkt, NULL, &amp;got_output);

           if (ret &lt; 0) {
               fprintf(stderr, "Error encoding frame\n");
               exit(1);
           }

           if (got_output) {
               printf("Write frame %3d (size=%5d)\n", i, pkt.size);
               fwrite(pkt.data, 1, pkt.size, f);
               av_free_packet(&amp;pkt);
           }
       }

       /* add sequence end code to have a real mpeg file */
       fwrite(endcode, 1, sizeof(endcode), f);
       fclose(f);

        avcodec_close(c);
        av_free(c);
        av_freep(&amp;frame->data[0]);
        av_frame_free(&amp;frame);
        printf("\n");
    }

    void write_video_frame()
    {
    }

    int lineSizeOfFrame(int width)
    {
       return  (width*24 + 31)/32 * 4;//((width*24 / 8) + 3) &amp; ~3;//(width*24 + 31)/32 * 4;
    }

    int getScreenshotWithCursor(uint8_t* frame)
    {
       int successful = 0;
           HDC screen, bitmapDC;
           HBITMAP screen_bitmap;

           screen = GetDC(NULL);
           RECT DesktopParams;

           HWND desktop = GetDesktopWindow();
           GetWindowRect(desktop, &amp;DesktopParams);

           int width = DesktopParams.right;
           int height = DesktopParams.bottom;

           bitmapDC = CreateCompatibleDC(screen);
           screen_bitmap = CreateCompatibleBitmap(screen, width, height);
           SelectObject(bitmapDC, screen_bitmap);
           if (BitBlt(bitmapDC, 0, 0, width, height, screen, 0, 0, SRCCOPY))
           {
                   int pos_x, pos_y;
                   HICON hcur;
                   ICONINFO icon_info;
                   CURSORINFO cursor_info;
                   cursor_info.cbSize = sizeof(CURSORINFO);
                   if (GetCursorInfo(&amp;cursor_info))
                   {
                           if (cursor_info.flags == CURSOR_SHOWING)
                           {
                                   hcur = CopyIcon(cursor_info.hCursor);
                                   if (GetIconInfo(hcur, &amp;icon_info))
                                   {
                                           pos_x = cursor_info.ptScreenPos.x - icon_info.xHotspot;
                                           pos_y = cursor_info.ptScreenPos.y - icon_info.yHotspot;
                                           DrawIcon(bitmapDC, pos_x, pos_y, hcur);
                                           if (icon_info.hbmColor) DeleteObject(icon_info.hbmColor);
                                           if (icon_info.hbmMask) DeleteObject(icon_info.hbmMask);
                                   }
                           }
                   }
                   int header_size = sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD);
                   size_t line_size = lineSizeOfFrame(width);
                   PBITMAPINFO lpbi = (PBITMAPINFO) malloc(header_size);
                   lpbi->bmiHeader.biSize = header_size;
                   lpbi->bmiHeader.biWidth = width;
                   lpbi->bmiHeader.biHeight = height;
                   lpbi->bmiHeader.biPlanes = 1;
                   lpbi->bmiHeader.biBitCount = 24;
                   lpbi->bmiHeader.biCompression = BI_RGB;
                   lpbi->bmiHeader.biSizeImage = height*line_size;
                   lpbi->bmiHeader.biXPelsPerMeter = 0;
                   lpbi->bmiHeader.biYPelsPerMeter = 0;
                   lpbi->bmiHeader.biClrUsed = 0;
                   lpbi->bmiHeader.biClrImportant = 0;
                   if (GetDIBits(bitmapDC, screen_bitmap, 0, height, (LPVOID)frame, lpbi, DIB_RGB_COLORS))
                   {
                       int i;
                       uint8_t *buf_begin = frame;
                       uint8_t *buf_end = frame + line_size*(lpbi->bmiHeader.biHeight - 1);
                       void *temp = malloc(line_size);
                       for (i = 0; i &lt; lpbi->bmiHeader.biHeight / 2; ++i)
                       {
                           memcpy(temp, buf_begin, line_size);
                           memcpy(buf_begin, buf_end, line_size);
                           memcpy(buf_end, temp, line_size);
                           buf_begin += line_size;
                           buf_end -= line_size;
                       }
                       cout &lt;&lt; *buf_begin &lt;&lt; endl;
                       free(temp);
                       successful = 1;
                   }
                   free(lpbi);
           }
           DeleteObject(screen_bitmap);
           DeleteDC(bitmapDC);
           ReleaseDC(NULL, screen);
           return successful;
    }

    int main()
    {
       RECT DesktopParams;

       HWND desktop = GetDesktopWindow();
       GetWindowRect(desktop, &amp;DesktopParams);

       int width = DesktopParams.right;
       int height = DesktopParams.bottom;
       uint8_t *frame = (uint8_t *)malloc(width * height);

       AVCodec *codec;
       AVCodecContext *codecContext = NULL;
       AVPacket packet;
       FILE *f;
       AVFrame *pictureYUV = NULL;
       AVFrame *pictureRGB;

       avcodec_register_all();

       codec = avcodec_find_encoder(AV_CODEC_ID_H264);

       if(!codec)
       {
           cout &lt;&lt; "codec not found!" &lt;&lt; endl;
           cin.get();
           return 1;
       }
       else
       {
           cout &lt;&lt; "codec h265 found!" &lt;&lt; endl;
       }

       codecContext = avcodec_alloc_context3(codec);

       codecContext->bit_rate = width * height * 4;
       codecContext->width = width;
       codecContext->height = height;
       codecContext->time_base.num = 1;
       codecContext->time_base.den = 250;
       codecContext->gop_size = 10;
       codecContext->max_b_frames = 1;
       codecContext->keyint_min = 1;
       codecContext->i_quant_factor = (float)0.71;                        // qscale factor between P and I frames
       codecContext->b_frame_strategy = 20;                               ///// find out exactly what this does
       codecContext->qcompress = (float)0.6;                              ///// find out exactly what this does
       codecContext->qmin = 20;                                           // minimum quantizer
       codecContext->qmax = 51;                                           // maximum quantizer
       codecContext->max_qdiff = 4;                                       // maximum quantizer difference between frames
       codecContext->refs = 4;                                            // number of reference frames
       codecContext->trellis = 1;
       codecContext->pix_fmt = AV_PIX_FMT_YUV420P;
       codecContext->codec_id = AV_CODEC_ID_H264;
       codecContext->codec_type = AVMEDIA_TYPE_VIDEO;

       if(avcodec_open2(codecContext, codec, NULL) &lt; 0)
       {
           cout &lt;&lt; "couldn't open codec" &lt;&lt; endl;
           cout &lt;&lt; stderr &lt;&lt; endl;
           cin.get();
           return 1;
       }
       else
       {
           cout &lt;&lt; "opened h265 codec!" &lt;&lt; endl;
           cin.get();
       }

       f = fopen("test.h264", "wb");

       if(!f)
       {
           cout &lt;&lt; "Unable to open file" &lt;&lt; endl;
           return 1;
       }



       struct SwsContext *img_convert_ctx = sws_getContext(codecContext->width, codecContext->height, PIX_FMT_RGB32, codecContext->width,
           codecContext->height, codecContext->pix_fmt, SWS_BILINEAR, NULL, NULL, NULL);

       int got_output = 0, i = 0;
       uint8_t encode[] = { 0, 0, 1, 0xb7 };

       try
       {
           for(i = 0; i &lt; codecContext->time_base.den; i++)
           {
               av_init_packet(&amp;packet);
               packet.data = NULL;
               packet.size = 0;

               pictureRGB = av_frame_alloc();
               pictureYUV = av_frame_alloc();

               getScreenshotWithCursor(frame);
               //ScreenShot("example.bmp", frame);

               int nbytes = avpicture_get_size(AV_PIX_FMT_YUV420P, codecContext->width, codecContext->height);                                    // allocating outbuffer
               uint8_t* outbuffer = (uint8_t*)av_malloc(nbytes*sizeof(uint8_t));

               pictureRGB = av_frame_alloc();
               pictureYUV = av_frame_alloc();

               avpicture_fill((AVPicture*)pictureRGB, frame, PIX_FMT_RGB32, codecContext->width, codecContext->height);                   // fill image with input screenshot
               avpicture_fill((AVPicture*)pictureYUV, outbuffer, PIX_FMT_YUV420P, codecContext->width, codecContext->height);
               av_image_alloc(pictureYUV->data, pictureYUV->linesize, codecContext->width, codecContext->height, codecContext->pix_fmt, 32);

               sws_scale(img_convert_ctx, pictureRGB->data, pictureRGB->linesize, 0, codecContext->height, pictureYUV->data, pictureYUV->linesize);

               pictureYUV->pts = i;

               avcodec_encode_video2(codecContext, &amp;packet, pictureYUV, &amp;got_output);

               if(got_output)
               {
                   printf("Write frame %3d (size=%5d)\n", i, packet.size);
                   fwrite(packet.data, 1, packet.size, f);
                   av_free_packet(&amp;packet);
               }

               //av_frame_free(&amp;pictureRGB);
               //av_frame_free(&amp;pictureYUV);
           }

           for(got_output = 1; got_output; i++)
           {
               fflush(stdout);

               avcodec_encode_video2(codecContext, &amp;packet, NULL, &amp;got_output);

               if (got_output) {
                   printf("Write frame %3d (size=%5d)\n", i, packet.size);
                   fwrite(packet.data, 1, packet.size, f);
                   av_free_packet(&amp;packet);
               }
           }
       }
       catch(std::exception ex)
       {
           cout &lt;&lt; ex.what() &lt;&lt; endl;
       }

       avcodec_close(codecContext);
       av_free(codecContext);
       av_freep(&amp;pictureYUV->data[0]);
       //av_frame_free(&amp;picture);
       fwrite(encode, 1, sizeof(encode), f);
       fclose(f);

       cin.get();

       return 0;
    }
    </iostream></sstream></string>
  • avcodec_decode_audio3 of FFmpeg return -1

    10 janvier 2015, par user1325717

    I use FFmpeg on android to decode mp3. I set all decoder enable on configure and make the .so file correctly. Here’s the .sh which add parameter for configure file :

    NDK=~/android-ndk-r5b
    PLATFORM=$NDK/platforms/android-8/arch-arm/
    PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86


    function build_one
    {
    ./configure --target-os=linux \
       --prefix=$PREFIX \
       --enable-cross-compile \
       --extra-libs="-lgcc" \
       --arch=arm \
       --cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
       --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
       --nm=$PREBUILT/bin/arm-linux-androideabi-nm \
       --sysroot=$PLATFORM \
       --extra-cflags=" -O3 -fpic -DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm -Wno-psabi -fno-short-enums  -fno-strict-aliasing -finline-limit=300 $OPTIMIZE_CFLAGS " \
       --disable-shared \
       --enable-static \
       --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib  -nostdlib -lc -lm -ldl -llog" \
       --enable-demuxer=mov \
       --enable-demuxer=h264 \
       --disable-ffplay \
       --enable-protocol=file \
       --enable-avformat \
       --enable-avcodec \
       --enable-decoder=rawvideo \
       --enable-decoder=mjpeg \
       --enable-decoder=h263 \
       --enable-decoder=mpeg4 \
       --enable-decoder=h264 \
       --enable-decoder=mp3 \
       --enable-decoder=mp3adu \
       --enable-decoder=mp3adufloat \
       --enable-decoder=mp3float \
       --enable-decoder=mp3on4 \
       --enable-decoder=mp3on4float \
       --enable-parser=h264 \
       --disable-network \
       --enable-zlib \
       --disable-avfilter \
       --disable-avdevice \
       $ADDITIONAL_CONFIGURE_FLAG


    make clean
    make  -j4 install

    $PREBUILT/bin/arm-linux-androideabi-ar d libavcodec/libavcodec.a inverse.o

    $PREBUILT/bin/arm-linux-androideabi-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib  -soname libffmpeg.so -shared -nostdlib  -z,noexecstack -Bsymbolic --whole-archive --no-undefined -o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog  --warn-once  --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a
    }

    #arm v7vfpv3
    CPU=armv7-a
    OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "
    PREFIX=./android/$CPU
    ADDITIONAL_CONFIGURE_FLAG=
    build_one

    I can read file and get info (decode type\ format type), then I follow the FFmpeg’s sample to call avcodec_decode_audio3 to decode audio file, it return -1, decoding failed. Is some body can tell me what is happened, thanks !

    #include
    #include
    #include
    #include <android></android>log.h>
    #include "libavcodec/avcodec.h"
    #include "libavformat/avformat.h"

    #define AUDIO_INBUF_SIZE 20480
    #define AUDIO_REFILL_THRESH 4096
    #define LOG_TAG "FFmpegTest"
    #define LOG_LEVEL 10
    #define LOGI(level, ...) if (level &lt;= LOG_LEVEL) {__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__);}
    #define LOGE(level, ...) if (level &lt;= LOG_LEVEL) {__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__);}

    char *sourceFileName;
    char *resultFileName;
    AVFormatContext *gFormatCtx;
    int audioStreamIndex;
    AVCodec *gCodec;
    AVCodecContext *gCodecCtx;
    FILE *sourceFile, *resultFile;
    int out_size, len;
    uint8_t *outbuf;
    uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
    AVPacket avpkt;

    JNIEXPORT void JNICALL Java_roman10_ffmpegTest_VideoBrowser_naDecode(JNIEnv *pEnv, jobject pObj, jstring source_file_name, jstring result_file_name)
    {
       LOGI(10, "start decode.");
       /* get source file's name */
       sourceFileName = (char *)(*pEnv)->GetStringUTFChars(pEnv, source_file_name, NULL);
       if (sourceFileName == NULL) {
           LOGE(1, "cannot get the source file name!");
           exit(1);
       }
       LOGI(10, "source file name is %s", sourceFileName);

       avcodec_init();

       av_register_all();

       /* get format somthing of source file to AVFormatContext */
       int lError;
       if ((lError = av_open_input_file(&amp;gFormatCtx, sourceFileName, NULL, 0, NULL)) !=0 ) {
           LOGE(1, "Error open source file: %d", lError);
           exit(1);
       }
       if ((lError = av_find_stream_info(gFormatCtx)) &lt; 0) {
           LOGE(1, "Error find stream information: %d", lError);
           exit(1);
       }
       LOGI(10, "audio format: %s", gFormatCtx->iformat->name);
       LOGI(10, "audio bitrate: %d", gFormatCtx->bit_rate);

       /* ???get audio stream's id and codec of source file??? */
       audioStreamIndex = av_find_best_stream(gFormatCtx, AVMEDIA_TYPE_AUDIO, -1, -1, &amp;gCodec, 0);
       LOGI(10, "audioStreamIndex %d", audioStreamIndex);
       if (audioStreamIndex == AVERROR_STREAM_NOT_FOUND) {
           LOGE(1, "cannot find a audio stream");
           exit(1);
       } else if (audioStreamIndex == AVERROR_DECODER_NOT_FOUND) {
           LOGE(1, "audio stream found, but no decoder is found!");
           exit(1);
       }
       LOGI(10, "audio codec: %s", gCodec->name);

       /* get codec somthing of audio stream to AVCodecContext */
       gCodecCtx = gFormatCtx->streams[audioStreamIndex]->codec;
       if (avcodec_open(gCodecCtx, gCodec) &lt; 0) {
       LOGE(1, "cannot open the audio codec!");
           exit(1);
       }

       /* ???gCodec = avcodec_find_decoder(gCodecCtx->codec_id);
       if (!gCodec) {
       LOGE(1, "codec not found");
           return;
       }

       gCodecCtx= avcodec_alloc_context();

       if (avcodec_open(gCodecCtx, gCodec) &lt; 0) {
       LOGE(1, "could not open codec");
           exit(1);
       }??? */

       outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);

       sourceFile = fopen(sourceFileName, "rb");
       if (!sourceFile) {
       LOGE(1, "could not open %s", sourceFileName);
           exit(1);
       }
       /* get result file's name */
       resultFileName = (char *)(*pEnv)->GetStringUTFChars(pEnv, result_file_name, NULL);
       LOGI(10, "result file name is %s", resultFileName);
       resultFile = fopen(resultFileName, "wb");
       if (!resultFile) {
       LOGE(1, "could not create result file");
           av_free(gCodecCtx);
           exit(1);
       }

       av_init_packet(&amp;avpkt);

       avpkt.data = inbuf;
       avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, sourceFile);
       LOGI(10, "avpkt.size: %d", avpkt.size);
       /* decode file */
       while (avpkt.size > 0) {
           out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
           len = avcodec_decode_audio3(gCodecCtx, (short *)outbuf, &amp;out_size, &amp;avpkt);
           if (len &lt; 0) {
               LOGE(1, "Error while decoding: %d", len);
               exit(1);
           }
           if (out_size > 0) {
               fwrite(outbuf, 1, out_size, resultFile);
           }
           avpkt.size -= len;
           avpkt.data += len;
           if (avpkt.size &lt; AUDIO_REFILL_THRESH) {
               memmove(inbuf, avpkt.data, avpkt.size);
               avpkt.data = inbuf;
               len = fread(avpkt.data + avpkt.size, 1,
                           AUDIO_INBUF_SIZE - avpkt.size, sourceFile);
               if (len > 0)
                   avpkt.size += len;
           }
       }

       fclose(resultFile);
       fclose(sourceFile);
       free(outbuf);

       avcodec_close(gCodecCtx);
       av_free(gCodecCtx);

       LOGI(10, "end decode.");
    }
  • Convert PRORES PCM S24LE to H.264 AAC

    23 septembre 2014, par Adam Walker

    I’m a rookie when it comes to media conversions. I’m trying use ffmpeg to convert raw PCM S24LE audio to something usable by Premiere. I also have raw video in the same format. PRORES.

    Here is the code I currently have.

    cd ../ffmpeg/bin
    :again
    if "%~1" == "" goto done
    ffmpeg -f  s24le -i "%~1" -strict experimental -acodec aac ../../2Ready4Premiere/%~n1.mp3
    shift
    goto again
    :done
    pause
    exit