
Recherche avancée
Médias (2)
-
Valkaama DVD Label
4 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Image
-
Podcasting Legal guide
16 mai 2011, par
Mis à jour : Mai 2011
Langue : English
Type : Texte
Autres articles (22)
-
La sauvegarde automatique de canaux SPIP
1er avril 2010, parDans le cadre de la mise en place d’une plateforme ouverte, il est important pour les hébergeurs de pouvoir disposer de sauvegardes assez régulières pour parer à tout problème éventuel.
Pour réaliser cette tâche on se base sur deux plugins SPIP : Saveauto qui permet une sauvegarde régulière de la base de donnée sous la forme d’un dump mysql (utilisable dans phpmyadmin) mes_fichiers_2 qui permet de réaliser une archive au format zip des données importantes du site (les documents, les éléments (...) -
Script d’installation automatique de MediaSPIP
25 avril 2011, parAfin de palier aux difficultés d’installation dues principalement aux dépendances logicielles coté serveur, un script d’installation "tout en un" en bash a été créé afin de faciliter cette étape sur un serveur doté d’une distribution Linux compatible.
Vous devez bénéficier d’un accès SSH à votre serveur et d’un compte "root" afin de l’utiliser, ce qui permettra d’installer les dépendances. Contactez votre hébergeur si vous ne disposez pas de cela.
La documentation de l’utilisation du script d’installation (...) -
Automated installation script of MediaSPIP
25 avril 2011, parTo overcome the difficulties mainly due to the installation of server side software dependencies, an "all-in-one" installation script written in bash was created to facilitate this step on a server with a compatible Linux distribution.
You must have access to your server via SSH and a root account to use it, which will install the dependencies. Contact your provider if you do not have that.
The documentation of the use of this installation script is available here.
The code of this (...)
Sur d’autres sites (3581)
-
FFmpeg : undefined references to av_frame_alloc()
6 août 2014, par dontrythisathomeI want to get into FFmpeg developing and i started following these samples tutorial here : here
I started with the first tutorial - tutorial01.c - but i run into this problem ’undefined references to av_frame_alloc()’.
I’m on Ubuntu 12.04 LTS.
This is my program :
/*
* File: main.c
* Author: dontrythisathome
*
* Created on 3 giugno 2014, 23.02
*/
#include
#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>frame.h>
#include <libswscale></libswscale>swscale.h>
/*
*
*/
void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame)
{
FILE *pFile;
char szFilename[32];
int y;
//Apre il file
sprintf(szFilename, "frame%d.ppm", iFrame);
pFile=fopen(szFilename, "wb");
if(pFile==NULL)
{return; }
//Scrive l'intestazione del file ( Larghezza x Altezza su video)
fprintf(pFile, "P6\n%d %d\n255\n", width, height);
//Scrive i data pixel
for(y=0; ydata[0]+y*pFrame->linesize[0], 1, width*3, pFile);
}
//Chiude il file
fclose(pFile);
}
/*
*
*/
/*Main Function*/
int main(int argc, char *argv[])
{
AVFormatContext *pFormatCtx;
int i, videoStreamIdx;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
AVFrame *pFrame;
AVFrame *pFrameRGB;
AVPacket packet;
int frameFinished;
int numBytes;
uint8_t *buffer;
static struct SwsContext *img_convert_ctx;
if(argc < 2){
printf("Inserisci un file video\n");
return -1;
}
//Registra tutti i formati e i codec
av_register_all();
//Apre il file video
if(avformat_open_input(&pFormatCtx, argv[1], NULL, NULL) != 0)
{return -1;} //Impossibile aprire il file
//Recupera le informazioni dello stream
if(avformat_find_stream_info(pFormatCtx, NULL) < 0)
{return -1;} // Couldn't find stream information
//Versa le informazioni del file sullo standard error
av_dump_format(pFormatCtx, 0, argv[1], 0);
//Trova il primo stream video
videoStreamIdx=-1;
for(i=0; inb_streams; i++)
{
if(pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{ videoStreamIdx=i;
break;}
}
if(videoStreamIdx==-1)
return -1; // Impossibile trovare lo stream video
// Punta al contenuto del codec per lo stream video
pCodecCtx = pFormatCtx->streams[videoStreamIdx]->codec;
// Trova il decoder per lo stream video
pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL)
{
fprintf(stderr, "Codec Non Supportato!\n");
return -1; //Impossibile trovare il codec
}
//Apre il codec
if(avcodec_open2(pCodecCtx, pCodec, NULL) < 0)
{return -1;} //Impossibile aprire il codec
//Alloca il frame video
pFrame = av_frame_alloc();
//Alloca una struct AVFrame
pFrameRGB = av_frame_alloc();
if(pFrameRGB==NULL)
{return -1;}
//Determina la grandezza necessaria per il buffer e lo alloca
numBytes = avpicture_get_size(PIX_FMT_RGB24,
pCodecCtx->width,
pCodecCtx->height);
buffer = (uint8_t *) av_malloc(numBytes*sizeof(uint8_t));
//Assegna le parti appropriate del buffer sulla superficie dell'immagine in pFrameRGB
//Tenere presente che pFrameRGB è un AVFrame, ma AVFrame è una superset di AVPicture
avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
int w = pCodecCtx->width;
int h = pCodecCtx->height;
img_convert_ctx = sws_getContext(w, h, pCodecCtx->pix_fmt,
w, h, PIX_FMT_RGB24,
SWS_LANCZOS, NULL, NULL, NULL);
//Legge i frame e salva i primi 5 frame su disco
i=0;
while((av_read_frame(pFormatCtx, &packet)>=0) && (i<5))
{
//Questo è il packet dello stream video?
if(packet.stream_index==videoStreamIdx)
{
//Decodifica il frame video
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
//Si è riusiciti ad ottenere il frame video?
if(frameFinished)
{
i++;
sws_scale(img_convert_ctx, (const uint8_t * const *)pFrame->data,
pFrame->linesize, 0, pCodecCtx->height,
pFrameRGB->data, pFrameRGB->linesize);
SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, i);
}
}
//Libera il pacchetto che era allocato da av_read_frame
av_free_packet(&packet);
}
//Libera l'immagine RGB
av_free(buffer);
av_free(pFrameRGB);
//Libera il frame YUV
av_free(pFrame);
//Chiude il codec
avcodec_close(pCodecCtx);
//Chiude il file video
avformat_close_input(&pFormatCtx);
/*FINE PROGRAMMA*/
return 0;
}This is the build output :
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: ingresso nella directory "/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid"
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/simplemediaplayerforandroid
make[2]: ingresso nella directory "/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid"
mkdir -p dist/Debug/GNU-Linux-x86
gcc -o dist/Debug/GNU-Linux-x86/simplemediaplayerforandroid build/Debug/GNU-Linux-x86/main.o -L/usr/lib/x86_64-linux-gnu -lavformat -lavcodec -lavutil -lswscale -lz -lbz2
build/Debug/GNU-Linux-x86/main.o: In function `main':
/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid/main.c:105: undefined reference to `av_frame_alloc'
/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid/main.c:108: undefined reference to `av_frame_alloc'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/simplemediaplayerforandroid] Errore 1
make[2]: uscita dalla directory "/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid"
make[1]: *** [.build-conf] Errore 2
make[1]: uscita dalla directory "/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid"
make: *** [.build-impl] Errore 2
BUILD FAILED (exit value 2, total time: 143ms)I also linked the correct library path and headers path because there is no error with that.
But when i try to build the program from the terminal with these commands :
gcc -o prog1 /home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid/main.c -lavformat -lavcodec -lavutil -lswscale -lz -lbz2
And the output is different :
/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid/main.c:11:29: fatal error: libavutil/frame.h: File o directory non esistente
compilation terminated.The output says that there is no file or directory existing.
What is the problem ? -
Problem opening xvid264 with avcodec_alloc_context(NULL)
12 juillet 2024, par user3763774I want to multiplex audio and video together using the ffmpeg encoding library with xvid264rgb codec. I can open the codec when I create the context specifying that codec, but not if I use NULL for the argument with allocate context. My understanding is I need to use NULL so I can open the audio codec as well.


In the example, the first open works with codec indicated in the allocate context. The second doesn't.


#include 
#include 
#include 
#include <libavcodec></libavcodec>avcodec.h>
#include <libavutil></libavutil>opt.h>
#define WIDTH 400
#define HEIGHT 300

const AVCodec *videocodec;

bool init_video_encoder(AVCodecContext *c, int width, int height) {
 int ret;
 
 const AVRational tb_rat = {1, 30};
 const AVRational fr_rat = {30, 1};

 fprintf(stderr, "init video encoder\n");
 // video
 //fprintf(stderr, "speed= %d \n", videocodec->speed);
 c->bit_rate = 400000;
 c->width = width;
 c->height = height;
 c->time_base = tb_rat;
 c->framerate = fr_rat;
 c->gop_size = 10;
 c->max_b_frames = 1;
 c->pix_fmt = AV_PIX_FMT_RGB24;
 if( videocodec->id == AV_CODEC_ID_H264 ) 
 av_opt_set(c->priv_data, "preset", "slow", 0);
 
 ret = avcodec_open2(c, videocodec, NULL);
 if( ret < 0 ) {
 fprintf(stderr, "failure to open codec: %s\n", av_err2str(ret));
 return false;
 }
 //avcodec_free_context(&c);
 return true;
}

int main(int argc, char **argv) {

 AVCodecContext *context = NULL;

 videocodec = avcodec_find_encoder_by_name("libx264rgb");
 if( videocodec == NULL ) {
 fprintf(stderr, "video encoder 'libx264rgb' not found");
 exit;
 }

 context = avcodec_alloc_context3(videocodec);
 if( context == NULL ) {
 fprintf(stderr, "could not allocate context with codec");
 return false;
 }
 if( init_video_encoder( context, WIDTH, HEIGHT ) ) 
 fprintf(stderr, " success initializing video encoder case one\n");
 else
 fprintf(stderr, " failure to initialize video encoder case one\n");
 avcodec_close( context );

 context = avcodec_alloc_context3(NULL);
 if( context == NULL ) {
 fprintf(stderr, "could not allocate context without codec");
 return false;
 }
 if( init_video_encoder( context, WIDTH, HEIGHT ) ) 
 fprintf(stderr, " success initializing video encoder case two\n");
 else
 fprintf(stderr, " failure to initialize video encoder case two\n");
 avcodec_close( context );
}



Here is the error message :


broken ffmpeg default settings detected
use an encoding preset (e.g. -vpre medium)
preset usage: -vpre <speed> -vpre <profile>
speed presets are listed in x264 --help
profile is optional; x264 defaults to high
failure to open codec: Generic error in an external library
failure to initialize video encoder case two
</profile></speed>


Is this the right approach to use ? How do I set the encoding preset ? The code appears already to do that.


-
Transcoding Videos Using FastAPI and ffmpeg
15 janvier 2024, par Sanji VinsmokeI created an API using Fast API where I upload one or more videos, may specify the resolution of transcoding, and the output is transcoded video from 240p upto the resolution I specified. Available resolutions are - 240p, 360p, 480p, 720p, 1080p. I used ffmpeg for the transcoding job.


The problem that is bugging me since yesterday is that, after deploying to the s3 bucket and adding the url for the index.m3u8 file in any hls player, the video is blank. Only the audio and streaming are working. I have tried tweaking with the parameters in the ffmpeg parameters, the error is still there. I tried manually transcoding a video file locally, even that video's index.m3u8 file is blank in live version. I added the relevant codes for this project. I implemented each feature one by one, but I simply cannot find the reason why the video is totally blank on live.


def transcode_video(input_path, output_folder, res, video_id, video_resolution, progress_bar=None):
 # Transcode the video into .m3u8 format with segment format
 output_path = os.path.join(output_folder, f"{res}_{video_id}.m3u8")

 # Use subprocess for command execution
 chunk_size = 1 # Specify the desired chunk size in seconds

 transcode_command = [
 "ffmpeg", "-i", input_path, "-vf", f"scale={res}:'trunc(ow/a/2)*2'", "-c:a", "aac", "-strict", "-2",
 "-f", "segment", "-segment_time", str(chunk_size), "-segment_list", output_path, "-segment_format", "ts",
 f"{output_path.replace('.m3u8', '_%03d.ts')}"
 ]

 try:
 subprocess.run(transcode_command, check=True, capture_output=True)
 except subprocess.CalledProcessError as e:
 print(f"Error during transcoding: {e}")
 print(f"FFmpeg error output: {e.stderr}")
 # Continue with the next video even if an error occurs
 return False

 # Update the progress bar
 if progress_bar:
 progress_bar.update(1)
 return True


def get_bandwidth(resolution):
 # Define a simple function to calculate bandwidth based on resolution
 resolutions_and_bandwidths = {
 240: 400000,
 360: 850000,
 480: 1400000,
 720: 2500000,
 1080: 4500000,
 }
 
 return resolutions_and_bandwidths.get(resolution, 0)
def create_index_m3u8(video_id, resolutions_to_transcode):
 # Write the index.m3u8 file
 index_m3u8_path = os.path.join(OUTPUT_FOLDER, f"index_{video_id}.m3u8")
 with open(index_m3u8_path, "w") as index_file:
 index_file.write("#EXTM3U\n")
 index_file.write("#EXT-X-VERSION:3\n")

 for res in resolutions_to_transcode:
 aspect_ratio = 16 / 9
 folder_name = f"{res}p_{video_id}"
 resolution_file_name = f"{res}_{video_id}.m3u8"
 index_file.write(
 f"#EXT-X-STREAM-INF:BANDWIDTH={get_bandwidth(res)},RESOLUTION={int(res * aspect_ratio)}x{res}\n{folder_name}/{resolution_file_name}\n"
 )



I tried reducing or increasing chunk size, adding codecs, setting up dimensions. Where am I doing wrong ?


My python version is 3.8.18, ffmpeg version-4.4.4, ffmpeg-python version-0.2.0