Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <math.h>
- extern "C" {
- #include <libavutil/mathematics.h>
- #include <libavformat/avformat.h>
- #include <libswscale/swscale.h>
- #include <libavcodec/avcodec.h>
- size_t av_strlcpy(char *dst, const char *src, size_t size);
- void av_opt_set_defaults2(void *s, int mask, int flags);
- }
- int avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat,
- const char *format, const char *filename)
- {
- AVFormatContext *s = avformat_alloc_context();
- int ret = 0;
- *avctx = NULL;
- if (!s)
- goto nomem;
- if (!oformat) {
- if (format) {
- oformat = av_guess_format(format, NULL, NULL);
- if (!oformat) {
- av_log(s, AV_LOG_ERROR, "Requested output format '%s' is not a suitable output format\n", format);
- ret = AVERROR(EINVAL);
- goto error;
- }
- } else {
- oformat = av_guess_format(NULL, filename, NULL);
- if (!oformat) {
- ret = AVERROR(EINVAL);
- av_log(s, AV_LOG_ERROR, "Unable to find a suitable output format for '%s'\n",
- filename);
- goto error;
- }
- }
- }
- s->oformat = oformat;
- if (s->oformat->priv_data_size > 0) {
- s->priv_data = av_mallocz(s->oformat->priv_data_size);
- if (!s->priv_data)
- goto nomem;
- if (s->oformat->priv_class) {
- *(const AVClass**)s->priv_data= s->oformat->priv_class;
- av_opt_set_defaults2(s->priv_data, 0, 0);
- }
- } else
- s->priv_data = NULL;
- if (filename)
- av_strlcpy(s->filename, filename, sizeof(s->filename));
- *avctx = s;
- return 0;
- nomem:
- av_log(s, AV_LOG_ERROR, "Out of memory\n");
- ret = AVERROR(ENOMEM);
- error:
- avformat_free_context(s);
- return ret;
- }
- int select_channel_layout(AVCodec *codec)
- {
- const uint64_t *p;
- uint64_t best_ch_layout = 0;
- int best_nb_channels = 0;
- if (!codec->channel_layouts)
- return AV_CH_LAYOUT_STEREO;
- p = codec->channel_layouts;
- while (*p) {
- int nb_channels = av_get_channel_layout_nb_channels(*p);
- if (nb_channels > best_nb_channels) {
- best_ch_layout = *p;
- best_nb_channels = nb_channels;
- }
- p++;
- }
- return best_ch_layout;
- }
- int check_sample_fmt(AVCodec *codec, enum AVSampleFormat sample_fmt)
- {
- const enum AVSampleFormat *p = codec->sample_fmts;
- while (*p != AV_SAMPLE_FMT_NONE) {
- if (*p == sample_fmt)
- return 1;
- p++;
- }
- return 0;
- }
- int select_sample_rate(AVCodec *codec)
- {
- const int *p;
- int best_samplerate = 0;
- if (!codec->supported_samplerates)
- return 44100;
- p = codec->supported_samplerates;
- while (*p) {
- best_samplerate = FFMAX(*p, best_samplerate);
- p++;
- }
- return best_samplerate;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement