
Recherche avancée
Médias (1)
-
SWFUpload Process
6 septembre 2011, par
Mis à jour : Septembre 2011
Langue : français
Type : Texte
Autres articles (39)
-
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 -
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 -
Support de tous types de médias
10 avril 2011Contrairement à beaucoup de logiciels et autres plate-formes modernes de partage de documents, MediaSPIP a l’ambition de gérer un maximum de formats de documents différents qu’ils soient de type : images (png, gif, jpg, bmp et autres...) ; audio (MP3, Ogg, Wav et autres...) ; vidéo (Avi, MP4, Ogv, mpg, mov, wmv et autres...) ; contenu textuel, code ou autres (open office, microsoft office (tableur, présentation), web (html, css), LaTeX, Google Earth) (...)
Sur d’autres sites (6583)
-
How AVCodecContext bitrate, framerate and timebase is used when encoding single frame
28 mars 2023, par CyrusI am trying to learn FFmpeg from examples as there is a tight schedule. The task is to encode a raw YUV image into JPEG format of the given width and height. I have found examples from ffmpeg official website, which turns out to be quite straight-forward. However there are some fields in AVCodecContext that I thought only makes sense when encoding videos(e.g. bitrate, framerate, timebase, gopsize, max_b_frames etc).


I understand on a high level what those values are when it comes to videos, but do I need to care about those when I just want a single image ? Currently for testing, I am just setting them as dummy values and it seems to work. But I want to make sure that I am not making terrible assumptions that will break in the long run.


EDIT :


Here is the code I got. Most of them are copy and paste from examples, with some changes to replace old APIs with newer ones.


#include "thumbnail.h"
#include "libavcodec/avcodec.h"
#include "libavutil/imgutils.h"
#include 
#include 
#include 

void print_averror(int error_code) {
 char err_msg[100] = {0};
 av_strerror(error_code, err_msg, 100);
 printf("Reason: %s\n", err_msg);
}

ffmpeg_status_t save_yuv_as_jpeg(uint8_t* source_buffer, char* output_thumbnail_filename, int thumbnail_width, int thumbnail_height) {
 const AVCodec* mjpeg_codec = avcodec_find_encoder(AV_CODEC_ID_MJPEG);
 if (!mjpeg_codec) {
 printf("Codec for mjpeg cannot be found.\n");
 return FFMPEG_THUMBNAIL_CODEC_NOT_FOUND;
 }

 AVCodecContext* codec_ctx = avcodec_alloc_context3(mjpeg_codec);
 if (!codec_ctx) {
 printf("Codec context cannot be allocated for the given mjpeg codec.\n");
 return FFMPEG_THUMBNAIL_ALLOC_CONTEXT_FAILED;
 }

 AVPacket* pkt = av_packet_alloc();
 if (!pkt) {
 printf("Thumbnail packet cannot be allocated.\n");
 return FFMPEG_THUMBNAIL_ALLOC_PACKET_FAILED;
 }

 AVFrame* frame = av_frame_alloc();
 if (!frame) {
 printf("Thumbnail frame cannot be allocated.\n");
 return FFMPEG_THUMBNAIL_ALLOC_FRAME_FAILED;
 }

 // The part that I don't understand
 codec_ctx->bit_rate = 400000;
 codec_ctx->width = thumbnail_width;
 codec_ctx->height = thumbnail_height;
 codec_ctx->time_base = (AVRational){1, 25};
 codec_ctx->framerate = (AVRational){1, 25};

 codec_ctx->gop_size = 10;
 codec_ctx->max_b_frames = 1;
 codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
 int ret = av_image_fill_arrays(frame->data, frame->linesize, source_buffer, AV_PIX_FMT_YUV420P, thumbnail_width, thumbnail_height, 32);
 if (ret < 0) {
 print_averror(ret);
 printf("Pixel format: yuv420p, width: %d, height: %d\n", thumbnail_width, thumbnail_height);
 return FFMPEG_THUMBNAIL_FILL_FRAME_DATA_FAILED;
 }

 ret = avcodec_send_frame(codec_ctx, frame);
 if (ret < 0) {
 print_averror(ret);
 printf("Failed to send frame to encoder.\n");
 return FFMPEG_THUMBNAIL_FILL_SEND_FRAME_FAILED;
 }

 ret = avcodec_receive_packet(codec_ctx, pkt);
 if (ret < 0) {
 print_averror(ret);
 printf("Failed to receive packet from encoder.\n");
 return FFMPEG_THUMBNAIL_FILL_SEND_FRAME_FAILED;
 }

 // store the thumbnail in output
 int fd = open(output_thumbnail_filename, O_CREAT | O_RDWR);
 write(fd, pkt->data, pkt->size);
 close(fd);

 // freeing allocated structs
 avcodec_free_context(&codec_ctx);
 av_frame_free(&frame);
 av_packet_free(&pkt);
 return FFMPEG_SUCCESS;
}



-
No such file or directory : 'ffprobe' : 'ffprobe'
27 novembre 2023, par Jack McCumberI'm hoping someone can point me in the right direction. I'm currently trying to build a python GUI that plays clips of sounds from a specified file and allows the user to annotate it. All the research I've done has pointed my to using pydub. I'm using the following snippet :


from pydub import AudioSegment
from pydub.playback import play

song = AudioSegment.from_wav("beepboop.mp3")
play(song)



However, I'm currently getting the following error :


Warning (from warnings module):
 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pydub/utils.py", line 170
 warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work

Warning (from warnings module):
 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pydub/utils.py", line 198
 warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)
RuntimeWarning: Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work
Traceback (most recent call last):
 File "/Users/jack/Desktop/code-repo/convert-csv-to-json/cleaner.py", line 7, in <module>
 song = AudioSegment.from_wav("beepboop.mp3")
 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pydub/audio_segment.py", line 808, in from_wav
 return cls.from_file(file, 'wav', parameters=parameters)
 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pydub/audio_segment.py", line 728, in from_file
 info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pydub/utils.py", line 274, in mediainfo_json
 res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
 restore_signals, start_new_session)
 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child
 raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe': 'ffprobe'
</module>


I've downloaded both ffprobe and ffmpeg from the official website, extracted the files, and installed to usr/local/bin based on input I've read in other StackOverflow comments. When I run :


print(os.environ['PATH'])



I get :


/usr/bin:/bin:/usr/sbin:/sbin



Also, MacOSX won't let me manually drag the executable into /usr/bin or /usr/sbin. Nor will it let me copy it into the directory using :


$ sudo cp ffmpeg /usr/bin



When I use :


pip3 install ffprobe-python



I get :


Requirement already satisfied: ffprobe-python in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (1.0.3)



I'll add that when I try and use the "apt install" method, it barks at me and says my version of MacOSX isn't supported.


-
Slowing down 960 fps video with ffmpeg (setpts is not working)
7 novembre 2016, par haridsvI am trying to slow down a video recorded on an Android phone at
960fps
. I found a lot of previous posts and blogs that all basically say the same thing, that you need to change the "presentation timestamp" (pts). I also found the official documentation that is saying the same thing. The command-line basically looks like this :ffmpeg -i input.mp4 -filter:v "setpts=4*PTS" -r 30 -y output.mp4
I copied the video file using Android Filter Transfer and when I use the above command-line, it works to slow it down, but the resulting output is choppy. The output of the
ffmpeg
also indicates that it is duplicating the frames :frame= 687 fps=103 q=-1.0 Lsize= 4454kB time=00:00:22.80 bitrate=1600.1kbits/s dup=515 drop=0 speed=3.42x
Running
ffprobe
on the file shows this :ffprobe version 3.1.1 Copyright (c) 2007-2016 the FFmpeg developers
built with Apple LLVM version 7.3.0 (clang-703.0.31)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.1.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-lda
libavutil 55. 28.100 / 55. 28.100
libavcodec 57. 48.101 / 57. 48.101
libavformat 57. 41.100 / 57. 41.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 47.100 / 6. 47.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 1.100 / 2. 1.100
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'VID_20161030_213810.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2016-10-30 16:08:14
location : +17.3874+078.3395/
location-eng : +17.3874+078.3395/
com.android.version: 6.0.1
com.android.capture.fps: 120.000000
Duration: 00:00:05.73, start: 0.000000, bitrate: 14991 kb/s
Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, 13859 kb/s, SAR 1:1 DAR 16:9, 30 fps, 30 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2016-10-30 16:08:14
handler_name : VideoHandleThis seems to detect that the video is
30 fps
instead of960 fps
, which is probably why it is filling in with duplicate frames instead of using the existing frames.I recording the video on Lenovo Z2 Plus (AKA Zuk Z2). If I playback the video using the built-in player at a slow speed it looks extremely smooth, so the frames are definitely there. Could someone help me figure out the right way ? The file is available here (about 10MB), in case someone would like to try it.
Update : Video playback at slo-mo on the phone recorded with another phone. Notice how smooth and slow the sparks are thrown around, which is impossible if the original video is 30fps.