
Recherche avancée
Médias (2)
-
GetID3 - Bloc informations de fichiers
9 avril 2013, par
Mis à jour : Mai 2013
Langue : français
Type : Image
-
GetID3 - Boutons supplémentaires
9 avril 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Image
Autres articles (50)
-
Mise à disposition des fichiers
14 avril 2011, parPar défaut, lors de son initialisation, MediaSPIP ne permet pas aux visiteurs de télécharger les fichiers qu’ils soient originaux ou le résultat de leur transformation ou encodage. Il permet uniquement de les visualiser.
Cependant, il est possible et facile d’autoriser les visiteurs à avoir accès à ces documents et ce sous différentes formes.
Tout cela se passe dans la page de configuration du squelette. Il vous faut aller dans l’espace d’administration du canal, et choisir dans la navigation (...) -
Problèmes fréquents
10 mars 2010, parPHP et safe_mode activé
Une des principales sources de problèmes relève de la configuration de PHP et notamment de l’activation du safe_mode
La solution consiterait à soit désactiver le safe_mode soit placer le script dans un répertoire accessible par apache pour le site -
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 (...)
Sur d’autres sites (8267)
-
ffmpeg stream encoding out produce a stream shows different program on each start
15 octobre 2018, par Ryan PhilipI am using ffmpeg for almost one year, my stream recently started behaving badly.
The lines on ffmpeg screen started running crazy fast when restreaming it, causing more CPU (with no encoding). I have mapped the stream to select only one stream. But the problem is even with mapping I am getting different program each time when it is played.
Also each program it is playing for less than a minute. There is no specific error message showing on ffmpeg screen. Only the output is behaving badly.
I even tried ffmpeg version 3.3, 3.4 and 4.0 with same results.
It has so many resolution streams, so i selected only 33 (video) and 34 (audio), the ones with highest resolution.
ffmpeg -i "http://insourceip/stream.m3u8" -err_detect explode -c copy -map 0:33? -map 0:34? -hls_time 10 -hls_list_size 6 -hls_wrap 10 -start_number 1 out/music.m3u8
Please help me with this.
Below is the output : the one after (No longer receiving playlist 8) start running crazy when started.
Program 11
Metadata:
variant_bitrate : 1088000
Stream #0:33: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p, 640x480 [SAR 12:11 DAR 16:11], 25 fps, 25 tbr, 90k tbn, 50 tbc
Metadata:
variant_bitrate : 1088000
Stream #0:34: Audio: aac (LC) ([15][0][0][0] / 0x000F), 32000 Hz, stereo, fltp
Metadata:
variant_bitrate : 1088000
Stream #0:35: Data: timed_id3 (ID3 / 0x20334449)
Metadata:
variant_bitrate : 1088000
[hls @ 0x7a64120] Opening '/music1.ts' for writing
Output #0, hls, to '/music.m3u8':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p, 640x480 [SAR 12:11 DAR 16:11], q=2-31, 25 fps, 25 tbr, 90k tbn, 25 tbc
Metadata:
variant_bitrate : 1088000
Stream #0:1: Audio: aac (LC) ([15][0][0][0] / 0x000F), 32000 Hz, stereo, fltp
Metadata:
variant_bitrate : 1088000
Stream #0:2: Data: timed_id3 (ID3 / 0x20334449)
Metadata:
variant_bitrate : 1088000
Stream mapping:
Stream #0:33 -> #0:0 (copy)
Stream #0:34 -> #0:1 (copy)
Stream #0:35 -> #0:2 (copy)
Press [q] to stop, [?] for help
[hls,applehttp @ 0x3d57120] No longer receiving playlist 10
[hls,applehttp @ 0x3d57120] No longer receiving playlist 1
[hls,applehttp @ 0x3d57120] No longer receiving playlist 3
[hls,applehttp @ 0x3d57120] No longer receiving playlist 5
[hls,applehttp @ 0x3d57120] No longer receiving playlist 7
[hls,applehttp @ 0x3d57120] No longer receiving playlist 9
[hls,applehttp @ 0x3d57120] No longer receiving playlist 0
[hls,applehttp @ 0x3d57120] No longer receiving playlist 2
[hls,applehttp @ 0x3d57120] No longer receiving playlist 4
[hls,applehttp @ 0x3d57120] No longer receiving playlist 6
[hls,applehttp @ 0x3d57120] No longer receiving playlist 8
***[hls,applehttp @ 0x3d57120] Opening 'FORMATED/i/MUSIC_1@13394/segment153957897_1_av-b.ts' for reading
[hls,applehttp @ 0x3d57120] Opening 'FORMATED/i/MUSIC_1@13394/segment153957898_1_av-b.ts' for reading
[hls @ 0x7a64120] Opening '/music2.ts' for writing
[hls @ 0x7a64120] Opening '/music.m3u8.tmp' for writing
[hls,applehttp @ 0x3d57120] Opening 'FORMATED/i/MUSIC_1@13394/segment153957899_1_av-b.ts' for reading
[hls @ 0x7a64120] Opening '/music3.ts' for writing*** -
How to fix a segmentaion fault in a C program ? [closed]
13 janvier 2012, par ipegasusPossible Duplicate :
Segmentation faultCurrently I am upgrading an open source program used for HTTP streaming. It needs to support the latest FFMPEG.
The code compiles fine with no warnings although I am getting a segmentation fault error.
I would like to know how to fix the issue ? and / or the best way to debug ? Please find attached a portion of the code due to size. I will try to add the project to github :) Thanks in advance !Sample Usage
# segmenter --i out.ts --l 10 --o stream.m3u8 --d segments --f stream
Makefile
FFLIBS=`pkg-config --libs libavformat libavcodec libavutil`
FFFLAGS=`pkg-config --cflags libavformat libavcodec libavutil`
all:
gcc -Wall -g segmenter.c -o segmenter ${FFFLAGS} ${FFLIBS}segmenter.c
/*
* Copyright (c) 2009 Chase Douglas
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include
#include
#include
#include
#include
#include "libavformat/avformat.h"
#include "libavformat/avio.h"
#include <sys></sys>stat.h>
#include "segmenter.h"
#include "libavformat/avformat.h"
#define IMAGE_ID3_SIZE 9171
void printUsage() {
fprintf(stderr, "\nExample: segmenter --i infile --d baseDir --f baseFileName --o playListFile.m3u8 --l 10 \n");
fprintf(stderr, "\nOptions: \n");
fprintf(stderr, "--i <infile>.\n");
fprintf(stderr, "--o <outfile>.\n");
fprintf(stderr, "--d basedir, the base directory for files.\n");
fprintf(stderr, "--f baseFileName, output files will be baseFileName-#.\n");
fprintf(stderr, "--l segment length, the length of each segment.\n");
fprintf(stderr, "--a, audio only decode for < 64k streams.\n");
fprintf(stderr, "--v, video only decode for < 64k streams.\n");
fprintf(stderr, "--version, print version details and exit.\n");
fprintf(stderr, "\n\n");
}
void ffmpeg_version() {
// output build and version numbers
fprintf(stderr, " libavutil version: %s\n", AV_STRINGIFY(LIBAVUTIL_VERSION));
fprintf(stderr, " libavutil build: %d\n", LIBAVUTIL_BUILD);
fprintf(stderr, " libavcodec version: %s\n", AV_STRINGIFY(LIBAVCODEC_VERSION));
fprintf(stdout, " libavcodec build: %d\n", LIBAVCODEC_BUILD);
fprintf(stderr, " libavformat version: %s\n", AV_STRINGIFY(LIBAVFORMAT_VERSION));
fprintf(stderr, " libavformat build: %d\n", LIBAVFORMAT_BUILD);
fprintf(stderr, " built on " __DATE__ " " __TIME__);
#ifdef __GNUC__
fprintf(stderr, ", gcc: " __VERSION__ "\n");
#else
fprintf(stderr, ", using a non-gcc compiler\n");
#endif
}
static AVStream *add_output_stream(AVFormatContext *output_format_context, AVStream *input_stream) {
AVCodecContext *input_codec_context;
AVCodecContext *output_codec_context;
AVStream *output_stream;
output_stream = avformat_new_stream(output_format_context, 0);
if (!output_stream) {
fprintf(stderr, "Segmenter error: Could not allocate stream\n");
exit(1);
}
input_codec_context = input_stream->codec;
output_codec_context = output_stream->codec;
output_codec_context->codec_id = input_codec_context->codec_id;
output_codec_context->codec_type = input_codec_context->codec_type;
output_codec_context->codec_tag = input_codec_context->codec_tag;
output_codec_context->bit_rate = input_codec_context->bit_rate;
output_codec_context->extradata = input_codec_context->extradata;
output_codec_context->extradata_size = input_codec_context->extradata_size;
if (av_q2d(input_codec_context->time_base) * input_codec_context->ticks_per_frame > av_q2d(input_stream->time_base) && av_q2d(input_stream->time_base) < 1.0 / 1000) {
output_codec_context->time_base = input_codec_context->time_base;
output_codec_context->time_base.num *= input_codec_context->ticks_per_frame;
} else {
output_codec_context->time_base = input_stream->time_base;
}
switch (input_codec_context->codec_type) {
#ifdef USE_OLD_FFMPEG
case CODEC_TYPE_AUDIO:
#else
case AVMEDIA_TYPE_AUDIO:
#endif
output_codec_context->channel_layout = input_codec_context->channel_layout;
output_codec_context->sample_rate = input_codec_context->sample_rate;
output_codec_context->channels = input_codec_context->channels;
output_codec_context->frame_size = input_codec_context->frame_size;
if ((input_codec_context->block_align == 1 && input_codec_context->codec_id == CODEC_ID_MP3) || input_codec_context->codec_id == CODEC_ID_AC3) {
output_codec_context->block_align = 0;
} else {
output_codec_context->block_align = input_codec_context->block_align;
}
break;
#ifdef USE_OLD_FFMPEG
case CODEC_TYPE_VIDEO:
#else
case AVMEDIA_TYPE_VIDEO:
#endif
output_codec_context->pix_fmt = input_codec_context->pix_fmt;
output_codec_context->width = input_codec_context->width;
output_codec_context->height = input_codec_context->height;
output_codec_context->has_b_frames = input_codec_context->has_b_frames;
if (output_format_context->oformat->flags & AVFMT_GLOBALHEADER) {
output_codec_context->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
break;
default:
break;
}
return output_stream;
}
int write_index_file(const char index[], const char tmp_index[], const unsigned int planned_segment_duration, const unsigned int actual_segment_duration[],
const char output_directory[], const char output_prefix[], const char output_file_extension[],
const unsigned int first_segment, const unsigned int last_segment) {
FILE *index_fp;
char *write_buf;
unsigned int i;
index_fp = fopen(tmp_index, "w");
if (!index_fp) {
fprintf(stderr, "Could not open temporary m3u8 index file (%s), no index file will be created\n", tmp_index);
return -1;
}
write_buf = malloc(sizeof (char) * 1024);
if (!write_buf) {
fprintf(stderr, "Could not allocate write buffer for index file, index file will be invalid\n");
fclose(index_fp);
return -1;
}
unsigned int maxDuration = planned_segment_duration;
for (i = first_segment; i <= last_segment; i++)
if (actual_segment_duration[i] > maxDuration)
maxDuration = actual_segment_duration[i];
snprintf(write_buf, 1024, "#EXTM3U\n#EXT-X-TARGETDURATION:%u\n", maxDuration);
if (fwrite(write_buf, strlen(write_buf), 1, index_fp) != 1) {
fprintf(stderr, "Could not write to m3u8 index file, will not continue writing to index file\n");
free(write_buf);
fclose(index_fp);
return -1;
}
for (i = first_segment; i <= last_segment; i++) {
snprintf(write_buf, 1024, "#EXTINF:%u,\n%s-%u%s\n", actual_segment_duration[i], output_prefix, i, output_file_extension);
if (fwrite(write_buf, strlen(write_buf), 1, index_fp) != 1) {
fprintf(stderr, "Could not write to m3u8 index file, will not continue writing to index file\n");
free(write_buf);
fclose(index_fp);
return -1;
}
}
snprintf(write_buf, 1024, "#EXT-X-ENDLIST\n");
if (fwrite(write_buf, strlen(write_buf), 1, index_fp) != 1) {
fprintf(stderr, "Could not write last file and endlist tag to m3u8 index file\n");
free(write_buf);
fclose(index_fp);
return -1;
}
free(write_buf);
fclose(index_fp);
return rename(tmp_index, index);
}
int main(int argc, const char *argv[]) {
//input parameters
char inputFilename[MAX_FILENAME_LENGTH], playlistFilename[MAX_FILENAME_LENGTH], baseDirName[MAX_FILENAME_LENGTH], baseFileName[MAX_FILENAME_LENGTH];
char baseFileExtension[5]; //either "ts", "aac" or "mp3"
int segmentLength, outputStreams, verbosity, version;
char currentOutputFileName[MAX_FILENAME_LENGTH];
char tempPlaylistName[MAX_FILENAME_LENGTH];
//these are used to determine the exact length of the current segment
double prev_segment_time = 0;
double segment_time;
unsigned int actual_segment_durations[2048];
double packet_time = 0;
//new variables to keep track of output size
double output_bytes = 0;
unsigned int output_index = 1;
AVOutputFormat *ofmt;
AVFormatContext *ic = NULL;
AVFormatContext *oc;
AVStream *video_st = NULL;
AVStream *audio_st = NULL;
AVCodec *codec;
int video_index;
int audio_index;
unsigned int first_segment = 1;
unsigned int last_segment = 0;
int write_index = 1;
int decode_done;
int ret;
int i;
unsigned char id3_tag[128];
unsigned char * image_id3_tag;
size_t id3_tag_size = 73;
int newFile = 1; //a boolean value to flag when a new file needs id3 tag info in it
if (parseCommandLine(inputFilename, playlistFilename, baseDirName, baseFileName, baseFileExtension, &outputStreams, &segmentLength, &verbosity, &version, argc, argv) != 0)
return 0;
if (version) {
ffmpeg_version();
return 0;
}
fprintf(stderr, "%s %s\n", playlistFilename, tempPlaylistName);
image_id3_tag = malloc(IMAGE_ID3_SIZE);
if (outputStreams == OUTPUT_STREAM_AUDIO)
build_image_id3_tag(image_id3_tag);
build_id3_tag((char *) id3_tag, id3_tag_size);
snprintf(tempPlaylistName, strlen(playlistFilename) + strlen(baseDirName) + 1, "%s%s", baseDirName, playlistFilename);
strncpy(playlistFilename, tempPlaylistName, strlen(tempPlaylistName));
strncpy(tempPlaylistName, playlistFilename, MAX_FILENAME_LENGTH);
strncat(tempPlaylistName, ".", 1);
//decide if this is an aac file or a mpegts file.
//postpone deciding format until later
/* ifmt = av_find_input_format("mpegts");
if (!ifmt)
{
fprintf(stderr, "Could not find MPEG-TS demuxer.\n");
exit(1);
} */
av_log_set_level(AV_LOG_DEBUG);
av_register_all();
ret = avformat_open_input(&ic, inputFilename, NULL, NULL);
if (ret != 0) {
fprintf(stderr, "Could not open input file %s. Error %d.\n", inputFilename, ret);
exit(1);
}
if (avformat_find_stream_info(ic, NULL) < 0) {
fprintf(stderr, "Could not read stream information.\n");
exit(1);
}
oc = avformat_alloc_context();
if (!oc) {
fprintf(stderr, "Could not allocate output context.");
exit(1);
}
video_index = -1;
audio_index = -1;
for (i = 0; i < ic->nb_streams && (video_index < 0 || audio_index < 0); i++) {
switch (ic->streams[i]->codec->codec_type) {
#ifdef USE_OLD_FFMPEG
case CODEC_TYPE_VIDEO:
#else
case AVMEDIA_TYPE_VIDEO:
#endif
video_index = i;
ic->streams[i]->discard = AVDISCARD_NONE;
if (outputStreams & OUTPUT_STREAM_VIDEO)
video_st = add_output_stream(oc, ic->streams[i]);
break;
#ifdef USE_OLD_FFMPEG
case CODEC_TYPE_AUDIO:
#else
case AVMEDIA_TYPE_AUDIO:
#endif
audio_index = i;
ic->streams[i]->discard = AVDISCARD_NONE;
if (outputStreams & OUTPUT_STREAM_AUDIO)
audio_st = add_output_stream(oc, ic->streams[i]);
break;
default:
ic->streams[i]->discard = AVDISCARD_ALL;
break;
}
}
if (video_index == -1) {
fprintf(stderr, "Stream must have video component.\n");
exit(1);
}
//now that we know the audio and video output streams
//we can decide on an output format.
if (outputStreams == OUTPUT_STREAM_AUDIO) {
//the audio output format should be the same as the audio input format
switch (ic->streams[audio_index]->codec->codec_id) {
case CODEC_ID_MP3:
fprintf(stderr, "Setting output audio to mp3.");
strncpy(baseFileExtension, ".mp3", strlen(".mp3"));
ofmt = av_guess_format("mp3", NULL, NULL);
break;
case CODEC_ID_AAC:
fprintf(stderr, "Setting output audio to aac.");
ofmt = av_guess_format("adts", NULL, NULL);
break;
default:
fprintf(stderr, "Codec id %d not supported.\n", ic->streams[audio_index]->id);
}
if (!ofmt) {
fprintf(stderr, "Could not find audio muxer.\n");
exit(1);
}
} else {
ofmt = av_guess_format("mpegts", NULL, NULL);
if (!ofmt) {
fprintf(stderr, "Could not find MPEG-TS muxer.\n");
exit(1);
}
}
oc->oformat = ofmt;
if (outputStreams & OUTPUT_STREAM_VIDEO && oc->oformat->flags & AVFMT_GLOBALHEADER) {
oc->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
/* Deprecated: pass the options to avformat_write_header directly.
if (av_set_parameters(oc, NULL) < 0) {
fprintf(stderr, "Invalid output format parameters.\n");
exit(1);
}
*/
av_dump_format(oc, 0, baseFileName, 1);
//open the video codec only if there is video data
if (video_index != -1) {
if (outputStreams & OUTPUT_STREAM_VIDEO)
codec = avcodec_find_decoder(video_st->codec->codec_id);
else
codec = avcodec_find_decoder(ic->streams[video_index]->codec->codec_id);
if (!codec) {
fprintf(stderr, "Could not find video decoder, key frames will not be honored.\n");
}
if (outputStreams & OUTPUT_STREAM_VIDEO)
ret = avcodec_open2(video_st->codec, codec, NULL);
else
avcodec_open2(ic->streams[video_index]->codec, codec, NULL);
if (ret < 0) {
fprintf(stderr, "Could not open video decoder, key frames will not be honored.\n");
}
}
snprintf(currentOutputFileName, strlen(baseDirName) + strlen(baseFileName) + strlen(baseFileExtension) + 10, "%s%s-%u%s", baseDirName, baseFileName, output_index++, baseFileExtension);
if (avio_open(&oc->pb, currentOutputFileName, URL_WRONLY) < 0) {
fprintf(stderr, "Could not open '%s'.\n", currentOutputFileName);
exit(1);
}
newFile = 1;
int r = avformat_write_header(oc,NULL);
if (r) {
fprintf(stderr, "Could not write mpegts header to first output file.\n");
debugReturnCode(r);
exit(1);
}
//no segment info is written here. This just creates the shell of the playlist file
write_index = !write_index_file(playlistFilename, tempPlaylistName, segmentLength, actual_segment_durations, baseDirName, baseFileName, baseFileExtension, first_segment, last_segment);
do {
AVPacket packet;
decode_done = av_read_frame(ic, &packet);
if (decode_done < 0) {
break;
}
if (av_dup_packet(&packet) < 0) {
fprintf(stderr, "Could not duplicate packet.");
av_free_packet(&packet);
break;
}
//this time is used to check for a break in the segments
// if (packet.stream_index == video_index && (packet.flags & PKT_FLAG_KEY))
// {
// segment_time = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;
// }
#if USE_OLD_FFMPEG
if (packet.stream_index == video_index && (packet.flags & PKT_FLAG_KEY))
#else
if (packet.stream_index == video_index && (packet.flags & AV_PKT_FLAG_KEY))
#endif
{
segment_time = (double) packet.pts * ic->streams[video_index]->time_base.num / ic->streams[video_index]->time_base.den;
}
// else if (video_index < 0)
// {
// segment_time = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;
// }
//get the most recent packet time
//this time is used when the time for the final segment is printed. It may not be on the edge of
//of a keyframe!
if (packet.stream_index == video_index)
packet_time = (double) packet.pts * ic->streams[video_index]->time_base.num / ic->streams[video_index]->time_base.den; //(double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;
else if (outputStreams & OUTPUT_STREAM_AUDIO)
packet_time = (double) audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;
else
continue;
//start looking for segment splits for videos one half second before segment duration expires. This is because the
//segments are split on key frames so we cannot expect all segments to be split exactly equally.
if (segment_time - prev_segment_time >= segmentLength - 0.5) {
fprintf(stderr, "looking to print index file at time %lf\n", segment_time);
avio_flush(oc->pb);
avio_close(oc->pb);
if (write_index) {
actual_segment_durations[++last_segment] = (unsigned int) rint(segment_time - prev_segment_time);
write_index = !write_index_file(playlistFilename, tempPlaylistName, segmentLength, actual_segment_durations, baseDirName, baseFileName, baseFileExtension, first_segment, last_segment);
fprintf(stderr, "Writing index file at time %lf\n", packet_time);
}
struct stat st;
stat(currentOutputFileName, &st);
output_bytes += st.st_size;
snprintf(currentOutputFileName, strlen(baseDirName) + strlen(baseFileName) + strlen(baseFileExtension) + 10, "%s%s-%u%s", baseDirName, baseFileName, output_index++, baseFileExtension);
if (avio_open(&oc->pb, currentOutputFileName, URL_WRONLY) < 0) {
fprintf(stderr, "Could not open '%s'\n", currentOutputFileName);
break;
}
newFile = 1;
prev_segment_time = segment_time;
}
if (outputStreams == OUTPUT_STREAM_AUDIO && packet.stream_index == audio_index) {
if (newFile && outputStreams == OUTPUT_STREAM_AUDIO) {
//add id3 tag info
//fprintf(stderr, "adding id3tag to file %s\n", currentOutputFileName);
//printf("%lf %lld %lld %lld %lld %lld %lf\n", segment_time, audio_st->pts.val, audio_st->cur_dts, audio_st->cur_pkt.pts, packet.pts, packet.dts, packet.dts * av_q2d(ic->streams[audio_index]->time_base) );
fill_id3_tag((char*) id3_tag, id3_tag_size, packet.dts);
avio_write(oc->pb, id3_tag, id3_tag_size);
avio_write(oc->pb, image_id3_tag, IMAGE_ID3_SIZE);
avio_flush(oc->pb);
newFile = 0;
}
packet.stream_index = 0; //only one stream in audio only segments
ret = av_interleaved_write_frame(oc, &packet);
} else if (outputStreams & OUTPUT_STREAM_VIDEO) {
if (newFile) {
//fprintf(stderr, "New File: %lld %lld %lld\n", packet.pts, video_st->pts.val, audio_st->pts.val);
//printf("%lf %lld %lld %lld %lld %lld %lf\n", segment_time, audio_st->pts.val, audio_st->cur_dts, audio_st->cur_pkt.pts, packet.pts, packet.dts, packet.dts * av_q2d(ic->streams[audio_index]->time_base) );
newFile = 0;
}
if (outputStreams == OUTPUT_STREAM_VIDEO)
ret = av_write_frame(oc, &packet);
else
ret = av_interleaved_write_frame(oc, &packet);
}
if (ret < 0) {
fprintf(stderr, "Warning: Could not write frame of stream.\n");
} else if (ret > 0) {
fprintf(stderr, "End of stream requested.\n");
av_free_packet(&packet);
break;
}
av_free_packet(&packet);
} while (!decode_done);
//make sure all packets are written and then close the last file.
avio_flush(oc->pb);
av_write_trailer(oc);
if (video_st && video_st->codec)
avcodec_close(video_st->codec);
if (audio_st && audio_st->codec)
avcodec_close(audio_st->codec);
for (i = 0; i < oc->nb_streams; i++) {
av_freep(&oc->streams[i]->codec);
av_freep(&oc->streams[i]);
}
avio_close(oc->pb);
av_free(oc);
struct stat st;
stat(currentOutputFileName, &st);
output_bytes += st.st_size;
if (write_index) {
actual_segment_durations[++last_segment] = (unsigned int) rint(packet_time - prev_segment_time);
//make sure that the last segment length is not zero
if (actual_segment_durations[last_segment] == 0)
actual_segment_durations[last_segment] = 1;
write_index_file(playlistFilename, tempPlaylistName, segmentLength, actual_segment_durations, baseDirName, baseFileName, baseFileExtension, first_segment, last_segment);
}
write_stream_size_file(baseDirName, baseFileName, output_bytes * 8 / segment_time);
return 0;
}
</outfile></infile> -
Linker errors when building a simple c++ program with ffmpeg
15 février 2023, par Serban StoenescuI have this c++ program :


#include <iostream>

extern "C"
{
 #include <libavcodec></libavcodec>avcodec.h>
 #include <libavformat></libavformat>avformat.h>
 #include <libswscale></libswscale>swscale.h>

}

namespace hrean::ffmpeg
{
namespace detail
{
 
}//namespace detail

void testFFmpeg()
{
 AVFormatContext *avFormatContext = avformat_alloc_context();
 //I can comment out the rest of the function, the error is the same

} //testFFmpeg()

} //namespace hrean::ffmpeg


int main(int argc, char **argv)
{
 try
 {
 hrean::ffmpeg::testFFmpeg();
 }
 catch(const std::runtime_error& e)
 {
 std::cerr << "Error! " << e.what() << '\n';
 return -1;
 }
 catch(...)
 {
 std::cerr << "Unknown error\n";
 return -1;
 }
 
 return 0;
}
</iostream>


The CMakeLists.txt for this is :


cmake_minimum_required(VERSION 3.13)
project(hrean)

add_subdirectory(lib/ffmpeg-module)

message("[temp] FFMPEG_INCLUDE_DIRS = ${FFMPEG_INCLUDE_DIRS}")
message("[temp] FFMPEG_LIBRARIES = ${FFMPEG_LIBRARIES}")
add_executable(hrean-app src/main.cpp)
target_include_directories(hrean-app PUBLIC ${FFMPEG_INCLUDE_DIRS})
target_link_libraries(hrean-app PUBLIC ${FFMPEG_LIBRARIES})



The CMakeLists.txt for lib/ffmpeg-module contains only


find_package(FFmpeg REQUIRED MODULE)



The CMake output is :


-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2") 
-- Checking for module 'libavcodec'
-- Found libavcodec, version 60.2.100
-- Checking for module 'libavformat'
-- Found libavformat, version 60.2.100
-- Checking for module 'libavdevice'
-- Found libavdevice, version 60.0.100
-- Checking for module 'libavutil'
-- Found libavutil, version 58.1.100
-- Checking for module 'libavfilter'
-- Found libavfilter, version 9.1.100
-- Checking for module 'libswscale'
-- Found libswscale, version 7.0.100
-- Checking for module 'libpostproc'
-- Found libpostproc, version 57.0.100
-- Checking for module 'libswresample'
-- Found libswresample, version 4.9.100
-- Found FFmpeg: /home/serban/ffmpeg_build/lib/libavcodec.a;/home/serban/ffmpeg_build/lib/libavformat.a;/home/serban/ffmpeg_build/lib/libavutil.a 
[temp] FFMPEG_INCLUDE_DIRS = /home/serban/ffmpeg_build/include
[temp] FFMPEG_LIBRARIES = /home/serban/ffmpeg_build/lib/libavcodec.a;/home/serban/ffmpeg_build/lib/libavformat.a;/home/serban/ffmpeg_build/lib/libavutil.a
-- Configuring done
-- Generating done
-- Build files have been written to: /home/serban/Work/hrean/build



When I run make, I get the following errors. The problem is, this worked perfectly yesterday and I changed nothing. I create a new Ubuntu virtual machine, everything fresh and I still get the same problem. The output is 1000+ lines long, here is some of it :


[ 50%] Building CXX object CMakeFiles/hrean-app.dir/src/main.cpp.o
[100%] Linking CXX executable hrean-app
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(amvenc.o): in function `amv_write_packet':
/home/serban/ffmpeg/libavformat/amvenc.c:356: undefined reference to `av_packet_unref'
/usr/bin/ld: /home/serban/ffmpeg/libavformat/amvenc.c:357: undefined reference to `av_packet_ref'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(amvenc.o): in function `amv_deinit':
/home/serban/ffmpeg/libavformat/amvenc.c:209: undefined reference to `av_packet_free'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(amvenc.o): in function `amv_init':
/home/serban/ffmpeg/libavformat/amvenc.c:111: undefined reference to `avcodec_get_name'
/usr/bin/ld: /home/serban/ffmpeg/libavformat/amvenc.c:117: undefined reference to `avcodec_get_name'
/usr/bin/ld: /home/serban/ffmpeg/libavformat/amvenc.c:188: undefined reference to `av_new_packet'
/usr/bin/ld: /home/serban/ffmpeg/libavformat/amvenc.c:196: undefined reference to `av_packet_alloc'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `asf_read_close':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1413: undefined reference to `av_packet_free'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `asf_read_single_payload':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1119: undefined reference to `av_new_packet'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `asf_read_packet':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1388: undefined reference to `av_packet_move_ref'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `reset_packet':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1030: undefined reference to `av_packet_unref'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `asf_deinterleave':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1313: undefined reference to `av_packet_unref'
/usr/bin/ld: /home/serban/ffmpeg/libavformat/asfdec_o.c:1314: undefined reference to `av_packet_from_data'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `asf_read_replicated_data':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1043: undefined reference to `av_new_packet'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `asf_read_timestamp':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1463: undefined reference to `av_packet_alloc'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `reset_packet':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1030: undefined reference to `av_packet_unref'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(asfdec_o.o): in function `asf_read_timestamp':
/home/serban/ffmpeg/libavformat/asfdec_o.c:1512: undefined reference to `av_packet_unref'



Any idea how to debug this ?


Later edit :
This is the find script I am using : FindFFmpeg.cmake
I changed the way I link to the libraries, this way causes the least amount of errors :


set(ORDERED_FFMPEG_LIBRARIES ${AVFORMAT_LIBRARIES} ${AVCODEC_LIBRARIES} ${AVUTIL_LIBRARIES})
message("[temp] ORDERED_FFMPEG_LIBRARIES=${ORDERED_FFMPEG_LIBRARIES}")
add_executable(hrean-app src/main.cpp)

target_include_directories(hrean-app PUBLIC ${FFMPEG_INCLUDE_DIRS})
target_link_libraries(hrean-app PUBLIC ${ORDERED_FFMPEG_LIBRARIES})



The errors are similar, but they seem to point to other locations :


[100%] Linking CXX executable hrean-app
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(mov.o): in function `mov_read_cmov':
/home/serban/ffmpeg/libavformat/mov.c:5578: undefined reference to `uncompress'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(swfdec.o): in function `swf_read_packet':
/home/serban/ffmpeg/libavformat/swfdec.c:393: undefined reference to `uncompress'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(swfdec.o): in function `swf_read_header':
/home/serban/ffmpeg/libavformat/swfdec.c:161: undefined reference to `inflateInit_'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(swfdec.o): in function `zlib_refill':
/home/serban/ffmpeg/libavformat/swfdec.c:134: undefined reference to `inflate'
/usr/bin/ld: /home/serban/ffmpeg_build/lib/libavformat.a(swfdec.o): in function `swf_read_close':
/home/serban/ffmpeg/libavformat/swfdec.c:557: undefined reference to `inflateEnd'



Do I have to link to anything else ?


Regards,
Serban