
Recherche avancée
Médias (1)
-
The Great Big Beautiful Tomorrow
28 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Texte
Autres articles (56)
-
MediaSPIP v0.2
21 juin 2013, parMediaSPIP 0.2 est la première version de MediaSPIP stable.
Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
Comme pour la version précédente, 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 (...) -
MediaSPIP version 0.1 Beta
16 avril 2011, parMediaSPIP 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 (...) -
Les autorisations surchargées par les plugins
27 avril 2010, parMediaspip core
autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs
Sur d’autres sites (8538)
-
value of got_picture_ptr is always 0. when use avcodec_decode_video2()
4 septembre 2014, par user3867261I’m using visual studio 2013 professional.
below code is simple decode tutorial using ffmpeg.
///> Include FFMpeg
extern "C" {
#include <libavformat></libavformat>avformat.h>
}
///> Library Link On Windows System
#pragma comment( lib, "avformat.lib" )
#pragma comment( lib, "avutil.lib" )
#pragma comment( lib, "avcodec.lib" )
static void write_ascii_frame(const char *szFileName, const AVFrame *pVframe);
int main(void)
{
const char *szFilePath = "C:\\singlo\\example.avi";
///> Initialize libavformat and register all the muxers, demuxers and protocols.
av_register_all();
///> Do global initialization of network components.
avformat_network_init();
int ret;
AVFormatContext *pFmtCtx = NULL;
///> Open an input stream and read the header.
ret = avformat_open_input( &pFmtCtx, szFilePath, NULL, NULL );
if( ret != 0 ) {
av_log( NULL, AV_LOG_ERROR, "File [%s] Open Fail (ret: %d)\n", ret );
exit( -1 );
}
av_log( NULL, AV_LOG_INFO, "File [%s] Open Success\n", szFilePath );
av_log( NULL, AV_LOG_INFO, "Format: %s\n", pFmtCtx->iformat->name );
///> Read packets of a media file to get stream information.
ret = avformat_find_stream_info( pFmtCtx, NULL );
if( ret < 0 ) {
av_log( NULL, AV_LOG_ERROR, "Fail to get Stream Information\n" );
exit( -1 );
}
av_log( NULL, AV_LOG_INFO, "Get Stream Information Success\n" );
///> Find Video Stream
int nVSI = -1;
int nASI = -1;
int i;
for( i = 0 ; i < pFmtCtx->nb_streams ; i++ ) {
if( nVSI < 0 && pFmtCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO ) {
nVSI = i;
}
else if( nASI < 0 && pFmtCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO ) {
nASI = i;
}
}
if( nVSI < 0 && nASI < 0 ) {
av_log( NULL, AV_LOG_ERROR, "No Video & Audio Streams were Found\n");
exit( -1 );
}
///> Find Video Decoder
AVCodec *pVideoCodec = avcodec_find_decoder( pFmtCtx->streams[nVSI]->codec->codec_id );
if( pVideoCodec == NULL ) {
av_log( NULL, AV_LOG_ERROR, "No Video Decoder was Found\n" );
exit( -1 );
}
///> Initialize Codec Context as Decoder
if( avcodec_open2( pFmtCtx->streams[nVSI]->codec, pVideoCodec, NULL ) < 0 ) {
av_log( NULL, AV_LOG_ERROR, "Fail to Initialize Decoder\n" );
exit( -1 );
}
///> Find Audio Decoder
AVCodec *pAudioCodec = avcodec_find_decoder( pFmtCtx->streams[nASI]->codec->codec_id );
if( pAudioCodec == NULL ) {
av_log( NULL, AV_LOG_ERROR, "No Audio Decoder was Found\n" );
exit( -1 );
}
///> Initialize Codec Context as Decoder
if( avcodec_open2( pFmtCtx->streams[nASI]->codec, pAudioCodec, NULL ) < 0 ) {
av_log( NULL, AV_LOG_ERROR, "Fail to Initialize Decoder\n" );
exit( -1 );
}
AVCodecContext *pVCtx = pFmtCtx->streams[nVSI]->codec;
AVCodecContext *pACtx = pFmtCtx->streams[nASI]->codec;
AVPacket pkt;
AVFrame* pVFrame, *pAFrame;
int bGotPicture = 0; // flag for video decoding
int bGotSound = 0; // flag for audio decoding
int bPrint = 0; // ë¹ëì¤ ì²« ì¥ë©´ë§ íì¼ë¡ ë¨ê¸°ê¸° ìí ìì flag ìëë¤
pVFrame = avcodec_alloc_frame();
pAFrame = avcodec_alloc_frame();
while( av_read_frame( pFmtCtx, &pkt ) >= 0 ) {
///> Decoding
if( pkt.stream_index == nVSI ) {
if( avcodec_decode_video2( pVCtx, pVFrame, &bGotPicture, &pkt ) >= 0 ) {
///////////////////////problem here/////////////////////////////////////////////
if( bGotPicture ) {
///> Ready to Render Image
av_log( NULL, AV_LOG_INFO, "Got Picture\n" );
if( !bPrint ) {
write_ascii_frame( "output.txt", pVFrame );
bPrint = 1;
}
}
}
// else ( < 0 ) : Decoding Error
}
else if( pkt.stream_index == nASI ) {
if( avcodec_decode_audio4( pACtx, pAFrame, &bGotSound, &pkt ) >= 0 ) {
if( bGotSound ) {
///> Ready to Render Sound
av_log( NULL, AV_LOG_INFO, "Got Sound\n" );
}
}
// else ( < 0 ) : Decoding Error
}
///> Free the packet that was allocated by av_read_frame
av_free_packet( &pkt );
}
av_free( pVFrame );
av_free( pAFrame );
///> Close an opened input AVFormatContext.
avformat_close_input( &pFmtCtx );
///> Undo the initialization done by avformat_network_init.
avformat_network_deinit();
return 0;
}
static void write_ascii_frame(const char *szFileName, const AVFrame *frame)
{
int x, y;
uint8_t *p0, *p;
const char arrAsciis[] = " .-+#";
FILE* fp = fopen( szFileName, "w" );
if( fp ) {
/* Trivial ASCII grayscale display. */
p0 = frame->data[0];
for (y = 0; y < frame->height; y++) {
p = p0;
for (x = 0; x < frame->width; x++)
putc( arrAsciis[*(p++) / 52], fp );
putc( '\n', fp );
p0 += frame->linesize[0];
}
fflush(fp);
fclose(fp);
}
}there is a problem in below part
if( avcodec_decode_video2( pVCtx, pVFrame, &bGotPicture, &pkt ) >= 0 ) {
///////////////////////problem here/////////////////////////////////////////////
if( bGotPicture ) {
///> Ready to Render Image
av_log( NULL, AV_LOG_INFO, "Got Picture\n" );
if( !bPrint ) {
write_ascii_frame( "output.txt", pVFrame );
bPrint = 1;
}
}
}the value of bGotPicture is always 0.. So i can’t decode video
plz help me.
where do problem occurs from ? in video ? in my code ? -
Use libav to copy raw H264 stream as mp4 without codec
11 décembre 2018, par cKt 1010Since my platform didn’t include libx264 some I can’t use H264 codec in libav.
I know this question is similar to Raw H264 frames in mpegts container using libavcodec. But trust me, I test bob2’s method but didn’t work.
There are some problem here :- How to set PTS and DTS ?
If I use setting below which was bob2 told, Libav will print : "Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly"
packet.flags |= AV_PKT_FLAG_KEY;
packet.pts = packet.dts = 0;So should I use frame rate to calculate it manually?
- How to set PPS and SPS ?
bob2 didn’t told it in his code, but it seems we can’t skip this step. Someone told me that it should be set to extradata which is in AVCodecContext struct. But what is formate ? should it include H264 header ?
- Should we delete
0x00 0x00 0x00 0x01
header one by one ?
Seems we must delete H264 header for every H264 frame. But it cost time anyway. Should we must do it ?
My code is mess (I tried to many method, lost in it now...). I past it below, and hope not confuse you.
Init :
AVOutputFormat *fmt;
AVFormatContext *oc;
AVCodec *audio_codec = NULL, *video_codec = NULL;
Int32 ret;
assert(video_st != NULL);
assert(audio_st != NULL);
/* Initialize libavcodec, and register all codecs and formats. */
av_register_all();
/* allocate the output media context */
printf("MediaSave: save file to %s", pObj->filePath);
avformat_alloc_output_context2(&oc, NULL, NULL, pObj->filePath);
if (!oc) {
Vps_printf(
"Could not deduce output format from file extension: using MPEG.");
avformat_alloc_output_context2(&oc, NULL, "mpeg", pObj->filePath);
}
if (!oc)
return SYSTEM_LINK_STATUS_EFAIL;
pObj->oc = oc;
fmt = oc->oformat;
fmt->video_codec = AV_CODEC_ID_H264;
Vps_printf("MediaSave: codec is %s", fmt->name);
/* Add the video streams using the default format codecs
* and initialize the codecs. */
if ((fmt->video_codec != AV_CODEC_ID_NONE) &&
(pObj->formate_type & MEDIA_SAVE_TYPE_VIDEO)) {
add_stream(video_st, oc, &video_codec, fmt->video_codec);
//open_video(oc, video_codec, video_st);
pObj->video_st = video_st;
pObj->video_codec = video_codec;
}
if ((fmt->audio_codec != AV_CODEC_ID_NONE) &&
(pObj->formate_type & MEDIA_SAVE_TYPE_AUDIO)) {
add_stream(audio_st, oc, &audio_codec, fmt->audio_codec);
//open_audio(oc, audio_codec, audio_st);
pObj->audio_codec = audio_codec;
pObj->audio_st = audio_st;
}
/* open the output file, if needed */
if (!(fmt->flags & AVFMT_NOFILE)) {
ret = avio_open(&oc->pb, pObj->filePath, AVIO_FLAG_WRITE);
if (ret < 0) {
Vps_printf("Could not open '%s': %s", pObj->filePath,
av_err2str(ret));
return SYSTEM_LINK_STATUS_EFAIL;
}
}Write h264
/* Write the stream header, if any. */
ret = avformat_write_header(oc, NULL);
int nOffset = 0;
int nPos =0;
uint8_t sps_pps[4] = { 0x00, 0x00, 0x00, 0x01 };
while(1)
{
AVFormatContext *oc = pObj->oc;
nPos = ReadOneNaluFromBuf(&naluUnit, bitstreamBuf->bufAddr + nOffset, bitstreamBuf->fillLength - nOffset);
if(naluUnit.type == 7 || naluUnit.type == 8) {
Vps_printf("Get type 7 or 8, Store it to extradata");
video_st->st->codec->extradata_size = naluUnit.size + sizeof(sps_pps);
video_st->st->codec->extradata = OSA_memAllocSR(OSA_HEAPID_DDR_CACHED_SR1, naluUnit.size + AV_INPUT_BUFFER_PADDING_SIZE, 32U);
memcpy(video_st->st->codec->extradata, sps_pps , sizeof(sps_pps));
memcpy(video_st->st->codec->extradata + sizeof(sps_pps), naluUnit.data, naluUnit.size);
break;
}
nOffset += nPos;
write_video_frame(oc, video_st, naluUnit);
if (nOffset >= bitstreamBuf->fillLength) {
FrameCounter++;
break;
}
}
static Int32 write_video_frame(AVFormatContext *oc, OutputStream *ost,
NaluUnit bitstreamBuf) {
Int32 ret;
static Int32 waitkey = 1, ptsInc = 0;
if (0 > ost->st->index) {
Vps_printf("Stream index less than 0");
return SYSTEM_LINK_STATUS_EFAIL;
}
AVStream *pst = oc->streams[ost->st->index];
// Init packet
AVPacket pkt;
av_init_packet(&pkt);
pkt.flags |= (0 >= getVopType(bitstreamBuf.data, bitstreamBuf.size))
? AV_PKT_FLAG_KEY
: 0;
pkt.stream_index = pst->index;
// Wait for key frame
if (waitkey) {
if (0 == (pkt.flags & AV_PKT_FLAG_KEY)){
return SYSTEM_LINK_STATUS_SOK;
}
else {
waitkey = 0;
Vps_printf("First frame");
}
}
pkt.pts = (ptsInc) * (90000 / STREAM_FRAME_RATE);
pkt.dts = (ptsInc) * (90000/STREAM_FRAME_RATE);
pkt.duration = 3000;
pkt.pos = -1;
ptsInc++;
ret = av_interleaved_write_frame(oc, &pkt);
if (ret < 0) {
Vps_printf("cannot write frame");
}
return SYSTEM_LINK_STATUS_SOK;}
-
using ffmpeg headers with a c program
15 avril 2014, par orpgoli'm trying to learn ffmpeg from drangers guide (for school), i have a mac so the first thing i did was to use Macports and get ffmpeg and sdl...
now when i'm tried to compile drangers code, the compiler didnt recognize the headers...
so i used -I on gnu when compiling, and also gave the "whole/path/name..." to the headers,
but i always get an error on some header missing...below i will put the code with my corrections.
i also tried including all the headers that i get an error about but there is always another header the compiler can't find
i tried both gnu (on console) and on xcode.
// tutorial01.c
// Code based on a tutorial by Martin Bohme (boehme@inb.uni-luebeckREMOVETHIS.de)
// Tested on Gentoo, CVS version 5/01/07 compiled with GCC 4.1.1
// A small sample program that shows how to use libavformat and libavcodec to
// read video from a file.
//
// Use
//
// gcc -o tutorial01 tutorial01.c -lavformat -lavcodec -lz
//
// to build (assuming libavformat and libavcodec are correctly installed
// your system).
//
// Run using
//
// tutorial01 myvideofile.mpg
//
// to write the first five frames from "myvideofile.mpg" to disk in PPM
// format.
#include "/opt/local/include/libavcodec/avcodec.h"
#include "/opt/local/include/libavformat/avformat.h"
#include
void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame) {
FILE *pFile;
char szFilename[32];
int y;
// Open file
sprintf(szFilename, "frame%d.ppm", iFrame);
pFile=fopen(szFilename, "wb");
if(pFile==NULL)
return;
// Write header
fprintf(pFile, "P6\n%d %d\n255\n", width, height);
// Write pixel data
for(y=0; ydata[0]+y*pFrame->linesize[0], 1, width*3, pFile);
// Close file
fclose(pFile);
}
int main(int argc, char *argv[]) {
AVFormatContext *pFormatCtx;
int i, videoStream;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
AVFrame *pFrame;
AVFrame *pFrameRGB;
AVPacket packet;
int frameFinished;
int numBytes;
uint8_t *buffer;
if(argc < 2) {
printf("Please provide a movie file\n");
return -1;
}
// Register all formats and codecs
av_register_all();
// Open video file
if(av_open_input_file(&pFormatCtx, argv[1], NULL, 0, NULL)!=0)
return -1; // Couldn't open file
// Retrieve stream information
if(av_find_stream_info(pFormatCtx)<0)
return -1; // Couldn't find stream information
// Dump information about file onto standard error
dump_format(pFormatCtx, 0, argv[1], 0);
// Find the first video stream
videoStream=-1;
for(i=0; inb_streams; i++)
if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) {
videoStream=i;
break;
}
if(videoStream==-1)
return -1; // Didn't find a video stream
// Get a pointer to the codec context for the video stream
pCodecCtx=pFormatCtx->streams[videoStream]->codec;
// Find the decoder for the video stream
pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL) {
fprintf(stderr, "Unsupported codec!\n");
return -1; // Codec not found
}
// Open codec
if(avcodec_open(pCodecCtx, pCodec)<0)
return -1; // Could not open codec
// Allocate video frame
pFrame=avcodec_alloc_frame();
// Allocate an AVFrame structure
pFrameRGB=avcodec_alloc_frame();
if(pFrameRGB==NULL)
return -1;
// Determine required buffer size and allocate buffer
numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,
pCodecCtx->height);
buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
// Assign appropriate parts of buffer to image planes in pFrameRGB
// Note that pFrameRGB is an AVFrame, but AVFrame is a superset
// of AVPicture
avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
pCodecCtx->width, pCodecCtx->height);
// Read frames and save first five frames to disk
i=0;
while(av_read_frame(pFormatCtx, &packet)>=0) {
// Is this a packet from the video stream?
if(packet.stream_index==videoStream) {
// Decode video frame
avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,
packet.data, packet.size);
// Did we get a video frame?
if(frameFinished) {
// Convert the image from its native format to RGB
img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24,
(AVPicture*)pFrame, pCodecCtx->pix_fmt, pCodecCtx->width,
pCodecCtx->height);
// Save the frame to disk
if(++i<=5)
SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height,
i);
}
}
// Free the packet that was allocated by av_read_frame
av_free_packet(&packet);
}
// Free the RGB image
av_free(buffer);
av_free(pFrameRGB);
// Free the YUV frame
av_free(pFrame);
// Close the codec
avcodec_close(pCodecCtx);
// Close the video file
av_close_input_file(pFormatCtx);
return 0;
}