From: Carl Hetherington Date: Thu, 29 Nov 2018 01:38:35 +0000 (+0000) Subject: swaroop: basic pass-through mp4 encoder. X-Git-Tag: v2.13.78~1 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=d2cf99dbfda417caae0d47c004a3262ca75321ca swaroop: basic pass-through mp4 encoder. --- diff --git a/run/dcpomatic_ecinema b/run/dcpomatic_ecinema new file mode 100755 index 000000000..ddb75157f --- /dev/null +++ b/run/dcpomatic_ecinema @@ -0,0 +1,25 @@ +#!/bin/bash + +export LD_LIBRARY_PATH=build/src/lib:build/src/wx:/home/c.hetherington/lib:$LD_LIBRARY_PATH +export DYLD_LIBRARY_PATH=build/src/lib:build/src/wx:/carl/Environment/64/lib +if [ "$1" == "--debug" ]; then + shift + gdb --args build/src/tools/dcpomatic2_ecinema $* +elif [ "$1" == "--valgrind" ]; then + shift + valgrind --tool="memcheck" build/src/tools/dcpomatic2_ecinema $* +elif [ "$1" == "--callgrind" ]; then + shift + valgrind --tool="callgrind" build/src/tools/dcpomatic2_ecinema $* +elif [ "$1" == "--massif" ]; then + shift + valgrind --tool="massif" build/src/tools/dcpomatic2_ecinema $* +elif [ "$1" == "--i18n" ]; then + shift + LANGUAGE=fr_FR.UTF8 LANG=fr_FR.UTF8 LC_ALL=fr_FR.UTF8 build/src/tools/dcpomatic2_ecinema "$*" +elif [ "$1" == "--perf" ]; then + shift + perf record build/src/tools/dcpomatic2_ecinema $* +else + build/src/tools/dcpomatic2_ecinema $* +fi diff --git a/src/tools/dcpomatic_ecinema.cc b/src/tools/dcpomatic_ecinema.cc new file mode 100644 index 000000000..6a19e5c42 --- /dev/null +++ b/src/tools/dcpomatic_ecinema.cc @@ -0,0 +1,173 @@ +/* + Copyright (C) 2018 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic 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 2 of the License, or + (at your option) any later version. + + DCP-o-matic 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 DCP-o-matic. If not, see . + +*/ + +#include "lib/version.h" +extern "C" { +#include +} +#include +#include +#include +#include +#include +#include +#include + +using std::string; +using std::cerr; +using std::cout; +using boost::optional; + +static void +help (string n) +{ + cerr << "Syntax: " << n << " [OPTION] \n" + << " -v, --version show DCP-o-matic version\n" + << " -h, --help show this help\n" + << "\n" + << " is the unencrypted .mp4 file.\n"; +} + +int +main (int argc, char* argv[]) +{ + optional output; + + int option_index = 0; + while (true) { + static struct option long_options[] = { + { "version", no_argument, 0, 'v'}, + { "help", no_argument, 0, 'h'}, + { "output", required_argument, 0, 'o'}, + }; + + int c = getopt_long (argc, argv, "vho:", long_options, &option_index); + + if (c == -1) { + break; + } + + switch (c) { + case 'v': + cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n"; + exit (EXIT_SUCCESS); + case 'h': + help (argv[0]); + exit (EXIT_SUCCESS); + case 'o': + output = optarg; + break; + } + } + + if (optind >= argc) { + help (argv[0]); + exit (EXIT_FAILURE); + } + + if (!output) { + cerr << "You must specify --output or -o\n"; + exit (EXIT_FAILURE); + } + + boost::filesystem::path input = argv[optind]; + boost::filesystem::path output_mp4 = *output / (input.filename().string() + ".ecinema"); + + if (mkdir(output->c_str(), 0777) < 0) { + cerr << "Could not create output directory `" << output->string() << "'\n"; + exit (EXIT_FAILURE); + } + + av_register_all (); + + AVFormatContext* input_fc = avformat_alloc_context (); + if (avformat_open_input(&input_fc, input.string().c_str(), 0, 0) < 0) { + cerr << "Could not open input file\n"; + exit (EXIT_FAILURE); + } + + if (avformat_find_stream_info (input_fc, 0) < 0) { + cerr << "Could not read stream information\n"; + exit (EXIT_FAILURE); + } + + AVFormatContext* output_fc; + avformat_alloc_output_context2 (&output_fc, av_guess_format("mp4", 0, 0), 0, 0); + + for (uint32_t i = 0; i < input_fc->nb_streams; ++i) { + AVStream* is = input_fc->streams[i]; + AVStream* os = avformat_new_stream (output_fc, is->codec->codec); + if (avcodec_copy_context (os->codec, is->codec) < 0) { + cerr << "Could not set up output stream.\n"; + exit (EXIT_FAILURE); + } + + switch (os->codec->codec_type) { + case AVMEDIA_TYPE_VIDEO: + os->time_base = is->time_base; + os->avg_frame_rate = is->avg_frame_rate; + os->r_frame_rate = is->r_frame_rate; + os->sample_aspect_ratio = is->sample_aspect_ratio; + os->codec->time_base = is->codec->time_base; + os->codec->framerate = is->codec->framerate; + os->codec->pix_fmt = is->codec->pix_fmt; + break; + case AVMEDIA_TYPE_AUDIO: + os->codec->sample_fmt = is->codec->sample_fmt; + os->codec->bits_per_raw_sample = is->codec->bits_per_raw_sample; + os->codec->sample_rate = is->codec->sample_rate; + os->codec->channel_layout = is->codec->channel_layout; + os->codec->channels = is->codec->channels; + break; + default: + /* XXX */ + break; + } + } + + if (avio_open2 (&output_fc->pb, output_mp4.string().c_str(), AVIO_FLAG_WRITE, 0, 0) < 0) { + cerr << "Could not open output file `" << output_mp4.string() << "'\n"; + exit (EXIT_FAILURE); + } + + if (avformat_write_header (output_fc, 0) < 0) { + cerr << "Could not write header to output.\n"; + exit (EXIT_FAILURE); + } + + AVPacket packet; + while (av_read_frame(input_fc, &packet) >= 0) { + AVStream* is = input_fc->streams[packet.stream_index]; + AVStream* os = output_fc->streams[packet.stream_index]; + packet.pts = av_rescale_q_rnd(packet.pts, is->time_base, os->time_base, (AVRounding) (AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX)); + packet.dts = av_rescale_q_rnd(packet.dts, is->time_base, os->time_base, (AVRounding) (AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX)); + packet.duration = av_rescale_q(packet.duration, is->time_base, os->time_base); + packet.pos = -1; + if (av_interleaved_write_frame (output_fc, &packet) < 0) { + cerr << "Could not write frame to output.\n"; + exit (EXIT_FAILURE); + } + } + + av_write_trailer (output_fc); + + avformat_free_context (input_fc); + avformat_free_context (output_fc); +} diff --git a/src/tools/wscript b/src/tools/wscript index 29cca533a..b6efc22b5 100644 --- a/src/tools/wscript +++ b/src/tools/wscript @@ -35,16 +35,21 @@ def build(bld): if bld.env.TARGET_WINDOWS: uselib += 'WINSOCK2 DBGHELP SHLWAPI MSWSOCK BOOST_LOCALE WINSOCK2 OLE32 DSOUND WINMM KSUSER ' + cli_tools = [] if bld.env.VARIANT != "swaroop": - for t in ['dcpomatic_cli', 'dcpomatic_server_cli', 'server_test', 'dcpomatic_kdm_cli', 'dcpomatic_create']: - obj = bld(features='cxx cxxprogram') - obj.uselib = uselib - obj.includes = ['..'] - obj.use = ['libdcpomatic2'] - obj.source = '%s.cc' % t - obj.target = t.replace('dcpomatic', 'dcpomatic2') - if t == 'server_test': - obj.install_path = None + cli_tools = ['dcpomatic_cli', 'dcpomatic_server_cli', 'server_test', 'dcpomatic_kdm_cli', 'dcpomatic_create'] + else: + cli_tools = ['dcpomatic_ecinema'] + + for t in cli_tools: + obj = bld(features='cxx cxxprogram') + obj.uselib = uselib + obj.includes = ['..'] + obj.use = ['libdcpomatic2'] + obj.source = '%s.cc' % t + obj.target = t.replace('dcpomatic', 'dcpomatic2') + if t == 'server_test': + obj.install_path = None gui_tools = [] if not bld.env.DISABLE_GUI: