
Recherche avancée
Médias (2)
-
Exemple de boutons d’action pour une collection collaborative
27 février 2013, par
Mis à jour : Mars 2013
Langue : français
Type : Image
-
Exemple de boutons d’action pour une collection personnelle
27 février 2013, par
Mis à jour : Février 2013
Langue : English
Type : Image
Autres articles (60)
-
Mise à jour de la version 0.1 vers 0.2
24 juin 2013, parExplications des différents changements notables lors du passage de la version 0.1 de MediaSPIP à la version 0.3. Quelles sont les nouveautés
Au niveau des dépendances logicielles Utilisation des dernières versions de FFMpeg (>= v1.2.1) ; Installation des dépendances pour Smush ; Installation de MediaInfo et FFprobe pour la récupération des métadonnées ; On n’utilise plus ffmpeg2theora ; On n’installe plus flvtool2 au profit de flvtool++ ; On n’installe plus ffmpeg-php qui n’est plus maintenu au (...) -
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;
-
Ecrire une actualité
21 juin 2013, parPrésentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
Vous pouvez personnaliser le formulaire de création d’une actualité.
Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)
Sur d’autres sites (8772)
-
avcodec/ccaption_dec : do not modify packet data in case of parity error
19 juin 2020, par Paul B Mahol -
Problem using FFmpeg to convert MKV with A/52 B audio (aka E-AC3) to AAC
5 juillet 2020, par nxl4I've got a number of MKV files which are (per VLC) encoded with A/52 B (aka E-AC3) audio codecs. I would like to convert these to AAC, but I'm having trouble doing this with FFmpeg. The command I'm running is :



ffmpeg -hwaccel auto -i original_file.mkv -y -c:v copy -c:a aac output_file.mkv




The command completes without error. However, the generated file has no audio when I play it. FFmpeg's output is as follows :



ffmpeg version 4.2.2-1ubuntu1 Copyright (c) 2000-2019 the FFmpeg developers
 built with gcc 9 (Ubuntu 9.3.0-3ubuntu1)
 configuration: --prefix=/usr --extra-version=1ubuntu1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
 libavutil 56. 31.100 / 56. 31.100
 libavcodec 58. 54.100 / 58. 54.100
 libavformat 58. 29.100 / 58. 29.100
 libavdevice 58. 8.100 / 58. 8.100
 libavfilter 7. 57.100 / 7. 57.100
 libavresample 4. 0. 0 / 4. 0. 0
 libswscale 5. 5.100 / 5. 5.100
 libswresample 3. 5.100 / 3. 5.100
 libpostproc 55. 5.100 / 55. 5.100
Guessed Channel Layout for Input Stream #0.1 : 5.1
Input #0, matroska,webm, from 'input_file.mkv':
 Metadata:
 encoder : libebml v1.3.5 + libmatroska v1.4.8
 creation_time : 2018-05-10T10:21:30.000000Z
 Duration: 00:42:08.15, start: 0.000000, bitrate: 3201 kb/s
 Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
 Metadata:
 BPS-eng : 2559028
 DURATION-eng : 00:42:08.151000000
 NUMBER_OF_FRAMES-eng: 60615
 NUMBER_OF_BYTES-eng: 808701337
 _STATISTICS_WRITING_APP-eng: mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-10 10:21:30
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
 Stream #0:1(eng): Audio: eac3, 48000 Hz, 5.1, fltp (default)
 Metadata:
 BPS-eng : 640000
 DURATION-eng : 00:42:08.096000000
 NUMBER_OF_FRAMES-eng: 79003
 NUMBER_OF_BYTES-eng: 202247680
 _STATISTICS_WRITING_APP-eng: mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-10 10:21:30
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
 Stream #0:2(eng): Subtitle: subrip
 Metadata:
 BPS-eng : 79
 DURATION-eng : 00:41:15.299000000
 NUMBER_OF_FRAMES-eng: 802
 NUMBER_OF_BYTES-eng: 24598
 _STATISTICS_WRITING_APP-eng: mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-10 10:21:30
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
 Stream #0:3(eng): Subtitle: subrip
 Metadata:
 title : SDH
 BPS-eng : 82
 DURATION-eng : 00:41:15.299000000
 NUMBER_OF_FRAMES-eng: 844
 NUMBER_OF_BYTES-eng: 25598
 _STATISTICS_WRITING_APP-eng: mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-10 10:21:30
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream mapping:
 Stream #0:0 -> #0:0 (copy)
 Stream #0:1 -> #0:1 (eac3 (native) -> aac (native))
 Stream #0:2 -> #0:2 (subrip (srt) -> ass (ssa))
Press [q] to stop, [?] for help
[aac @ 0x55d0572a1740] Using a PCE to encode channel layout "5.1(side)"
Output #0, matroska, to 'output_file.mkv':
 Metadata:
 encoder : Lavf58.29.100
 Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 23.98 fps, 23.98 tbr, 1k tbn, 1k tbc (default)
 Metadata:
 BPS-eng : 2559028
 DURATION-eng : 00:42:08.151000000
 NUMBER_OF_FRAMES-eng: 60615
 NUMBER_OF_BYTES-eng: 808701337
 _STATISTICS_WRITING_APP-eng: mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-10 10:21:30
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
 Stream #0:1(eng): Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, 5.1(side), fltp, 394 kb/s (default)
 Metadata:
 BPS-eng : 640000
 DURATION-eng : 00:42:08.096000000
 NUMBER_OF_FRAMES-eng: 79003
 NUMBER_OF_BYTES-eng: 202247680
 _STATISTICS_WRITING_APP-eng: mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-10 10:21:30
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
 encoder : Lavc58.54.100 aac
 Stream #0:2(eng): Subtitle: ass (ssa)
 Metadata:
 BPS-eng : 79
 DURATION-eng : 00:41:15.299000000
 NUMBER_OF_FRAMES-eng: 802
 NUMBER_OF_BYTES-eng: 24598
 _STATISTICS_WRITING_APP-eng: mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-10 10:21:30
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
 encoder : Lavc58.54.100 ssa 
video:789747kB audio:121419kB subtitle:41kB other streams:0kB global headers:1kB muxing overhead: 0.142563%
[aac @ 0x55d0572a1740] Qavg: 428.063




Any ideas what I'm doing wrong here ? In case it helps an
ffprobe -show_streams
command run on the original file shows the following :


DL.DDP5.1.H.264-NTG.mkv
ffprobe version 4.2.2-1ubuntu1 Copyright (c) 2007-2019 the FFmpeg developers
 built with gcc 9 (Ubuntu 9.3.0-3ubuntu1)
 configuration: --prefix=/usr --extra-version=1ubuntu1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
 libavutil 56. 31.100 / 56. 31.100
 libavcodec 58. 54.100 / 58. 54.100
 libavformat 58. 29.100 / 58. 29.100
 libavdevice 58. 8.100 / 58. 8.100
 libavfilter 7. 57.100 / 7. 57.100
 libavresample 4. 0. 0 / 4. 0. 0
 libswscale 5. 5.100 / 5. 5.100
 libswresample 3. 5.100 / 3. 5.100
 libpostproc 55. 5.100 / 55. 5.100
Input #0, matroska,webm, from 'input_file.mkv':
 Metadata:
 encoder : libebml v1.3.5 + libmatroska v1.4.8
 creation_time : 2018-05-10T10:21:30.000000Z
 Duration: 00:42:08.15, start: 0.000000, bitrate: 3201 kb/s
 Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
 Metadata:
 BPS-eng : 2559028
 DURATION-eng : 00:42:08.151000000
 NUMBER_OF_FRAMES-eng: 60615
 NUMBER_OF_BYTES-eng: 808701337
 _STATISTICS_WRITING_APP-eng: mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-10 10:21:30
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
 Stream #0:1(eng): Audio: eac3, 48000 Hz, 6 channels, fltp (default)
 Metadata:
 BPS-eng : 640000
 DURATION-eng : 00:42:08.096000000
 NUMBER_OF_FRAMES-eng: 79003
 NUMBER_OF_BYTES-eng: 202247680
 _STATISTICS_WRITING_APP-eng: mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-10 10:21:30
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
 Stream #0:2(eng): Subtitle: subrip
 Metadata:
 BPS-eng : 79
 DURATION-eng : 00:41:15.299000000
 NUMBER_OF_FRAMES-eng: 802
 NUMBER_OF_BYTES-eng: 24598
 _STATISTICS_WRITING_APP-eng: mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-10 10:21:30
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
 Stream #0:3(eng): Subtitle: subrip
 Metadata:
 title : SDH
 BPS-eng : 82
 DURATION-eng : 00:41:15.299000000
 NUMBER_OF_FRAMES-eng: 844
 NUMBER_OF_BYTES-eng: 25598
 _STATISTICS_WRITING_APP-eng: mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
 _STATISTICS_WRITING_DATE_UTC-eng: 2018-05-10 10:21:30
 _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_time_base=1001/48000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=1280
height=720
coded_width=1280
coded_height=720
has_b_frames=2
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=31
color_range=tv
color_space=bt709
color_transfer=bt709
color_primaries=bt709
chroma_location=left
field_order=progressive
timecode=N/A
refs=1
is_avc=true
nal_length_size=4
id=N/A
r_frame_rate=24000/1001
avg_frame_rate=24000/1001
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:BPS-eng=2559028
TAG:DURATION-eng=00:42:08.151000000
TAG:NUMBER_OF_FRAMES-eng=60615
TAG:NUMBER_OF_BYTES-eng=808701337
TAG:_STATISTICS_WRITING_APP-eng=mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
TAG:_STATISTICS_WRITING_DATE_UTC-eng=2018-05-10 10:21:30
TAG:_STATISTICS_TAGS-eng=BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
[/STREAM]
[STREAM]
index=1
codec_name=eac3
codec_long_name=ATSC A/52B (AC-3, E-AC-3)
profile=unknown
codec_type=audio
codec_time_base=1/48000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=fltp
sample_rate=48000
channels=6
channel_layout=unknown
bits_per_sample=0
dmix_mode=-1
ltrt_cmixlev=-1.000000
ltrt_surmixlev=-1.000000
loro_cmixlev=-1.000000
loro_surmixlev=-1.000000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=eng
TAG:BPS-eng=640000
TAG:DURATION-eng=00:42:08.096000000
TAG:NUMBER_OF_FRAMES-eng=79003
TAG:NUMBER_OF_BYTES-eng=202247680
TAG:_STATISTICS_WRITING_APP-eng=mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
TAG:_STATISTICS_WRITING_DATE_UTC-eng=2018-05-10 10:21:30
TAG:_STATISTICS_TAGS-eng=BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
[/STREAM]
[STREAM]
index=2
codec_name=subrip
codec_long_name=SubRip subtitle
profile=unknown
codec_type=subtitle
codec_time_base=0/1
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=N/A
height=N/A
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=2528151
duration=2528.151000
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=eng
TAG:BPS-eng=79
TAG:DURATION-eng=00:41:15.299000000
TAG:NUMBER_OF_FRAMES-eng=802
TAG:NUMBER_OF_BYTES-eng=24598
TAG:_STATISTICS_WRITING_APP-eng=mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
TAG:_STATISTICS_WRITING_DATE_UTC-eng=2018-05-10 10:21:30
TAG:_STATISTICS_TAGS-eng=BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
[/STREAM]
[STREAM]
index=3
codec_name=subrip
codec_long_name=SubRip subtitle
profile=unknown
codec_type=subtitle
codec_time_base=0/1
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=N/A
height=N/A
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=2528151
duration=2528.151000
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=eng
TAG:title=SDH
TAG:BPS-eng=82
TAG:DURATION-eng=00:41:15.299000000
TAG:NUMBER_OF_FRAMES-eng=844
TAG:NUMBER_OF_BYTES-eng=25598
TAG:_STATISTICS_WRITING_APP-eng=mkvmerge v21.0.0 ('Tardigrades Will Inherit The Earth') 64-bit
TAG:_STATISTICS_WRITING_DATE_UTC-eng=2018-05-10 10:21:30
TAG:_STATISTICS_TAGS-eng=BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
[/STREAM]




-
FFmpeg - Audio encoding produces extra noise over audio
17 mai 2020, par user3208915I am trying to use FFmpeg to take a video (MP4 in this case) and copy it as another MP4. This is so that I can get the hang of decoding/encoding a video and go on to doing other things in that process. My code basically takes a video file, decodes the video and audio streams, and encodes the video and audio streams to an output video file.



As of now, my code only works for the video stream of the input file. The video part of the output file is exactly the same as the video part of the input file. However, the audio part is not. The audio part of the output contains the original audio, but with noise over it. Think of it as someone screaming into their mic or when audio gets too loud for a speaker to handle.



The way I'm handling the decoding/encoding process for the video and audio streams is the same, except with a difference in AVCodecContext settings (video —> frame_rate, width, height, etc. ; audio —> sample_rate, channels, etc.).



This is currently the code that I'm working with :



The Video struct :



typedef struct Video {
 AVFormatContext* inputContext;
 AVFormatContext* outputContext;
 AVCodec* videoCodec;
 AVCodec* audioCodec;
 AVStream* inputStream;
 AVStream* outputStream;
 AVCodecContext* videoCodecContext_I; // Input
 AVCodecContext* audioCodecContext_I; // Input
 AVCodecContext* videoCodecContext_O; // Output
 AVCodecContext* audioCodecContext_O; // Output
 int videoStream; // Video stream index
 int audioStream; // Audio stream index
} Video;




The main code that handles the encoding/decoding (I've only included the audio side since the video side is the same) :



int openVideo(Video* video, char* filename, char* outputFile) {
 video->inputContext = avformat_alloc_context();
 if (!video->inputContext) {
 printf("[ERROR] Failed to allocate input format context\n");
 return -1;
 }
 if (avformat_open_input(&(video->inputContext), filename, NULL, NULL) < 0) {
 printf("[ERROR] Could not open the input file\n");
 return -1;
 }

 if (avformat_find_stream_info(video->inputContext, NULL) < 0) {
 printf("[ERROR] Failed to retrieve input stream info\n");
 return -1;
 }
 avformat_alloc_output_context2(&(video->outputContext), NULL, NULL, outputFile);
 if (!video->outputContext) {
 printf("[ERROR] Failed to create output context\n");
 return -1;
 }
 printf("[OPEN] Video %s opened\n", filename);
 return 0;
}

int prepareStreamInfo(AVCodecContext** codecContext, AVCodec** codec, AVStream* stream) {
 *codec = avcodec_find_decoder(stream->codecpar->codec_id);
 if (!*codec) {
 printf("[ERROR] Failed to find input codec\n");
 return -1;
 }
 *codecContext = avcodec_alloc_context3(*codec);
 if (!codecContext) {
 printf("[ERROR] Failed to allocate memory for input codec context\n");
 return -1;
 }
 if (avcodec_parameters_to_context(*codecContext, stream->codecpar) < 0) {
 printf("[ERROR] Failed to fill input codec context\n");
 return -1;
 }
 if (avcodec_open2(*codecContext, *codec, NULL) < 0) {
 printf("[ERROR] Failed to open input codec\n");
 return -1;
 }
 return 0;
}

int findStreams(Video* video, char* filename, char* outputFile) {
 if (openVideo(video, filename, outputFile) < 0) {
 printf("[ERROR] Video %s failed to open\n", filename);
 return -1;
 }
 for (int i = 0; i < video->inputContext->nb_streams; i++) {
 video->inputStream = video->inputContext->streams[i];
 if (video->inputContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
 video->videoStream = i;
 if (prepareStreamInfo(&(video->videoCodecContext_I), &(video->videoCodec), video->inputStream) < 0) {
 printf("[ERROR] Could not prepare video stream information\n");
 return -1;video->outputStream->time_base = video->audioCodecContext_O->time_base;
 }
 } else if (video->inputContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
 video->audioStream = i;
 if (prepareStreamInfo(&(video->audioCodecContext_I), &(video->audioCodec), video->inputStream) < 0) {
 printf("[ERROR] Could not prepare audio stream information\n");
 return -1;
 }
 }
 video->outputStream = avformat_new_stream(video->outputContext, NULL);
 if (!video->outputStream) {
 printf("[ERROR] Failed allocating output stream\n");
 return -1;
 }
 if (avcodec_parameters_copy(video->outputStream->codecpar, video->inputStream->codecpar) < 0) {
 printf("[ERROR] Failed to copy codec parameters\n");
 return -1;
 }
 }
 if (video->videoStream == -1) {
 printf("[ERROR] Video stream for %s not found\n", filename);
 return -1;
 }
 if (video->audioStream == -1) {
 printf("[ERROR] Audio stream for %s not found\n", filename);
 return -1;
 }
 if (!(video->outputContext->oformat->flags & AVFMT_NOFILE)) {
 if (avio_open(&(video->outputContext->pb), outputFile, AVIO_FLAG_WRITE) < 0) {
 printf("Could not open output file %s", outputFile);
 return -1;
 }
 }
 return 0;
}

int prepareAudioOutStream(Video* video) {
 video->audioCodec = avcodec_find_encoder_by_name("mp2");
 if (!video->audioCodec) {
 printf("[ERROR] Failed to find audio output codec\n");
 return -1;
 }
 video->audioCodecContext_O = avcodec_alloc_context3(video->audioCodec);
 if (!video->audioCodecContext_O) {
 printf("[ERROR] Failed to allocate memory for audio output codec context\n");
 return -1;
 }
 // Quite possibly the issue
 video->audioCodecContext_O->channels = video->audioCodecContext_I->channels;
 video->audioCodecContext_O->channel_layout = av_get_default_channel_layout(video->audioCodecContext_O->channels);
 video->audioCodecContext_O->sample_rate = video->audioCodecContext_I->sample_rate;
 video->audioCodecContext_O->sample_fmt = video->audioCodec->sample_fmts[0];
 video->audioCodecContext_O->bit_rate = video->audioCodecContext_I->bit_rate;
 video->audioCodecContext_O->time_base = video->audioCodecContext_I->time_base;
 video->audioCodecContext_O->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
 if (avcodec_open2(video->audioCodecContext_O, video->audioCodec, NULL) < 0) {
 printf("[ERROR] Failed to open audio output codec\n");
 return -1;
 }
 if (avcodec_parameters_from_context(getAudioStream(video)->codecpar, video->audioCodecContext_O) < 0) {
 printf("[ERROR] Failed to fill audio stream\n");
 return -1;
 }
 return 0;
}

int decodeAudio(Video* video, AVPacket* packet, AVFrame* frame) {
 int response = avcodec_send_packet(video->audioCodecContext_I, packet);
 if (response < 0) {
 printf("[ERROR] Failed to send audio packet to decoder\n");
 return response;
 }
 while (response >= 0) {
 response = avcodec_receive_frame(video->audioCodecContext_I, frame);
 if (response == AVERROR(EAGAIN) || response == AVERROR_EOF) {
 break;
 } else if (response < 0) {
 printf("[ERROR] Failed to receive audio frame from decoder\n");
 return response;
 }
 if (response >= 0) {
 // Do stuff and encode
 if (encodeAudio(video, frame) < 0) {
 printf("[ERROR] Failed to encode new audio\n");
 return -1;
 }
 }
 av_frame_unref(frame);
 }
 return 0;
}

int encodeAudio(Video* video, AVFrame* frame) {
 AVPacket* packet = av_packet_alloc();
 if (!packet) {
 printf("[ERROR] Could not allocate memory for audio output packet\n");
 return -1;
 }
 int response = avcodec_send_frame(video->audioCodecContext_O, frame);
 if (response < 0) {
 printf("[ERROR] Failed to send audio frame for encoding\n");
 return response;
 }
 while (response >= 0) {
 response = avcodec_receive_packet(video->audioCodecContext_O, packet);
 if (response == AVERROR(EAGAIN) || response == AVERROR_EOF) {
 break;
 } else if (response < 0) {
 printf("[ERROR] Failed to receive audio packet from encoder\n");
 return response;
 }
 packet->stream_index = video->audioStream;
 video->inputStream = getAudioStream(video);
 video->outputStream = video->outputContext->streams[packet->stream_index];
 packet->pts = av_rescale_q_rnd(packet->pts, video->inputStream->time_base, video->outputStream->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
 packet->dts = av_rescale_q_rnd(packet->dts, video->inputStream->time_base, video->outputStream->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
 packet->duration = av_rescale_q(packet->duration, video->inputStream->time_base, video->outputStream->time_base);
 packet->pos = -1;
 //av_packet_rescale_ts(packet, video->inputStream->time_base, video->outputStream->time_base);

 response = av_interleaved_write_frame(video->outputContext, packet);
 if (response < 0) {
 printf("[ERROR] Failed to write audio packet\n");
 break;
 }
 }
 av_packet_unref(packet);
 av_packet_free(&packet);
 return 0;
}

int readFrames(Video* video, AVPacket* packet, AVFrame* frame) {
 if (!packet) {
 printf("[ERROR] Packet not allocated to be read\n");
 return -1;
 }
 if (!frame) {
 printf("[ERROR] Frame not allocated to be read\n");
 return -1;
 }
 if (prepareVideoOutStream(video) < 0) {
 printf("[ERROR] Failed to prepare output video stream\n");
 return -1;
 }
 if (prepareAudioOutStream(video) < 0) {
 printf("[ERROR] Failed to prepare output audio stream\n");
 return -1;
 }
 int frameNum = 0;
 while (av_read_frame(video->inputContext, packet) >= 0) {
 printf("[READ] Reading frame %i\n", frameNum);
 if (packet->stream_index == video->videoStream) {
 if (decodeVideo(video, packet, frame) < 0) {
 printf("[ERROR] Failed to decode and encode video\n");
 return -1;
 }
 } else if (packet->stream_index == video->audioStream) {
 if (decodeAudio(video, packet, frame) < 0) {
 printf("[ERROR] Failed to decode and encode audio\n");
 return -1;
 }
 }
 av_packet_unref(packet);
 frameNum++;
 }
 // Flush encoder
 encodeVideo(video, NULL);
 encodeAudio(video, NULL);
 av_write_trailer(video->outputContext);
 return 0;
}




My main method that runs all the functions :



int main(int argc, char* argv[]) {
 Video* video = (Video*)malloc(sizeof(Video));
 initVideo(video);
 if (findStreams(video, argv[1], argv[2]) < 0) {
 printf("[ERROR] Could not find streams\n");
 return -1;
 }

 AVDictionary* dic = NULL;
 if (avformat_write_header(video->outputContext, &dic) < 0) {
 printf("[ERROR] Error while writing header to output file\n");
 return -1;
 }
 AVFrame* frame = av_frame_alloc();
 AVPacket* packet = av_packet_alloc();
 if (readFrames(video, packet, frame) < 0) {
 printf("[ERROR] Failed to read and write new video\n");
 return -1;
 }
 freeVideo(video); // Frees all codecs and contexts and the video
 return 0;
}




I tried to lay out my code so that it can be read from top to bottom without needing to scroll up.



I realize that when copying a video, I can just pass the AVPacket to write to the output file, but I wanted to be able to work with the AVFrame in the future, so I wrote it this way. I have a feeling that the issue with the way my audio is behaving is because of the audio output AVCodecContext from the prepareAudioOutStream() function.



Reading the FFmpeg documentation has proved to be of little help with this issue as well as other online sources. I must be missing something (or have something unneeded) so anything that would point me in the right direction would be helpful.



Thank you.