X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fffmpeg%2Fconsumer%2Fffmpeg_consumer.cpp;h=276ddebe176a0c68a35cd555a39f1722e4dacba6;hb=99ee141d02252abc02911c31516b37dc7d551126;hp=f488be7d0684d92b408560c5b6bcb1331a9d64c1;hpb=623472e30864f882aa703c04ca916148d33a77cd;p=casparcg diff --git a/modules/ffmpeg/consumer/ffmpeg_consumer.cpp b/modules/ffmpeg/consumer/ffmpeg_consumer.cpp index f488be7d0..276ddebe1 100644 --- a/modules/ffmpeg/consumer/ffmpeg_consumer.cpp +++ b/modules/ffmpeg/consumer/ffmpeg_consumer.cpp @@ -1,21 +1,22 @@ /* -* copyright (c) 2010 Sveriges Television AB +* Copyright (c) 2011 Sveriges Television AB * -* This ffmpeg is part of CasparCG. +* This file is part of CasparCG (www.casparcg.com). * -* CasparCG is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. +* CasparCG is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. * -* CasparCG 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 CasparCG. If not, see . +* CasparCG 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 CasparCG. If not, see . * +* Author: Robert Nagy, ronag89@gmail.com */ #include "../StdAfx.h" @@ -24,26 +25,28 @@ #include "ffmpeg_consumer.h" -#include +#include "../producer/audio/audio_resampler.h" + +#include #include #include #include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include #include #include -#include -#include #include - -#include -#include - -#include +#include +#include +#include +#include #if defined(_MSC_VER) #pragma warning (push) @@ -56,6 +59,9 @@ extern "C" #include #include #include + #include + #include + #include } #if defined(_MSC_VER) #pragma warning (pop) @@ -63,6 +69,166 @@ extern "C" namespace caspar { namespace ffmpeg { +int av_opt_set(void *obj, const char *name, const char *val, int search_flags) +{ + AVClass* av_class = *(AVClass**)obj; + + if((strcmp(name, "pix_fmt") == 0 || strcmp(name, "pixel_format") == 0) && strcmp(av_class->class_name, "AVCodecContext") == 0) + { + AVCodecContext* c = (AVCodecContext*)obj; + auto pix_fmt = av_get_pix_fmt(val); + if(pix_fmt == PIX_FMT_NONE) + return -1; + c->pix_fmt = pix_fmt; + return 0; + } + if((strcmp(name, "r") == 0 || strcmp(name, "frame_rate") == 0) && strcmp(av_class->class_name, "AVCodecContext") == 0) + { + AVCodecContext* c = (AVCodecContext*)obj; + + if(c->codec_type != AVMEDIA_TYPE_VIDEO) + return -1; + + AVRational rate; + int ret = av_parse_video_rate(&rate, val); + if(ret < 0) + return ret; + + c->time_base.num = rate.den; + c->time_base.den = rate.num; + return 0; + } + + return ::av_opt_set(obj, name, val, search_flags); +} + +struct option +{ + std::string name; + std::string value; + + option(std::string name, std::string value) + : name(std::move(name)) + , value(std::move(value)) + { + } +}; + +struct output_format +{ + AVOutputFormat* format; + int width; + int height; + CodecID vcodec; + CodecID acodec; + int croptop; + int cropbot; + + output_format(const core::video_format_desc& format_desc, const std::string& filename, std::vector