
Recherche avancée
Médias (91)
-
Spitfire Parade - Crisis
15 mai 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Wired NextMusic
14 mai 2011, par
Mis à jour : Février 2012
Langue : English
Type : Video
-
Video d’abeille en portrait
14 mai 2011, par
Mis à jour : Février 2012
Langue : français
Type : Video
-
Sintel MP4 Surround 5.1 Full
13 mai 2011, par
Mis à jour : Février 2012
Langue : English
Type : Video
-
Carte de Schillerkiez
13 mai 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Texte
-
Publier une image simplement
13 avril 2011, par ,
Mis à jour : Février 2012
Langue : français
Type : Video
Autres articles (88)
-
Amélioration de la version de base
13 septembre 2013Jolie sélection multiple
Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...) -
Menus personnalisés
14 novembre 2010, parMediaSPIP utilise le plugin Menus pour gérer plusieurs menus configurables pour la navigation.
Cela permet de laisser aux administrateurs de canaux la possibilité de configurer finement ces menus.
Menus créés à l’initialisation du site
Par défaut trois menus sont créés automatiquement à l’initialisation du site : Le menu principal ; Identifiant : barrenav ; Ce menu s’insère en général en haut de la page après le bloc d’entête, son identifiant le rend compatible avec les squelettes basés sur Zpip ; (...) -
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
Sur d’autres sites (7923)
-
ffmpeg api alternate transcoding and remuxing for same file
21 juin 2022, par Alexandre NoviusContext


Hello !


I'm currently working on the development of a small library allowing to cut an h.264 video on any frame, but without re-encoding (transcoding) the whole video. The idea is to re-encode only the GOP on which we want to cut, and to rewrite (remux) directly the others GOP.


The avcut project (https://github.com/anyc/avcut) allows to do that, but requires a systematic decoding of each package, and seems to not work with the recent versions of ffmpeg from the tests I could do and from the recent feedbacks in the github issues.


As a beginner, I started from the code examples provided in the ffmpeg documentation, in particular : transcoding.c and remuxing.c.


Problem encountered


The problem I'm having is that I can't get both transcoding and remuxing to work properly at the same time. In particular, depending on the method I use to initialize the AVCodecParameters of the output video stream, transcoding works, or remuxing works :


- 

avcodec_parameters_copy
works well for remuxingavcodec_parameters_from_context
works well for transcoding






In case I choose
avcodec_parameters_from_context
, the transcoded GOP are correctly read by my video player (parole), but the remuxed packets are not read, and ffprobe does not show/detect them.

In case I choose
avcodec_parameters_from_context
, the remuxing GOP are correctly read by my video player, but the transcoding key_frame are bugged (I have the impression that the b-frame and p-frame are ok), andffprobe -i
return an error about the NAL of the key-frames :

[h264 @ 0x55ec8a079300] sps_id 32 out of range
[h264 @ 0x55ec8a079300] Invalid NAL unit size (1677727148 > 735).
[h264 @ 0x55ec8a079300] missing picture in access unit with size 744



I suspect that the problem is related to the extradata of the packets. Through some experiments on the different attributes of the output AVCodecParameters, it seems that it is the
extradata
andextradata_size
attributes that are responsible for the functioning of one method or the other.

Version


ffmpeg development branch retrieved on 2022-05-17 from https://github.com/FFmpeg/FFmpeg.


Compiled with
--enable-libx264 --enable-gpl --enable-decoder=png --enable-encoder=png


Code


My code is written in c++ and is based on two classes : a class defining the parameters and methods on the input file (
InputContexts
) and a class defining them for the output file (OutputContexts
). The code of these two classes is defined in the following files :

- 

- contexts.h
- contexts.cpp






The code normally involved in the problem is the following :


- 

- stream initialization




int OutputContexts::init(const char* out_filename, InputContexts* input_contexts){
 int ret;
 int stream_index = 0;

 avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, out_filename);
 if (!ofmt_ctx) {
 fprintf(stderr, "Could not create output context\n");
 ret = AVERROR_UNKNOWN;
 return ret;
 }

 av_dump_format(ofmt_ctx, 0, out_filename, 1);
 
 encoders.resize(input_contexts->ifmt_ctx->nb_streams, nullptr);
 codecs.resize(input_contexts->ifmt_ctx->nb_streams, nullptr);
 
 // stream mapping
 for (int i = 0; i < input_contexts->ifmt_ctx->nb_streams; i++) {
 AVStream *out_stream;
 AVStream *in_stream = input_contexts->ifmt_ctx->streams[i];
 AVCodecContext* decoder_ctx = input_contexts->decoders[i];
 
 // add new stream to output context
 out_stream = avformat_new_stream(ofmt_ctx, NULL);
 if (!out_stream) {
 fprintf(stderr, "Failed allocating output stream\n");
 ret = AVERROR_UNKNOWN;
 return ret;
 }

 // from avcut blog
 av_dict_copy(&out_stream->metadata, in_stream->metadata, 0);

 out_stream->time_base = in_stream->time_base;

 // encoder
 if (decoder_ctx->codec_type == AVMEDIA_TYPE_VIDEO){
 ret = prepare_encoder_video(i, input_contexts);
 if (ret < 0){
 fprintf(stderr, "Error while preparing encoder for stream #%u\n", i);
 return ret;
 }

 // from avcut
 out_stream->sample_aspect_ratio = in_stream->sample_aspect_ratio;

 // works well for remuxing
 ret = avcodec_parameters_copy(out_stream->codecpar, in_stream->codecpar);
 if (ret < 0) {
 fprintf(stderr, "Failed to copy codec parameters\n");
 return ret;
 }

 // works well for transcoding
 // ret = avcodec_parameters_from_context(out_stream->codecpar, encoders[i]);
 // if (ret < 0) {
 // av_log(NULL, AV_LOG_ERROR, "Failed to copy encoder parameters to output stream #%u\n", i);
 // return ret;
 // }

 } else if (decoder_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
 ...
 } else {
 ...
 }

 // TODO useful ???
 // set current stream position to 0
 // out_stream->codecpar->codec_tag = 0;
 }

 // opening output file in write mode with the ouput context
 if (!(ofmt_ctx->oformat->flags & AVFMT_NOFILE)) {
 ret = avio_open(&ofmt_ctx->pb, out_filename, AVIO_FLAG_WRITE);
 if (ret < 0) {
 fprintf(stderr, "Could not open output file '%s'", out_filename);
 return ret;
 }
 }
 
 // write headers from output context in output file
 ret = avformat_write_header(ofmt_ctx, NULL);
 if (ret < 0) {
 fprintf(stderr, "Error occurred when opening output file\n");
 return ret;
 }

 return ret;
}



- 

- AVCodecContext initialization for encoder




int OutputContexts::prepare_encoder_video(int stream_index, InputContexts* input_contexts){
 int ret;
 const AVCodec* encoder;
 AVCodecContext* decoder_ctx = input_contexts->decoders[stream_index];
 AVCodecContext* encoder_ctx;

 if (video_index >= 0){
 fprintf(stderr, "Impossible to mark stream #%u as video, stream #%u is already registered as video stream.\n", 
 stream_index, video_index);
 return -1; //TODO change this value for correct error code
 }
 video_index = stream_index;

 if(decoder_ctx->codec_id == AV_CODEC_ID_H264){
 encoder = avcodec_find_encoder_by_name("libx264");
 if (!encoder) {
 av_log(NULL, AV_LOG_FATAL, "Encoder libx264 not found\n");
 return AVERROR_INVALIDDATA;
 }
 fmt::print("Encoder libx264 will be used for stream {}.\n", stream_index);
 } else {
 std::string s = fmt::format("No video encoder found for the given codec_id: {}\n", avcodec_get_name(decoder_ctx->codec_id));
 av_log(NULL, AV_LOG_FATAL, s.c_str());
 return AVERROR_INVALIDDATA;
 }
 
 encoder_ctx = avcodec_alloc_context3(encoder);
 if (!encoder_ctx) {
 av_log(NULL, AV_LOG_FATAL, "Failed to allocate the encoder context\n");
 return AVERROR(ENOMEM);
 }

 // from avcut
 encoder_ctx->time_base = decoder_ctx->time_base;
 encoder_ctx->ticks_per_frame = decoder_ctx->ticks_per_frame;
 encoder_ctx->delay = decoder_ctx->delay;
 encoder_ctx->width = decoder_ctx->width;
 encoder_ctx->height = decoder_ctx->height;
 encoder_ctx->pix_fmt = decoder_ctx->pix_fmt;
 encoder_ctx->sample_aspect_ratio = decoder_ctx->sample_aspect_ratio;
 encoder_ctx->color_primaries = decoder_ctx->color_primaries;
 encoder_ctx->color_trc = decoder_ctx->color_trc;
 encoder_ctx->colorspace = decoder_ctx->colorspace;
 encoder_ctx->color_range = decoder_ctx->color_range;
 encoder_ctx->chroma_sample_location = decoder_ctx->chroma_sample_location;
 encoder_ctx->profile = decoder_ctx->profile;
 encoder_ctx->level = decoder_ctx->level;

 encoder_ctx->thread_count = 1; // spawning more threads causes avcodec_close to free threads multiple times
 encoder_ctx->codec_tag = 0;
 
 // correct values ???
 encoder_ctx->qmin = 16;
 encoder_ctx->qmax = 26;
 encoder_ctx->max_qdiff = 4;
 // end from avcut

 // according to avcut, should not be set
 // if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER){
 // encoder_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
 // }

 ret = avcodec_open2(encoder_ctx, encoder, NULL);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot open video encoder for stream #%u\n", stream_index);
 return ret;
 }
 
 codecs[stream_index] = encoder;
 encoders[stream_index] = encoder_ctx;

 return ret;
}



Example


To illustrate my problem, I provide here a test code using the two classes that alternates between transcoding and remuxing at each key-frame encountered in the file using my classes.


- 

- trans_remux.cpp




To compile the code :


g++ -o trans_remux trans_remux.cpp contexts.cpp -D__STDC_CONSTANT_MACROS `pkg-config --libs libavfilter` -lfmt -g



Currently the code is using
avcodec_parameters_copy
(contexts.cpp:333
), so it works well for remuxing. If you want to test the version withavcodec_parameters_from_context
, pls comment from line 333 to 337 incontexts.cpp
and uncomment from line 340 to 344 and recompile.

-
FFMpeg crop a portrait (vertical) video square 1:1
1er avril 2022, par huggerSOLVED... It was a UI issue... Not an FFpeg issue.


I am new to FFMpeg. I am stuck on cropping a portrait video taken from a portrait device square.


I would like my video output to be 1080x1080.


First, I tried this.


FFmpegKit.execute(`-y -i ${media.path} -vf "crop=1080:1080:exact=1" ${path}`)



As I hoped, this worked for photos. (but strangely rotates the photo) - looking into that...


BUT, for videos it does not work. instead it turns the video landscape.


I then tried to add scale :


FFmpegKit.execute(`-y -i ${media.path} -vf "crop=1080:1080:exact=1, scale=1080:1080" ${path}`)



But this left me with the same result.


Here are the console logs for some more information :


LOG Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file:///private/var/mobile/Containers/Data/Application/71E462FC-4824-41FE-B28D-57AF7B6078C3/tmp/ReactNative/329ACC6F-42B6-4B12-A289-889DADE1BC3A.mov':
 LOG Metadata:
 LOG major_brand :
 LOG qt
 LOG 
 LOG minor_version :
 LOG 0
 LOG 
 LOG compatible_brands:
 LOG qt
 LOG 
 LOG creation_time :
 LOG 2022-04-01T03:41:12.000000Z
 LOG 
 LOG Duration:
 LOG 00:00:02.35
 LOG , start:
 LOG 0.000000
 LOG , bitrate:
 LOG 21200 kb/s
 LOG 
 LOG Stream #0:0
 LOG [0x1]
 LOG (und)
 LOG : Video: hevc (hvc1 / 0x31637668), yuv420p(tv, bt709), 1080x1920, 21140 kb/s
 LOG ,
 LOG 59.96 fps,
 LOG 59.94 tbr,
 LOG 600 tbn
 LOG (default)
 LOG 
 LOG Metadata:
 LOG creation_time :
 LOG 2022-04-01T03:41:13.000000Z
 LOG 
 LOG handler_name :
 LOG Core Media Video
 LOG 
 LOG vendor_id :
 LOG [0][0][0][0]
 LOG 
 LOG encoder :
 LOG HEVC
 LOG 
 LOG Stream #0:1
 LOG [0x2]
 LOG (und)
 LOG : Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 61 kb/s
 LOG (default)
 LOG 
 LOG Metadata:
 LOG creation_time :
 LOG 2022-04-01T03:41:13.000000Z
 LOG 
 LOG handler_name :
 LOG Core Media Audio
 LOG 
 LOG vendor_id :
 LOG [0][0][0][0]
 LOG 
 LOG [hevc @ 0x118ce07d0] The "sub_text_format" option is deprecated: Deprecated, does nothing
 LOG [aac @ 0x10d30e190] The "sub_text_format" option is deprecated: Deprecated, does nothing
 LOG Stream mapping:
 LOG Stream #0:0 -> #0:0
 LOG (hevc (native) -> mpeg4 (native))
 LOG 
 LOG Stream #0:1 -> #0:1
 LOG (aac (native) -> aac (native))
 LOG 
 LOG Press [q] to stop, [?] for help
 LOG Output #0, mp4, to '/var/mobile/Containers/Data/Application/71E462FC-4824-41FE-B28D-57AF7B6078C3/Documents/after.mp4':
 LOG Metadata:
 LOG major_brand :
 LOG qt
 LOG 
 LOG minor_version :
 LOG 0
 LOG 
 LOG compatible_brands:
 LOG qt
 LOG 
 LOG encoder :
 LOG Lavf59.10.100
 LOG 
 LOG Stream #0:0
 LOG (und)
 LOG : Video: mpeg4 (mp4v / 0x7634706D), yuv420p(tv, bt709, progressive), 1080x1080, q=2-31, 10000 kb/s
 LOG ,
 LOG 59.94 fps,
 LOG 60k tbn
 LOG (default)
 LOG 
 LOG Metadata:
 LOG creation_time :
 LOG 2022-04-01T03:41:13.000000Z
 LOG 
 LOG handler_name :
 LOG Core Media Video
 LOG 
 LOG vendor_id :
 LOG [0][0][0][0]
 LOG 
 LOG encoder :
 LOG Lavc59.15.102 mpeg4
 LOG 
 LOG Side data:
 LOG 
 LOG cpb:
 LOG bitrate max/min/avg: 0/0/10000000 buffer size: 0
 LOG vbv_delay: N/A
 LOG 
 LOG Stream #0:1
 LOG (und)
 LOG : Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 69 kb/s
 LOG (default)
 LOG 
 LOG Metadata:
 LOG creation_time :
 LOG 2022-04-01T03:41:13.000000Z
 LOG 
 LOG handler_name :
 LOG Core Media Audio
 LOG 
 LOG vendor_id :
 LOG [0][0][0][0]
 LOG 
 LOG encoder :
 LOG Lavc59.15.102 aac
 LOG 
 LOG frame= 1 fps=0.0 q=3.6 size= 0kB time=00:00:01.06 bitrate= 0.3kbits/s speed=9.23x
 LOG frame= 47 fps=0.0 q=2.0 size= 768kB time=00:00:01.85 bitrate=3390.0kbits/s speed=3.01x
 LOG frame= 95 fps= 81 q=2.2 size= 1792kB time=00:00:02.32 bitrate=6313.3kbits/s speed=1.99x
 LOG frame= 129 fps= 77 q=2.5 size= 2560kB time=00:00:02.32 bitrate=9018.9kbits/s speed=1.39x
 LOG frame= 139 fps= 78 q=2.6 Lsize= 2953kB time=00:00:02.38 bitrate=10124.6kbits/s speed=1.34x
 LOG video:2929kB audio:20kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead:
 LOG 0.136336%
 LOG 
 LOG [aac @ 0x112820f50] Qavg: 113.412
 LOG COMPLETED
 LOG {}



This is the result, when i replace

-i {media}
with
-f lavfi -i smptebars=r=60000/1001:s=1080x1920:d=1




ALMOST but not 1:1...


I have not had any luck online trying to find a solution for this so I have decided to post on here.


I hope I can get some guidance here !


Cheers.


-
ffmpeg how to concat and COMPRESS at the same time ? [closed]
17 juin 2022, par Alex NoxConcat command :


ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4



Content of list.txt


file '2022-03-26-1.mp4'

file '2022-03-26-2.mp4'



The following above seems working, but I want to compress files at the same time, so I type :


ffmpeg concat -an -i list.txt -crf 23 -c:v libx264 out.mp4



But it doesn't work ? Why ?