
Recherche avancée
Médias (2)
-
Exemple de boutons d’action pour une collection collaborative
27 février 2013, par
Mis à jour : Mars 2013
Langue : français
Type : Image
-
Exemple de boutons d’action pour une collection personnelle
27 février 2013, par
Mis à jour : Février 2013
Langue : English
Type : Image
Autres articles (43)
-
Publier sur MédiaSpip
13 juin 2013Puis-je poster des contenus à partir d’une tablette Ipad ?
Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir -
Encodage et transformation en formats lisibles sur Internet
10 avril 2011MediaSPIP transforme et ré-encode les documents mis en ligne afin de les rendre lisibles sur Internet et automatiquement utilisables sans intervention du créateur de contenu.
Les vidéos sont automatiquement encodées dans les formats supportés par HTML5 : MP4, Ogv et WebM. La version "MP4" est également utilisée pour le lecteur flash de secours nécessaire aux anciens navigateurs.
Les documents audios sont également ré-encodés dans les deux formats utilisables par HTML5 :MP3 et Ogg. La version "MP3" (...) -
Selection of projects using MediaSPIP
2 mai 2011, parThe examples below are representative elements of MediaSPIP specific uses for specific projects.
MediaSPIP farm @ Infini
The non profit organizationInfini develops hospitality activities, internet access point, training, realizing innovative projects in the field of information and communication technologies and Communication, and hosting of websites. It plays a unique and prominent role in the Brest (France) area, at the national level, among the half-dozen such association. Its members (...)
Sur d’autres sites (4790)
-
FFMPEG and STB_Image Create awful Picture
9 février 2023, par murage kibichoI 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.

/
This is the original image



Perhaps I allocate my frame buffer incorrectly ?

ret = av_frame_get_buffer(frame, 0);




This is my entire program


#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "stb_image_resize.h"
#include 

#include <libavcodec></libavcodec>avcodec.h>
#include <libavutil></libavutil>opt.h>
#include <libavutil></libavutil>imgutils.h>
#include <libswscale></libswscale>swscale.h>
//gcc stack.c -lm -o stack.o `pkg-config --cflags --libs libavformat libavcodec libswresample libswscale libavutil` && ./stack.o

/*
int i : pts of current frame
*/
void PictureToFrame(int i, AVFrame *frame, int height, int width)
{
 //Use stb image to get rgb values
 char *fileName = "profil.jpeg";
 int imageHeight = 0;
 int imageWidth = 0;
 int colorChannels = 0;
 int arrayLength = 0;
 unsigned char *image = stbi_load(fileName,&imageWidth,&imageHeight,&colorChannels,0);
 
 printf("(height: %d, width: %d)\n",imageHeight, imageWidth);
 assert(colorChannels == 3 && imageHeight == height && imageWidth == width);
 
 //Convert unsigned char * to uint8_t *
 arrayLength = imageHeight * imageWidth * colorChannels;
 uint8_t *rgb = calloc(arrayLength, sizeof(uint8_t));
 int j = arrayLength-1;
 for(int i = 0; i < arrayLength; i++)
 {
 rgb[i] = (uint8_t) image[i];
 }
 
 //Use SwsContext to scale RGB to YUV420P and write to frame
 const int in_linesize[1] = { 3* imageWidth};
 struct SwsContext *sws_context = NULL;
 sws_context = sws_getCachedContext(sws_context,
 imageWidth, imageHeight, AV_PIX_FMT_RGB24,
 imageWidth, imageHeight, AV_PIX_FMT_YUV420P,
 0, 0, 0, 0);
 sws_scale(sws_context, (const uint8_t * const *)&rgb, in_linesize, 0,
 imageHeight, frame->data, frame->linesize);
 //Save frame pts
 frame->pts = i;
 
 //Free alloc'd data
 stbi_image_free(image);
 sws_freeContext(sws_context);
 free(rgb);
}
static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt, FILE *outfile)
{
 int returnValue;
 /* send the frame to the encoder */
 if(frame)
 {
 printf("Send frame %3"PRId64"\n", frame->pts);
 }
 returnValue = avcodec_send_frame(enc_ctx, frame);
 if(returnValue < 0)
 {
 printf("Error sending a frame for encoding\n");
 return;
 }
 while(returnValue >= 0)
 {
 returnValue = avcodec_receive_packet(enc_ctx, pkt);
 if(returnValue == AVERROR(EAGAIN) || returnValue == AVERROR_EOF)
 {
 return;
 }
 else if(returnValue < 0)
 {
 printf("Error during encoding\n");
 return;
 }

 printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size);
 fwrite(pkt->data, 1, pkt->size, outfile);
 av_packet_unref(pkt);
 }
}


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

 filename = "outo.mp4";
 codec_name = "mpeg1video";//"mpeg1video";//"libx264";


 /* find the mpeg1video encoder */
 codec = avcodec_find_encoder_by_name(codec_name);
 if(!codec)
 {
 printf("Error finding codec\n");
 return 0;
 }

 c = avcodec_alloc_context3(codec);
 if(!c)
 {
 printf("Error allocating c\n");
 return 0;
 }

 pkt = av_packet_alloc();
 if(!pkt)
 {
 printf("Error allocating pkt\n");
 return 0;
 }

 /* put sample parameters */
 c->bit_rate = 400000;
 /* resolution must be a multiple of two */
 c->width = 800;
 c->height = 800;
 /* frames per second */
 c->time_base = (AVRational){1, 25};
 c->framerate = (AVRational){25, 1};
 c->gop_size = 10;
 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 */
 ret = avcodec_open2(c, codec, NULL);
 if(ret < 0) 
 {
 printf("Error opening codec\n");
 return 0;
 }

 f = fopen(filename, "wb");
 if(!f)
 {
 printf("Error opening file\n");
 return 0;
 }

 frame = av_frame_alloc();
 if(!frame)
 {
 printf("Error allocating frame\n");
 return 0;
 }
 frame->format = c->pix_fmt;
 frame->width = c->width;
 frame->height = c->height;

 //I suspect this is the problem
 ret = av_frame_get_buffer(frame, 0);
 if(ret < 0)
 {
 fprintf(stderr, "Could not allocate the video frame data\n");
 exit(1);
 }

 /* encode 25 frames*/
 for(i = 0; i < 25; i++) 
 {

 /* make sure the frame data is writable */
 ret = av_frame_make_writable(frame);
 if(ret < 0)
 {
 return 0;
 }
 //FIll Frame with picture data
 PictureToFrame(i, frame, c->height, c->width);

 /* encode the image */
 encode(c, frame, pkt, f);
 }

 /* flush the encoder */
 encode(c, NULL, pkt, f);

 /* add sequence end code to have a real MPEG file */
 if (codec->id == AV_CODEC_ID_MPEG1VIDEO || codec->id == AV_CODEC_ID_MPEG2VIDEO)
 fwrite(endcode, 1, sizeof(endcode), f);
 fclose(f);

 avcodec_free_context(&c);
 av_frame_free(&frame);
 av_packet_free(&pkt);

 return 0;
}




-
AC3 decoding throws error number -16976906 ... vlc plays well
23 décembre 2022, par user1940163I have got a mpeg ts file with following composition (shown by ffprobe)


ffprobe version N-109444-geef763c705 Copyright (c) 2007-2022 the FFmpeg developers
 built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
 configuration: --enable-openssl
 libavutil 57. 43.100 / 57. 43.100
 libavcodec 59. 55.103 / 59. 55.103
 libavformat 59. 34.102 / 59. 34.102
 libavdevice 59. 8.101 / 59. 8.101
 libavfilter 8. 53.100 / 8. 53.100
 libswscale 6. 8.112 / 6. 8.112
 libswresample 4. 9.100 / 4. 9.100
[mpegts @ 0x56201c2c1cc0] Could not find codec parameters for stream 1 (Audio: ac3 ([129][0][0][0] / 0x0081), stereo, fltp): unspecified sample rate
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, mpegts, from 'ff_vlc.ts':
 Duration: 00:10:00.02, start: 1.400000, bitrate: 1839 kb/s
 Program 1
 Metadata:
 service_name : Service01
 service_provider: FFmpeg
 Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 856x480 [SAR 320:321 DAR 16:9], 30 fps, 59.94 tbr, 90k tbn
 Stream #0:1[0x101](spa): Audio: ac3 ([129][0][0][0] / 0x0081), stereo, fltp




I intend to transcode this so that I copy the video as it is but the audio will be encoded to aac ...so that I can play it in the browser.


I use the following ffmpeg command to attempt that


ffmpeg -i ff_vlc.ts -vcodec copy -acodec aac -map 0:v:0 -map 0:a:0 ff_vlc_2.ts



this throws errors with -16976906 as follows..........( I have clipped the repetitive excessively long output)


ffmpeg -i ff_vlc.ts -vcodec copy -acodec aac -map 0:v:0 -map 0:a:0 ff_vlc_2.ts
ffmpeg version N-109444-geef763c705 Copyright (c) 2000-2022 the FFmpeg developers
 built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
 configuration: --enable-openssl
 libavutil 57. 43.100 / 57. 43.100
 libavcodec 59. 55.103 / 59. 55.103
 libavformat 59. 34.102 / 59. 34.102
 libavdevice 59. 8.101 / 59. 8.101
 libavfilter 8. 53.100 / 8. 53.100
 libswscale 6. 8.112 / 6. 8.112
 libswresample 4. 9.100 / 4. 9.100
[mpegts @ 0x55b4369b2440] Could not find codec parameters for stream 1 (Audio: ac3 ([129][0][0][0] / 0x0081), stereo, fltp): unspecified sample rate
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, mpegts, from 'ff_vlc.ts':
 Duration: 00:10:00.02, start: 1.400000, bitrate: 1839 kb/s
 Program 1
 Metadata:
 service_name : Service01
 service_provider: FFmpeg
 Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 856x480 [SAR 320:321 DAR 16:9], 30 fps, 59.94 tbr, 90k tbn
 Stream #0:1[0x101](spa): Audio: ac3 ([129][0][0][0] / 0x0081), stereo, fltp
Stream mapping:
 Stream #0:0 -> #0:0 (copy)
 Stream #0:1 -> #0:1 (ac3 (native) -> aac (native))
Press [q] to stop, [?] for help
Error while decoding stream #0:1: Error number -16976906 occurred
 Last message repeated 17065 times
Too many packets buffered for output stream 0:0.
Error submitting a packet to the muxer for output stream #0:0.
Error while decoding stream #0:1: Error number -16976906 occurred
 Last message repeated 2 times
Too many packets buffered for output stream 0:0.
Error submitting a packet to the muxer for output stream #0:0.
Too many packets buffered for output stream 0:0.
Error submitting a packet to the muxer for output stream #0:0.
Too many packets buffered for output stream 0:0.
Error submitting a packet to the muxer for output stream #0:0.
Error while decoding stream #0:1: Error number -16976906 occurred
 Last message repeated 2 times
Too many packets buffered for output stream 0:0.
Error submitting a packet to the muxer for output stream #0:0.
Too many packets buffered for output stream 0:0.
Error submitting a packet to the muxer for output stream #0:0.
Error while decoding stream #0:1: Error number -16976906 occurred
 Last message repeated 2 times
....
....
....(repetitive output clipped and removed)
....
....
 Last message repeated 2 times
Too many packets buffered for output stream 0:0.
Error submitting a packet to the muxer for output stream #0:0.
Too many packets buffered for output stream 0:0.
Error submitting a packet to the muxer for output stream #0:0.
Too many packets buffered for output stream 0:0.
Error submitting a packet to the muxer for output stream #0:0.
Too many packets buffered for output stream 0:0.
Error submitting a packet to the muxer for output stream #0:0.
Error while decoding stream #0:1: Error number -16976906 occurred
 Last message repeated 2 times
Too many packets buffered for output stream 0:0.
Error submitting a packet to the muxer for output stream #0:0.
Too many packets buffered for output stream 0:0.
Error submitting a packet to the muxer for output stream #0:0.
Error while decoding stream #0:1: Error number -16976906 occurred
Too many packets buffered for output stream 0:0.
Error submitting a packet to the muxer for output stream #0:0.
Too many packets buffered for output stream 0:0.
Error submitting a packet to the muxer for output stream #0:0.
[abuffer @ 0x56289e5ab100] Value inf for parameter 'time_base' out of range [0 - 2.14748e+09]
 Last message repeated 1 times
[abuffer @ 0x56289e5ab100] Error setting option time_base to value 1/0.
[graph_0_in_0_1 @ 0x5628a3f5e800] Error applying options to the filter.
Error reinitializing filters!
Error while filtering: Numerical result out of range
Finishing stream 0:1 without any data written to it.
[abuffer @ 0x56289b2b89c0] Value inf for parameter 'time_base' out of range [0 - 2.14748e+09]
 Last message repeated 1 times
[abuffer @ 0x56289b2b89c0] Error setting option time_base to value 1/0.
[graph_0_in_0_1 @ 0x56289a63e780] Error applying options to the filter.
Error configuring filter graph
Conversion failed!




I tried the above even with this command


ffmpeg -analyzeduration 2147483647 -probesize 2147483647 -i ff_vlc.ts -vcodec copy -acodec aac -map 0:v:0 -map 0:a:0 ff_vlc_2.ts



Still get the same errors. Only changed lines in the output are


[mpegts @ 0x55e1b757d580] Failed to allocate buffers for seekback
[mpegts @ 0x55e1b757d580] Could not find codec parameters for stream 1 (Audio: ac3 ([129][0][0][0] / 0x0081), stereo, fltp): unspecified sample rate
Consider increasing the value for the 'analyzeduration' (2147483647) and 'probesize' (2147483647) options




VLC player has no problems in playing this audio ... only ffmpeg cannot decode.


How do I fix this ?


Please help
Thanks


-
Error submitting the frame for encoding when submitting NV12 texture
6 mai 2022, par Caio AugustoI'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.