
Recherche avancée
Autres articles (69)
-
Gestion générale des documents
13 mai 2011, parMédiaSPIP ne modifie jamais le document original mis en ligne.
Pour chaque document mis en ligne il effectue deux opérations successives : la création d’une version supplémentaire qui peut être facilement consultée en ligne tout en laissant l’original téléchargeable dans le cas où le document original ne peut être lu dans un navigateur Internet ; la récupération des métadonnées du document original pour illustrer textuellement le fichier ;
Les tableaux ci-dessous expliquent ce que peut faire MédiaSPIP (...) -
Use, discuss, criticize
13 avril 2011, parTalk to people directly involved in MediaSPIP’s development, or to people around you who could use MediaSPIP to share, enhance or develop their creative projects.
The bigger the community, the more MediaSPIP’s potential will be explored and the faster the software will evolve.
A discussion list is available for all exchanges between users. -
MediaSPIP Player : les contrôles
26 mai 2010, parLes contrôles à la souris du lecteur
En plus des actions au click sur les boutons visibles de l’interface du lecteur, il est également possible d’effectuer d’autres actions grâce à la souris : Click : en cliquant sur la vidéo ou sur le logo du son, celui ci se mettra en lecture ou en pause en fonction de son état actuel ; Molette (roulement) : en plaçant la souris sur l’espace utilisé par le média (hover), la molette de la souris n’exerce plus l’effet habituel de scroll de la page, mais diminue ou (...)
Sur d’autres sites (10019)
-
ffmeg mux video and audio into a mp4 file, no sound in quicktime player
10 novembre 2014, par user2789801I’m using ffmpeg to mux a video file and a audio file into a single mp4 file.The mp4 file plays fine on windows, but it has no sound in quicktime player on mac. And I get a error message "2041 invalid sample description".
Here’s what I’m doing,
First, I open the video file and the audio file, init a output frame context.
Then I add a video stream and a audio stream according to the video and audio files.
Then write the header, then start muxing, then write the trailer.Here’s my code
#include "CoreRender.h"
CoreRender::CoreRender(const char* _vp, const char * _ap, const char * _op)
{
sprintf(videoPath, "%s", _vp);
sprintf(audioPath, "%s", _ap);
sprintf(outputPath, "%s", _op);
formatContext_video = NULL;
formatContext_audio = NULL;
formatContext_output = NULL;
videoStreamIdx = -1;
outputVideoStreamIdx = -1;
videoStreamIdx = -1;
audioStreamIdx = -1;
outputVideoStreamIdx = -1;
outputAudioStreamIdx = -1;
av_init_packet(&pkt);
init();
}
void CoreRender::init()
{
av_register_all();
avcodec_register_all();
// allocate a memory for the AVFrame object
frame = (AVFrame *)av_mallocz(sizeof(AVFrame));
rgbFrame = (AVFrame *)av_mallocz(sizeof(AVFrame));
if (avformat_open_input(&formatContext_video, videoPath, 0, 0) < 0)
{
release();
}
if (avformat_find_stream_info(formatContext_video, 0) < 0)
{
release();
}
if (avformat_open_input(&formatContext_audio, audioPath, 0, 0) < 0)
{
release();
}
if (avformat_find_stream_info(formatContext_audio, 0) < 0)
{
release();
}
avformat_alloc_output_context2(&formatContext_output, NULL, NULL, outputPath);
if (!formatContext_output)
{
release();
}
ouputFormat = formatContext_output->oformat;
for (int i = 0; i < formatContext_video->nb_streams; i++)
{
// create the output AVStream according to the input AVStream
if (formatContext_video->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
videoStreamIdx = i;
AVStream * in_stream = formatContext_video->streams[i];
AVStream * out_stream = avformat_new_stream(formatContext_output, in_stream->codec->codec);
if (! out_stream)
{
release();
}
outputVideoStreamIdx = out_stream->index;
if (avcodec_copy_context(out_stream->codec, in_stream->codec) < 0)
{
release();
}
out_stream->codec->codec_tag = 0;
if (formatContext_output->oformat->flags & AVFMT_GLOBALHEADER)
{
out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
break;
}
}
for (int i = 0; i < formatContext_audio->nb_streams; i++)
{
if (formatContext_audio->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
{
AVCodec *encoder;
encoder = avcodec_find_encoder(AV_CODEC_ID_AAC);
audioStreamIdx = i;
AVStream *in_stream = formatContext_audio->streams[i];
AVStream *out_stream = avformat_new_stream(formatContext_output, encoder);
if (!out_stream)
{
release();
}
outputAudioStreamIdx = out_stream->index;
AVCodecContext *dec_ctx, *enc_ctx;
dec_ctx = in_stream->codec;
enc_ctx = out_stream->codec;
enc_ctx->sample_rate = dec_ctx->sample_rate;
enc_ctx->channel_layout = dec_ctx->channel_layout;
enc_ctx->channels = av_get_channel_layout_nb_channels(enc_ctx->channel_layout);
enc_ctx->time_base = { 1, enc_ctx->sample_rate };
enc_ctx->bit_rate = 480000;
if (avcodec_open2(enc_ctx, encoder, NULL) < 0)
{
release();
}
if (formatContext_output->oformat->flags & AVFMT_GLOBALHEADER)
{
out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
break;
}
}
if (!(ouputFormat->flags & AVFMT_NOFILE))
{
if (avio_open(&formatContext_output->pb, outputPath, AVIO_FLAG_WRITE) < 0)
{
release();
}
}
if (avformat_write_header(formatContext_output, NULL) < 0)
{
release();
}
}
void CoreRender::mux()
{
// find the decoder for the audio codec
codecContext_a = formatContext_audio->streams[audioStreamIdx]->codec;
codec_a = avcodec_find_decoder(codecContext_a->codec_id);
if (codec == NULL)
{
avformat_close_input(&formatContext_audio);
release();
}
codecContext_a = avcodec_alloc_context3(codec_a);
if (codec_a->capabilities&CODEC_CAP_TRUNCATED)
codecContext_a->flags |= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */
if (avcodec_open2(codecContext_a, codec_a, NULL) < 0)
{
avformat_close_input(&formatContext_audio);
release();
}
int frame_index = 0;
int64_t cur_pts_v = 0, cur_pts_a = 0;
while (true)
{
AVFormatContext *ifmt_ctx;
int stream_index = 0;
AVStream *in_stream, *out_stream;
if (av_compare_ts(cur_pts_v,
formatContext_video->streams[videoStreamIdx]->time_base,
cur_pts_a,
formatContext_audio->streams[audioStreamIdx]->time_base) <= 0)
{
ifmt_ctx = formatContext_video;
stream_index = outputVideoStreamIdx;
if (av_read_frame(ifmt_ctx, &pkt) >=0)
{
do
{
if (pkt.stream_index == videoStreamIdx)
{
cur_pts_v = pkt.pts;
break;
}
} while (av_read_frame(ifmt_ctx, &pkt) >= 0);
}
else
{
break;
}
}
else
{
ifmt_ctx = formatContext_audio;
stream_index = outputAudioStreamIdx;
if (av_read_frame(ifmt_ctx, &pkt) >=0)
{
do
{
if (pkt.stream_index == audioStreamIdx)
{
cur_pts_a = pkt.pts;
break;
}
} while (av_read_frame(ifmt_ctx, &pkt) >=0);
processAudio();
}
else
{
break;
}
}
in_stream = ifmt_ctx->streams[pkt.stream_index];
out_stream = formatContext_output->streams[stream_index];
if (pkt.pts == AV_NOPTS_VALUE)
{
AVRational time_base1 = in_stream->time_base;
int64_t calc_duration = (double)AV_TIME_BASE / av_q2d(in_stream->r_frame_rate);
pkt.pts = (double)(frame_index * calc_duration) / (double)(av_q2d(time_base1) * AV_TIME_BASE);
pkt.dts = pkt.pts;
pkt.duration = (double)calc_duration / (double)(av_q2d(time_base1) * AV_TIME_BASE);
frame_index++;
}
pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, out_stream->time_base, (enum AVRounding) (AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX));
pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, out_stream->time_base, (enum AVRounding) (AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX));
pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base, out_stream->time_base);
pkt.pos = -1;
pkt.stream_index = stream_index;
LOGE("Write 1 Packet. size:%5d\tpts:%8d", pkt.size, pkt.pts);
if (av_interleaved_write_frame(formatContext_output, &pkt) < 0)
{
break;
}
av_free_packet(&pkt);
}
av_write_trailer(formatContext_output);
}
void CoreRender::processAudio()
{
int got_frame_v = 0;
AVFrame *tempFrame = (AVFrame *)av_mallocz(sizeof(AVFrame));
avcodec_decode_audio4(formatContext_audio->streams[audioStreamIdx]->codec, tempFrame, &got_frame_v, &pkt);
if (got_frame_v)
{
tempFrame->pts = av_frame_get_best_effort_timestamp(tempFrame);
int ret;
int got_frame_local;
int * got_frame = &got_frame_v;
AVPacket enc_pkt;
int(*enc_func)(AVCodecContext *, AVPacket *, const AVFrame *, int *) = avcodec_encode_audio2;
if (!got_frame)
{
got_frame = &got_frame_local;
}
// encode filtered frame
enc_pkt.data = NULL;
enc_pkt.size = 0;
av_init_packet(&enc_pkt);
ret = enc_func(codecContext_a, &enc_pkt, tempFrame, got_frame);
av_frame_free(&tempFrame);
av_frame_free(&tempFrame);
if (ret < 0)
{
return ;
}
if (!(*got_frame))
{
return ;
}
enc_pkt.stream_index = outputAudioStreamIdx;
av_packet_rescale_ts(&enc_pkt,
formatContext_output->streams[outputAudioStreamIdx]->codec->time_base,
formatContext_output->streams[outputAudioStreamIdx]->time_base);
}
}
void CoreRender::release()
{
avformat_close_input(&formatContext_video);
avformat_close_input(&formatContext_audio);
if (formatContext_output&& !(ouputFormat->flags & AVFMT_NOFILE))
avio_close(formatContext_output->pb);
avformat_free_context(formatContext_output);
}
CoreRender::~CoreRender()
{
}As you can see, I transcode the audio format into aac, and keep the video as it is.
Here’s how I use itCoreRender render("d:\\bg.mp4", "d:\\music.mp3", "d:\\output.mp4");
render.mux();
return 0;The video file is always in h.264 format.
So what I’m doing wrong ? -
Using FFMPEG to merge video frames back into a video with subtitle messes up the audio when seeking
26 juin 2023, par YoungDONI broke down a h265 video into frames and try to merge them back together with its original audio, subtitle and fonts. The resulting video has an issue where when I try to seek at some points in the video, the audio stops playing. And even when I don't seek, at a point the video hangs and the audio keeps playing. Seconds later, the video resumes, but now, video and audio are out of sync. This doesn't happen with the original video.


The reason I'm breaking the video into frames and merging them is because I want to upscale each frame. But I'm going to leave that part out because this issue occurs with the original unscaled frames.


Here's the details of the original video. Notice it has video, audio and two font streams.


.\ffmpeg.exe -i "input.mkv"

Input #0, matroska,webm, from 'input.mkv':
 Metadata:
 encoder : libebml v1.3.10 + libmatroska v1.5.2
 creation_time : 2021-01-07T00:20:19.000000Z
 Duration: 00:23:02.05, start: 0.000000, bitrate: 320 kb/s
 Stream #0:0: Video: hevc (Main), yuv420p(tv), 1280x720, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default)
 Metadata:
 BPS-eng : 278671
 DURATION-eng : 00:23:02.006000000
 NUMBER_OF_FRAMES-eng: 33135
 NUMBER_OF_BYTES-eng: 48140731
 _STATISTICS_WRITING_APP-eng: mkvmerge v46.0.0 ('No Deeper Escape') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2021-01-07 00:20:19
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
 Stream #0:1(jpn): Audio: aac (HE-AAC), 48000 Hz, stereo, fltp
 Metadata:
 BPS-eng : 36166
 DURATION-eng : 00:23:02.016000000
 NUMBER_OF_FRAMES-eng: 32391
 NUMBER_OF_BYTES-eng: 6247833
 _STATISTICS_WRITING_APP-eng: mkvmerge v46.0.0 ('No Deeper Escape') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2021-01-07 00:20:19
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
 Stream #0:2(eng): Subtitle: ass (default)
 Metadata:
 BPS-eng : 76
 DURATION-eng : 00:21:20.790000000
 NUMBER_OF_FRAMES-eng: 246
 NUMBER_OF_BYTES-eng: 12264
 _STATISTICS_WRITING_APP-eng: mkvmerge v46.0.0 ('No Deeper Escape') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2021-01-07 00:20:19
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
 Stream #0:3: Attachment: ttf
 Metadata:
 filename : Roboto-Medium.ttf
 mimetype : application/x-truetype-font
 Stream #0:4: Attachment: ttf
 Metadata:
 filename : Roboto-MediumItalic.ttf
 mimetype : application/x-truetype-font



Here's how I break it into frames


.\ffmpeg.exe -i "input.mkv" -qscale:v 1 -qmin 1 -qmax 1 -vsync 0 "InputFolder/frame%08d.png"



Here's how I merge the frames back to video with all the original streams except the video


.\ffmpeg.exe -r 23.98 -i "InputFolder\frame%08d.png" -i "input.mkv" -map 0:v:0 -map 1 -map -1:v -c:a copy -c:v libx265 -r 23.98 -pix_fmt yuv420p "output.mkv"



Here's the details of the resulting video :


.\ffmpeg.exe -i "output.mkv"

Input #0, matroska,webm, from 'output.mkv':
 Metadata:
 ENCODER : Lavf58.45.100
 Duration: 00:23:02.05, start: 0.000000, bitrate: 245 kb/s
 Stream #0:0: Video: hevc (Main), yuv420p(tv), 1280x720 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default)
 Metadata:
 ENCODER : Lavc58.91.100 libx265
 DURATION : 00:23:01.777000000
 Stream #0:1(jpn): Audio: aac (HE-AAC), 48000 Hz, stereo, fltp (default)
 Metadata:
 BPS-eng : 36166
 DURATION-eng : 00:23:02.016000000
 NUMBER_OF_FRAMES-eng: 32391
 NUMBER_OF_BYTES-eng: 6247833
 _STATISTICS_WRITING_APP-eng: mkvmerge v46.0.0 ('No Deeper Escape') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2021-01-07 00:20:19
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
 DURATION : 00:23:02.046000000
 Stream #0:2(eng): Subtitle: ass (default)
 Metadata:
 BPS-eng : 76
 DURATION-eng : 00:21:20.790000000
 NUMBER_OF_FRAMES-eng: 246
 NUMBER_OF_BYTES-eng: 12264
 _STATISTICS_WRITING_APP-eng: mkvmerge v46.0.0 ('No Deeper Escape') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2021-01-07 00:20:19
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
 ENCODER : Lavc58.91.100 ssa
 DURATION : 00:21:21.580000000
 Stream #0:3: Attachment: ttf
 Metadata:
 filename : Roboto-Medium.ttf
 mimetype : application/x-truetype-font
 Stream #0:4: Attachment: ttf
 Metadata:
 filename : Roboto-MediumItalic.ttf
 mimetype : application/x-truetype-font



One thing to note is that I've done this successfully numerous times with h264 videos. No audio issues. Another thing to note which might be more relevant is that when I merge the frames with only the original audio stream (as opposed to all original streams except video), the audio issue does not occur.


.\ffmpeg.exe -r 23.98 -i "InputFolder\frame%08d.png" -i "input.mkv" -map 0:v:0 -map 1:a:0 -c:a copy -c:v libx265 -r 23.98 -pix_fmt yuv420p "output.mkv"

Produces no audio issues. But this isn't good for me because I want the subtitles and fonts from the original video.



If anyone needs me to upload the original video somewhere so they can reproduce it, let me know.


Edit : Also note that Merging the frames with the original audio AND subtitle stream, i.e without the fonts, the issue remains.


-
Using PyAV to encode mono audio to file, params match docs, but still causes Errno 22
20 février 2023, par andrew8088While trying to use PyAV to encode live mono audio from a microphone to a compressed audio stream (using mp2 or flac as encoder), the program kept raising an exception
ValueError: [Errno 22] Invalid argument
.

To remove the live microphone source as a cause of the problem, and to make the problematic code easier for others to run/test, I have removed the mic source and now just generate a pure tone as a sequence of input buffers.


All attempts to figure out the missing or mismatched or incorrect argument have just resulted in seeing documentation and examples that are the same as my code.


I would like to know from someone who has used PyAV successfully for mono audio what the correct method and parameters are for encoding mono frames into the mono stream.


The package used is av 10.0.0 installed with

pip3 install av --no-binary av

so it uses my package-manager provided ffmpeg library, which is version 4.2.7.

The problematic python code is :


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Recreating an error 22 when encoding sound with PyAV.

Created on Sun Feb 19 08:10:29 2023
@author: andrewm
"""
import typing
import sys
import math
import fractions

import av
from av import AudioFrame

""" Ensure some PyAudio constants are still defined without changing 
 the PyAudio recording callback function and without depending 
 on PyAudio simply for reproducing the PyAV bug [Errno 22] thrown in 
 File "av/filter/context.pyx", line 89, in av.filter.context.FilterContext.push
"""
class PA_Stub():
 paContinue = True
 paComplete= False

pyaudio = PA_Stub()


"""Generate pure tone at given frequency with amplitude 0...1.0 at 
 sampling frewuency fs and beginning at phase offset 'phase'.
 Returns the new phase after the sinusoid has cycled over the 
 sampling window length.
"""
def generate_tone(
 freq:int, phase:float, amp:float, fs, samp_fmt, buffer:bytearray
) -> float:
 assert samp_fmt == "s16", "Only s16 supported atm"
 samp_size_bytes = 2
 n_samples = int(len(buffer)/samp_size_bytes)
 window = [int(0) for i in range(n_samples)]
 theta = phase
 phase_inc = 2*math.pi * freq / fs
 for i in range(n_samples):
 v = amp * math.sin(theta)
 theta += phase_inc
 s = int((2**15-1)*v)
 window[i] = s
 for sample_i in range(len(window)):
 byte_i = sample_i * samp_size_bytes
 enc = window[sample_i].to_bytes(
 2, byteorder=sys.byteorder, signed=True
 )
 buffer[byte_i] = enc[0]
 buffer[byte_i+1] = enc[1]
 return theta


channels = 1
fs = 44100 # Record at 44100 samples per second
fft_size_samps = 256
chunk_samps = fft_size_samps * 10 # Record in chunks that are multiples of fft windows.

# print(f"fft_size_samps={fft_size_samps}\nchunk_samps={chunk_samps}")

seconds = 3.0
out_filename = "testoutput.wav"

# Store data in chunks for 3 seconds
sample_limit = int(fs * seconds)
sample_len = 0
frames = [] # Initialize array to store frames

ffmpeg_codec_name = 'mp2' # flac, mp3, or libvorbis make same error.

sample_size_bytes = 2
buffer = bytearray(int(chunk_samps*sample_size_bytes))
chunkperiod = chunk_samps / fs
total_chunks = int(math.ceil(seconds / chunkperiod))
phase = 0.0

### uncomment if you want to see the synthetic data being used as a mic input.
# with open("test.raw","wb") as raw_out:
# for ci in range(total_chunks):
# phase = generate_tone(2600, phase, 0.8, fs, "s16", buffer)
# raw_out.write(buffer)
# print("finished gen test")
# sys.exit(0)
# #---- 

# Using mp2 or mkv as the container format gets the same error.
with av.open(out_filename+'.mp2', "w", format="mp2") as output_con:
 output_con.metadata["title"] = "My title"
 output_con.metadata["key"] = "value"
 channel_layout = "mono"
 sample_fmt = "s16p"

 ostream = output_con.add_stream(ffmpeg_codec_name, fs, layout=channel_layout)
 assert ostream is not None, "No stream!"
 cctx = ostream.codec_context
 cctx.sample_rate = fs
 cctx.time_base = fractions.Fraction(numerator=1,denominator=fs)
 cctx.format = sample_fmt
 cctx.channels = channels
 cctx.layout = channel_layout
 print(cctx, f"layout#{cctx.channel_layout}")
 
 # Define PyAudio-style callback for recording plus PyAV transcoding.
 def rec_callback(in_data, frame_count, time_info, status):
 global sample_len
 global ostream
 frames.append(in_data)
 nsamples = int(len(in_data) / (channels*sample_size_bytes))
 
 frame = AudioFrame(format=sample_fmt, layout=channel_layout, samples=nsamples)
 frame.sample_rate = fs
 frame.time_base = fractions.Fraction(numerator=1,denominator=fs)
 frame.pts = sample_len
 frame.planes[0].update(in_data)
 print(frame, len(in_data))
 
 for out_packet in ostream.encode(frame):
 output_con.mux(out_packet)
 for out_packet in ostream.encode(None):
 output_con.mux(out_packet)
 
 sample_len += nsamples
 retflag = pyaudio.paContinue if sample_lencode>


If you uncomment the RAW output part you will find the generated data can be imported as PCM s16 Mono 44100Hz into Audacity and plays the expected tone, so the generated audio data does not seem to be the problem.


The normal program console output up until the exception is :


mp2 at 0x7f8e38202cf0> layout#4
Beginning
 5120
. 5120



The stack trace is :


Traceback (most recent call last):

 File "Dev/multichan_recording/av_encode.py", line 147, in <module>
 ret_data, ret_flag = rec_callback(buffer, ci, {}, 1)

 File "Dev/multichan_recording/av_encode.py", line 121, in rec_callback
 for out_packet in ostream.encode(frame):

 File "av/stream.pyx", line 153, in av.stream.Stream.encode

 File "av/codec/context.pyx", line 484, in av.codec.context.CodecContext.encode

 File "av/audio/codeccontext.pyx", line 42, in av.audio.codeccontext.AudioCodecContext._prepare_frames_for_encode

 File "av/audio/resampler.pyx", line 101, in av.audio.resampler.AudioResampler.resample

 File "av/filter/graph.pyx", line 211, in av.filter.graph.Graph.push

 File "av/filter/context.pyx", line 89, in av.filter.context.FilterContext.push

 File "av/error.pyx", line 336, in av.error.err_check

ValueError: [Errno 22] Invalid argument

</module>


edit : It's interesting that the error happens on the 2nd AudioFrame, as apparently the first one was encoded okay, because they are given the same attribute values aside from the Presentation Time Stamp (pts), but leaving this out and letting PyAV/ffmpeg generate the PTS by itself does not fix the error, so an incorrect PTS does not seem the cause.


After a brief glance in
av/filter/context.pyx
the exception must come from a bad return value fromres = lib.av_buffersrc_write_frame(self.ptr, frame.ptr)

Trying to dig intoav_buffersrc_write_frame
from the ffmpeg source it is not clear what could be causing this error. The only obvious one is a mismatch between channel layouts, but my code is setting the layout the same in the Stream and the Frame. That problem had been found by an old question pyav - cannot save stream as mono and their answer (that one parameter required is undocumented) is the only reason the code now has the layout='mono' argument when making the stream.

The program output shows layout #4 is being used, and from https://github.com/FFmpeg/FFmpeg/blob/release/4.2/libavutil/channel_layout.h you can see this is the value for symbol AV_CH_FRONT_CENTER which is the only channel in the MONO layout.


The mismatch is surely some other object property or an undocumented parameter requirement.


How do you encode mono audio to a compressed stream with PyAV ?