
Recherche avancée
Médias (91)
-
Géodiversité
9 septembre 2011, par ,
Mis à jour : Août 2018
Langue : français
Type : Texte
-
USGS Real-time Earthquakes
8 septembre 2011, par
Mis à jour : Septembre 2011
Langue : français
Type : Texte
-
SWFUpload Process
6 septembre 2011, par
Mis à jour : Septembre 2011
Langue : français
Type : Texte
-
La conservation du net art au musée. Les stratégies à l’œuvre
26 mai 2011
Mis à jour : Juillet 2013
Langue : français
Type : Texte
-
Podcasting Legal guide
16 mai 2011, par
Mis à jour : Mai 2011
Langue : English
Type : Texte
-
Creativecommons informational flyer
16 mai 2011, par
Mis à jour : Juillet 2013
Langue : English
Type : Texte
Autres articles (88)
-
List of compatible distributions
26 avril 2011, parThe table below is the list of Linux distributions compatible with the automated installation script of MediaSPIP. Distribution nameVersion nameVersion number Debian Squeeze 6.x.x Debian Weezy 7.x.x Debian Jessie 8.x.x Ubuntu The Precise Pangolin 12.04 LTS Ubuntu The Trusty Tahr 14.04
If you want to help us improve this list, you can provide us access to a machine whose distribution is not mentioned above or send the necessary fixes to add (...) -
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 (...) -
Librairies et logiciels spécifiques aux médias
10 décembre 2010, parPour un fonctionnement correct et optimal, plusieurs choses sont à prendre en considération.
Il est important, après avoir installé apache2, mysql et php5, d’installer d’autres logiciels nécessaires dont les installations sont décrites dans les liens afférants. Un ensemble de librairies multimedias (x264, libtheora, libvpx) utilisées pour l’encodage et le décodage des vidéos et sons afin de supporter le plus grand nombre de fichiers possibles. Cf. : ce tutoriel ; FFMpeg avec le maximum de décodeurs et (...)
Sur d’autres sites (7728)
-
FFMPEG - rewarp MPEGDash to MP4 changes audio bitrate mode
30 juin 2022, par Matthieu DucorpsI'm rewrapping some MPEGDash to MP4 wrapper and some files are outputed with variable audio bitrate where others with constant bitrate,and both sources looks exactly the same.


For reference :


I'm using FFMPEG 5.0 for the rewrapping


ffmpeg version 5.0-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
 built with gcc 11.2.0 (Rev5, Built by MSYS2 project)
 configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
 libavutil 57. 17.100 / 57. 17.100
 libavcodec 59. 18.100 / 59. 18.100
 libavformat 59. 16.100 / 59. 16.100
 libavdevice 59. 4.100 / 59. 4.100
 libavfilter 8. 24.100 / 8. 24.100
 libswscale 6. 4.100 / 6. 4.100
 libswresample 4. 3.100 / 4. 3.100
 libpostproc 56. 3.100 / 56. 3.100



And MediaInfo 22.09 to check the medias.




I'm using this command to rewrap the media :


ffmpeg.exe -y -i MPEGDash.mpd -map 0:v -map 0:a -c copy OutFile.mp4



This source MPEGDASH with constant audio bitrate


General
Complete name : \\Constant\PROXY\A0002_30sec\MPEGDash_A0002_30sec.mpd
Format : DASH MPD
File size : 4.14 MiB
Duration : 30 s 80 ms
Overall bit rate mode : Constant
Overall bit rate : 1 154 kb/s

Video
ID : 0-1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L3.1
Format settings : CABAC / 2 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference frames : 2 frames
Format settings, GOP : M=3, N=30
Muxing mode : dash
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 30 s 30 ms
Bit rate mode : Constant
Bit rate : 640 kb/s
Width : 640 pixels
Height : 360 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 29.970 (30000/1001) FPS
Standard : NTSC
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.093
Stream size : 2.28 MiB (55%)
Language : English
Encoded date : UTC 2022-06-30 08:20:16
Tagged date : UTC 2022-06-30 08:20:16
Color range : Limited
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709
Source : V0_360p_640000/V0_360p_640000_init.mp4
Codec configuration box : avcC

Audio #1
ID : 160-1
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Muxing mode : dash
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 128 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 460 KiB (11%)
Language : English
Encoded date : UTC 2022-06-30 08:20:16
Tagged date : UTC 2022-06-30 08:20:16
Source : A0_48000_128000/A0_48000_128000_init.mp4

Audio #2
ID : 161-1
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Muxing mode : dash
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 128 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 460 KiB (11%)
Language : English
Encoded date : UTC 2022-06-30 08:20:16
Tagged date : UTC 2022-06-30 08:20:16
Source : A1_48000_128000/A1_48000_128000_init.mp4

Audio #3
ID : 162-1
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Muxing mode : dash
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 128 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 460 KiB (11%)
Language : English
Encoded date : UTC 2022-06-30 08:20:16
Tagged date : UTC 2022-06-30 08:20:16
Source : A2_48000_128000/A2_48000_128000_init.mp4

Audio #4
ID : 163-1
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Muxing mode : dash
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 128 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 460 KiB (11%)
Language : English
Encoded date : UTC 2022-06-30 08:20:16
Tagged date : UTC 2022-06-30 08:20:16
Source : A3_48000_128000/A3_48000_128000_init.mp4



Has the expected output with constant audio bitrate on the MP4


General
Complete name : \\Constant\PROXY\A0002_30sec\A0002_30sec.mp4
Format : MPEG-4
Format profile : Base Media
Codec ID : isom (isom/iso2/avc1/mp41)
File size : 4.13 MiB
Duration : 30 s 96 ms
Overall bit rate mode : Constant
Overall bit rate : 1 152 kb/s
Movie name : MPEGDash_A0002_30sec.mpd
Writing application : Lavf59.16.100

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L3.1
Format settings : CABAC / 2 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference frames : 2 frames
Format settings, GOP : M=3, N=30
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 30 s 96 ms
Source duration : 29 s 997 ms
Bit rate mode : Constant
Bit rate : 590 kb/s
Nominal bit rate : 640 kb/s
Maximum bit rate : 636 kb/s
Width : 640 pixels
Height : 360 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 29.970 (30000/1001) FPS
Standard : NTSC
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.085
Stream size : 2.12 MiB (51%)
Source stream size : 2.28 MiB (55%)
Color range : Limited
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709
mdhd_Duration : 30030
Codec configuration box : avcC

Audio #1
ID : 2
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 125 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 460 KiB (11%)
Language : English
Default : Yes
Alternate group : 1

Audio #2
ID : 3
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 125 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 460 KiB (11%)
Language : English
Default : Yes
Alternate group : 2

Audio #3
ID : 4
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 125 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 460 KiB (11%)
Language : English
Default : Yes
Alternate group : 3

Audio #4
ID : 5
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 125 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 460 KiB (11%)
Language : English
Default : Yes
Alternate group : 4



But this source MPEGDASH which has the same characteristics :


General
Complete name : \\Variable\PROXY\A0005_30sec\MPEGDash_A0005_30sec.mpd
Format : DASH MPD
File size : 4.15 MiB
Duration : 30 s 80 ms
Overall bit rate mode : Constant
Overall bit rate : 1 157 kb/s

Video
ID : 0-1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L3.1
Format settings : CABAC / 2 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference frames : 2 frames
Format settings, GOP : M=3, N=30
Muxing mode : dash
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 30 s 30 ms
Bit rate mode : Constant
Bit rate : 640 kb/s
Width : 640 pixels
Height : 360 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 29.970 (30000/1001) FPS
Standard : NTSC
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.093
Stream size : 2.29 MiB (55%)
Language : English
Encoded date : UTC 2022-06-30 08:24:03
Tagged date : UTC 2022-06-30 08:24:03
Color range : Limited
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709
Source : V0_360p_640000/V0_360p_640000_init.mp4
Codec configuration box : avcC

Audio #1
ID : 160-1
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Muxing mode : dash
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 128 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 461 KiB (11%)
Language : English
Encoded date : UTC 2022-06-30 08:24:03
Tagged date : UTC 2022-06-30 08:24:03
Source : A0_48000_128000/A0_48000_128000_init.mp4

Audio #2
ID : 161-1
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Muxing mode : dash
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 128 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 460 KiB (11%)
Language : English
Encoded date : UTC 2022-06-30 08:24:03
Tagged date : UTC 2022-06-30 08:24:03
Source : A1_48000_128000/A1_48000_128000_init.mp4

Audio #3
ID : 162-1
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Muxing mode : dash
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 128 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 460 KiB (11%)
Language : English
Encoded date : UTC 2022-06-30 08:24:03
Tagged date : UTC 2022-06-30 08:24:03
Source : A2_48000_128000/A2_48000_128000_init.mp4

Audio #4
ID : 163-1
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Muxing mode : dash
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 128 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 460 KiB (11%)
Language : English
Encoded date : UTC 2022-06-30 08:24:03
Tagged date : UTC 2022-06-30 08:24:03
Source : A3_48000_128000/A3_48000_128000_init.mp4



Has this output where the MP4 have the first audio with variable bitrate


General
Complete name : \\Variable\PROXY\A0005_30sec\A0005_30sec.mp4
Format : MPEG-4
Format profile : Base Media
Codec ID : isom (isom/iso2/avc1/mp41)
File size : 4.14 MiB
Duration : 30 s 96 ms
Overall bit rate mode : Variable
Overall bit rate : 1 155 kb/s
Movie name : MPEGDash_A0005_30sec.mpd
Writing application : Lavf59.16.100

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L3.1
Format settings : CABAC / 2 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference frames : 2 frames
Format settings, GOP : M=3, N=30
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 30 s 96 ms
Source duration : 29 s 997 ms
Bit rate mode : Constant
Bit rate : 593 kb/s
Nominal bit rate : 640 kb/s
Maximum bit rate : 640 kb/s
Width : 640 pixels
Height : 360 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 29.970 (30000/1001) FPS
Standard : NTSC
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.086
Stream size : 2.13 MiB (51%)
Source stream size : 2.29 MiB (55%)
Color range : Limited
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709
mdhd_Duration : 30030
Codec configuration box : avcC

Audio #1
ID : 2
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Variable
Bit rate : 126 kb/s
Maximum bit rate : 128 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 461 KiB (11%)
Language : English
Default : Yes
Alternate group : 1

Audio #2
ID : 3
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 125 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 460 KiB (11%)
Language : English
Default : Yes
Alternate group : 2

Audio #3
ID : 4
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 125 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 460 KiB (11%)
Language : English
Default : Yes
Alternate group : 3

Audio #4
ID : 5
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 30 s 80 ms
Bit rate mode : Constant
Bit rate : 125 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 460 KiB (11%)
Language : English
Default : Yes
Alternate group : 4



Maybe I'm missing something but,I don't see what.


-
FFMPEG : Overlay Capture Time (w/Counter)
27 juin 2022, par AdamKI am using the Shutter Encoder application on Windows to batch convert .MOV files, which provides the option of injecting custom FFMPEG commands for each file. The app natively offers overlay (drawtext) of timecode starting at 00:00:00:00. I also see that it knows and preserves the metadata time for each file as this is included in the commands "-metadata creation_time="2022-06-27T16:00:30.730888500Z"


I would like to have the timecode start at the creation time, and was wondering how I might be able to offset the timecode as such. Or...is there another way of overlaying (drawtext-ing) a time counter, starting at creation time ? I would also like to overlay the creation date as well. Thanks in advance for your advice.


-
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.