forked from KolibriOS/kolibrios
ffmpeg-2.8.5
git-svn-id: svn://kolibrios.org@6147 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
108
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/aviocat.c
Normal file
108
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/aviocat.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Martin Storsjo
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libavutil/time.h"
|
||||
#include "libavformat/avformat.h"
|
||||
|
||||
static int usage(const char *argv0, int ret)
|
||||
{
|
||||
fprintf(stderr, "%s [-b bytespersec] [-d duration] input_url output_url\n", argv0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int bps = 0, duration = 0, ret, i;
|
||||
const char *input_url = NULL, *output_url = NULL;
|
||||
int64_t stream_pos = 0;
|
||||
int64_t start_time;
|
||||
char errbuf[50];
|
||||
AVIOContext *input, *output;
|
||||
|
||||
av_register_all();
|
||||
avformat_network_init();
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (!strcmp(argv[i], "-b") && i + 1 < argc) {
|
||||
bps = atoi(argv[i + 1]);
|
||||
i++;
|
||||
} else if (!strcmp(argv[i], "-d") && i + 1 < argc) {
|
||||
duration = atoi(argv[i + 1]);
|
||||
i++;
|
||||
} else if (!input_url) {
|
||||
input_url = argv[i];
|
||||
} else if (!output_url) {
|
||||
output_url = argv[i];
|
||||
} else {
|
||||
return usage(argv[0], 1);
|
||||
}
|
||||
}
|
||||
if (!output_url)
|
||||
return usage(argv[0], 1);
|
||||
|
||||
ret = avio_open2(&input, input_url, AVIO_FLAG_READ, NULL, NULL);
|
||||
if (ret) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
fprintf(stderr, "Unable to open %s: %s\n", input_url, errbuf);
|
||||
return 1;
|
||||
}
|
||||
if (duration && !bps) {
|
||||
int64_t size = avio_size(input);
|
||||
if (size < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
fprintf(stderr, "Unable to get size of %s: %s\n", input_url, errbuf);
|
||||
goto fail;
|
||||
}
|
||||
bps = size / duration;
|
||||
}
|
||||
ret = avio_open2(&output, output_url, AVIO_FLAG_WRITE, NULL, NULL);
|
||||
if (ret) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
fprintf(stderr, "Unable to open %s: %s\n", output_url, errbuf);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
start_time = av_gettime_relative();
|
||||
while (1) {
|
||||
uint8_t buf[1024];
|
||||
int n;
|
||||
n = avio_read(input, buf, sizeof(buf));
|
||||
if (n <= 0)
|
||||
break;
|
||||
avio_write(output, buf, n);
|
||||
stream_pos += n;
|
||||
if (bps) {
|
||||
avio_flush(output);
|
||||
while ((av_gettime_relative() - start_time) * bps / AV_TIME_BASE < stream_pos)
|
||||
av_usleep(50 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
avio_flush(output);
|
||||
avio_close(output);
|
||||
|
||||
fail:
|
||||
avio_close(input);
|
||||
avformat_network_deinit();
|
||||
return ret ? 1 : 0;
|
||||
}
|
46
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/bisect-create
Normal file
46
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/bisect-create
Normal file
@@ -0,0 +1,46 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if test "bisect-create" = "`basename $0`" ; then
|
||||
echo tools/ffbisect created
|
||||
git show master:tools/bisect-create > tools/ffbisect
|
||||
chmod u+x tools/ffbisect
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! git show master:tools/bisect-create | diff - tools/ffbisect > /dev/null ; then
|
||||
echo updating tools/ffbisect script to HEAD.
|
||||
git show master:tools/bisect-create > tools/ffbisect
|
||||
chmod u+x tools/ffbisect
|
||||
tools/ffbisect $*
|
||||
exit 0
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
need)
|
||||
case $2 in
|
||||
ffmpeg|ffplay|ffprobe|ffserver)
|
||||
echo $2.c >> tools/bisect.need
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
start|reset)
|
||||
echo . > tools/bisect.need
|
||||
git bisect $*
|
||||
;;
|
||||
skip)
|
||||
git bisect $*
|
||||
;;
|
||||
good|bad)
|
||||
git bisect $*
|
||||
|
||||
until ls `cat tools/bisect.need` > /dev/null 2> /dev/null; do
|
||||
git bisect skip || break
|
||||
done
|
||||
;;
|
||||
run)
|
||||
shift # remove "run" from arguments
|
||||
git bisect run sh -c "ls \`cat tools/bisect.need\` > /dev/null 2> /dev/null || exit 125; \"\$@\"" sh "$@"
|
||||
;;
|
||||
esac
|
@@ -0,0 +1,55 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
This file is part of FFmpeg.
|
||||
|
||||
All scripts contained in this file can be considered public domain.
|
||||
-->
|
||||
<title>FFmpeg bookmarklets</title>
|
||||
<meta charset="UTF-8">
|
||||
<script type="text/javascript">
|
||||
function convert(js) {
|
||||
js = js.replace(/\/\*.*?\*\//g, ""); /* comments */
|
||||
js = js.replace(/\s+/g, " ");
|
||||
js = js.replace(/\s+\z/, "");
|
||||
js = "(function(){" + js + "})();void 0";
|
||||
return "javascript:" + escape(js);
|
||||
}
|
||||
function init() {
|
||||
var pre = document.getElementsByTagName("pre");
|
||||
for (var i = 0; pre.length > i; i++) {
|
||||
document.getElementById(pre[i].id + "-link").href = convert(pre[i].textContent);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style type="text/css">
|
||||
pre { border: solid black 1px; padding: 0.2ex; font-size: 80% }
|
||||
</style>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
|
||||
<h1>Introduction</h1>
|
||||
|
||||
The scripts in this page are
|
||||
<a href="http://en.wikipedia.org/wiki/Bookmarklet">bookmarklets</a>: store
|
||||
their link version in a bookmark, and later activate the bookmark on a page
|
||||
to run the script.
|
||||
|
||||
<h1>TED Talks captions</h1>
|
||||
|
||||
<p><a id="ted_talks_captions-link" href="#">Get links to the captions</a></p>
|
||||
|
||||
<pre id="ted_talks_captions">
|
||||
d = window.open("", "sub", "width=256,height=512,resizable=yes,scrollbars=yes").document;
|
||||
l = document.getElementById("languageCode").getElementsByTagName("option");
|
||||
for (i = 1; i < l.length ; i++) {
|
||||
d.body.appendChild(p = d.createElement("p"));
|
||||
p.appendChild(a = d.createElement("a"));
|
||||
a.appendChild(d.createTextNode(l[i].textContent));
|
||||
a.href="http://www.ted.com/talks/subtitles/id/" + talkID+"/lang/" + l[i].value;
|
||||
}
|
||||
</pre>
|
||||
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$NDK" = "" ]; then
|
||||
echo NDK variable not set, assuming ${HOME}/android-ndk
|
||||
export NDK=${HOME}/android-ndk
|
||||
fi
|
||||
|
||||
echo "Fetching Android system headers"
|
||||
git clone --depth=1 --branch gingerbread-release https://github.com/CyanogenMod/android_frameworks_base.git ../android-source/frameworks/base
|
||||
git clone --depth=1 --branch gingerbread-release https://github.com/CyanogenMod/android_system_core.git ../android-source/system/core
|
||||
|
||||
echo "Fetching Android libraries for linking"
|
||||
# Libraries from any froyo/gingerbread device/emulator should work
|
||||
# fine, since the symbols used should be available on most of them.
|
||||
if [ ! -d "../android-libs" ]; then
|
||||
if [ ! -f "../update-cm-7.0.3-N1-signed.zip" ]; then
|
||||
wget http://download.cyanogenmod.com/get/update-cm-7.0.3-N1-signed.zip -P../
|
||||
fi
|
||||
unzip ../update-cm-7.0.3-N1-signed.zip system/lib/* -d../
|
||||
mv ../system/lib ../android-libs
|
||||
rmdir ../system
|
||||
fi
|
||||
|
||||
|
||||
SYSROOT=$NDK/platforms/android-9/arch-arm
|
||||
# Expand the prebuilt/* path into the correct one
|
||||
TOOLCHAIN=`echo $NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/*-x86`
|
||||
export PATH=$TOOLCHAIN/bin:$PATH
|
||||
ANDROID_SOURCE=../android-source
|
||||
ANDROID_LIBS=../android-libs
|
||||
ABI="armeabi-v7a"
|
||||
|
||||
rm -rf ../build/stagefright
|
||||
mkdir -p ../build/stagefright
|
||||
|
||||
DEST=../build/stagefright
|
||||
FLAGS="--target-os=linux --cross-prefix=arm-linux-androideabi- --arch=arm --cpu=armv7-a"
|
||||
FLAGS="$FLAGS --sysroot=$SYSROOT"
|
||||
FLAGS="$FLAGS --disable-avdevice --disable-decoder=h264 --disable-decoder=h264_vdpau --enable-libstagefright-h264"
|
||||
|
||||
EXTRA_CFLAGS="-I$ANDROID_SOURCE/frameworks/base/include -I$ANDROID_SOURCE/system/core/include"
|
||||
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/base/media/libstagefright"
|
||||
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/base/include/media/stagefright/openmax"
|
||||
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$NDK/sources/cxx-stl/gnu-libstdc++/include -I$NDK/sources/cxx-stl/gnu-libstdc++/libs/$ABI/include"
|
||||
|
||||
EXTRA_CFLAGS="$EXTRA_CFLAGS -march=armv7-a -mfloat-abi=softfp -mfpu=neon"
|
||||
EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS -L$NDK/sources/cxx-stl/gnu-libstdc++/libs/$ABI"
|
||||
EXTRA_CXXFLAGS="-Wno-multichar -fno-exceptions -fno-rtti"
|
||||
DEST="$DEST/$ABI"
|
||||
FLAGS="$FLAGS --prefix=$DEST"
|
||||
|
||||
mkdir -p $DEST
|
||||
|
||||
echo $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" --extra-cxxflags="$EXTRA_CXXFLAGS" > $DEST/info.txt
|
||||
./configure $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" --extra-cxxflags="$EXTRA_CXXFLAGS" | tee $DEST/configuration.txt
|
||||
[ $PIPESTATUS == 0 ] || exit 1
|
||||
make clean
|
||||
make -j4 || exit 1
|
11
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/clean-diff
Normal file
11
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/clean-diff
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
sed '/^+[^+]/!s/ /TaBBaT/g' |\
|
||||
expand -t $(seq -s , 9 8 200) |\
|
||||
sed 's/TaBBaT/ /g' |\
|
||||
sed '/^+[^+]/s/ * $//' |\
|
||||
tr -d '\015' |\
|
||||
tr '\n' '<27>' |\
|
||||
sed 's/\(@@[^@]*@@<40>[^@]*\)/\n\1/g' |\
|
||||
egrep -v '@@[^@]*@@<40>(( [^<5E>]*<2A>)|([+-][[:space:]]*<2A>)|(-[[:space:]]*([^<5E>]*)<29>\+[[:space:]]*\5<>))*$' |\
|
||||
tr -d '\n' |\
|
||||
tr '<27>' '\n'
|
42
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/coverity.c
Normal file
42
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/coverity.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/* Coverity Scan model
|
||||
*
|
||||
* Copyright (C) 2014 Red Hat, Inc.
|
||||
*
|
||||
* Authors:
|
||||
* Markus Armbruster <armbru@redhat.com>
|
||||
* Paolo Bonzini <pbonzini@redhat.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or, at your
|
||||
* option, any later version. See the COPYING file in the top-level directory.
|
||||
*/
|
||||
/*
|
||||
* This is the source code for our Coverity user model file. The
|
||||
* purpose of user models is to increase scanning accuracy by explaining
|
||||
* code Coverity can't see (out of tree libraries) or doesn't
|
||||
* sufficiently understand. Better accuracy means both fewer false
|
||||
* positives and more true defects. Memory leaks in particular.
|
||||
*
|
||||
* - A model file can't import any header files. Some built-in primitives are
|
||||
* available but not wchar_t, NULL etc.
|
||||
* - Modeling doesn't need full structs and typedefs. Rudimentary structs
|
||||
* and similar types are sufficient.
|
||||
* - An uninitialized local variable signifies that the variable could be
|
||||
* any value.
|
||||
*
|
||||
* The model file must be uploaded by an admin in the analysis settings of
|
||||
* https://scan.coverity.com/projects/54
|
||||
*
|
||||
* above text is based on https://github.com/qemu/qemu/blob/master/scripts/coverity-model.c
|
||||
*/
|
||||
|
||||
#define NULL (void *)0
|
||||
|
||||
// Based on https://scan.coverity.com/models
|
||||
void *av_malloc(size_t size) {
|
||||
int has_memory;
|
||||
__coverity_negative_sink__(size);
|
||||
if(has_memory)
|
||||
return __coverity_alloc__(size);
|
||||
else
|
||||
return 0;
|
||||
}
|
587
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/crypto_bench.c
Normal file
587
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/crypto_bench.c
Normal file
@@ -0,0 +1,587 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Nicolas George
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* Optional external libraries; can be enabled using:
|
||||
* make VERSUS=crypto+gcrypt+tomcrypt tools/crypto_bench */
|
||||
#define USE_crypto 0x01 /* OpenSSL's libcrypto */
|
||||
#define USE_gcrypt 0x02 /* GnuTLS's libgcrypt */
|
||||
#define USE_tomcrypt 0x04 /* LibTomCrypt */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "libavutil/avutil.h"
|
||||
#include "libavutil/avstring.h"
|
||||
#include "libavutil/crc.h"
|
||||
#include "libavutil/intreadwrite.h"
|
||||
#include "libavutil/timer.h"
|
||||
|
||||
#ifndef AV_READ_TIME
|
||||
#define AV_READ_TIME(x) 0
|
||||
#endif
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h> /* for getopt */
|
||||
#endif
|
||||
#if !HAVE_GETOPT
|
||||
#include "compat/getopt.c"
|
||||
#endif
|
||||
|
||||
#define MAX_INPUT_SIZE 1048576
|
||||
#define MAX_OUTPUT_SIZE 128
|
||||
|
||||
static const char *enabled_libs;
|
||||
static const char *enabled_algos;
|
||||
static unsigned specified_runs;
|
||||
|
||||
static const uint8_t *hardcoded_key = "FFmpeg is the best program ever.";
|
||||
|
||||
static void fatal_error(const char *tag)
|
||||
{
|
||||
av_log(NULL, AV_LOG_ERROR, "Fatal error: %s\n", tag);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
struct hash_impl {
|
||||
const char *lib;
|
||||
const char *name;
|
||||
void (*run)(uint8_t *output, const uint8_t *input, unsigned size);
|
||||
const char *output;
|
||||
};
|
||||
|
||||
/***************************************************************************
|
||||
* lavu: libavutil
|
||||
***************************************************************************/
|
||||
|
||||
#include "libavutil/md5.h"
|
||||
#include "libavutil/sha.h"
|
||||
#include "libavutil/sha512.h"
|
||||
#include "libavutil/ripemd.h"
|
||||
#include "libavutil/aes.h"
|
||||
#include "libavutil/blowfish.h"
|
||||
#include "libavutil/camellia.h"
|
||||
#include "libavutil/cast5.h"
|
||||
#include "libavutil/twofish.h"
|
||||
#include "libavutil/rc4.h"
|
||||
#include "libavutil/xtea.h"
|
||||
|
||||
#define IMPL_USE_lavu IMPL_USE
|
||||
|
||||
static void run_lavu_md5(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
av_md5_sum(output, input, size);
|
||||
}
|
||||
|
||||
#define DEFINE_LAVU_MD(suffix, type, namespace, hsize) \
|
||||
static void run_lavu_ ## suffix(uint8_t *output, \
|
||||
const uint8_t *input, unsigned size) \
|
||||
{ \
|
||||
static struct type *h; \
|
||||
if (!h && !(h = av_ ## namespace ## _alloc())) \
|
||||
fatal_error("out of memory"); \
|
||||
av_ ## namespace ## _init(h, hsize); \
|
||||
av_ ## namespace ## _update(h, input, size); \
|
||||
av_ ## namespace ## _final(h, output); \
|
||||
}
|
||||
|
||||
DEFINE_LAVU_MD(sha1, AVSHA, sha, 160);
|
||||
DEFINE_LAVU_MD(sha256, AVSHA, sha, 256);
|
||||
DEFINE_LAVU_MD(sha512, AVSHA512, sha512, 512);
|
||||
DEFINE_LAVU_MD(ripemd128, AVRIPEMD, ripemd, 128);
|
||||
DEFINE_LAVU_MD(ripemd160, AVRIPEMD, ripemd, 160);
|
||||
|
||||
static void run_lavu_aes128(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
static struct AVAES *aes;
|
||||
if (!aes && !(aes = av_aes_alloc()))
|
||||
fatal_error("out of memory");
|
||||
av_aes_init(aes, hardcoded_key, 128, 0);
|
||||
av_aes_crypt(aes, output, input, size >> 4, NULL, 0);
|
||||
}
|
||||
|
||||
static void run_lavu_blowfish(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
static struct AVBlowfish *blowfish;
|
||||
if (!blowfish && !(blowfish = av_blowfish_alloc()))
|
||||
fatal_error("out of memory");
|
||||
av_blowfish_init(blowfish, hardcoded_key, 16);
|
||||
av_blowfish_crypt(blowfish, output, input, size >> 3, NULL, 0);
|
||||
}
|
||||
|
||||
static void run_lavu_camellia(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
static struct AVCAMELLIA *camellia;
|
||||
if (!camellia && !(camellia = av_camellia_alloc()))
|
||||
fatal_error("out of memory");
|
||||
av_camellia_init(camellia, hardcoded_key, 128);
|
||||
av_camellia_crypt(camellia, output, input, size >> 4, NULL, 0);
|
||||
}
|
||||
|
||||
static void run_lavu_cast128(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
static struct AVCAST5 *cast;
|
||||
if (!cast && !(cast = av_cast5_alloc()))
|
||||
fatal_error("out of memory");
|
||||
av_cast5_init(cast, hardcoded_key, 128);
|
||||
av_cast5_crypt(cast, output, input, size >> 3, 0);
|
||||
}
|
||||
|
||||
static void run_lavu_twofish(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
static struct AVTWOFISH *twofish;
|
||||
if (!twofish && !(twofish = av_twofish_alloc()))
|
||||
fatal_error("out of memory");
|
||||
av_twofish_init(twofish, hardcoded_key, 128);
|
||||
av_twofish_crypt(twofish, output, input, size >> 4, NULL, 0);
|
||||
}
|
||||
|
||||
static void run_lavu_rc4(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
static struct AVRC4 *rc4;
|
||||
if (!rc4 && !(rc4 = av_rc4_alloc()))
|
||||
fatal_error("out of memory");
|
||||
av_rc4_init(rc4, hardcoded_key, 128, 0);
|
||||
av_rc4_crypt(rc4, output, input, size, NULL, 0);
|
||||
}
|
||||
|
||||
static void run_lavu_xtea(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
static struct AVXTEA *xtea;
|
||||
if (!xtea && !(xtea = av_xtea_alloc()))
|
||||
fatal_error("out of memory");
|
||||
av_xtea_init(xtea, hardcoded_key);
|
||||
av_xtea_crypt(xtea, output, input, size >> 3, NULL, 0);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* crypto: OpenSSL's libcrypto
|
||||
***************************************************************************/
|
||||
|
||||
#if (USE_EXT_LIBS) & USE_crypto
|
||||
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/ripemd.h>
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/blowfish.h>
|
||||
#include <openssl/camellia.h>
|
||||
#include <openssl/cast.h>
|
||||
#include <openssl/rc4.h>
|
||||
|
||||
#define DEFINE_CRYPTO_WRAPPER(suffix, function) \
|
||||
static void run_crypto_ ## suffix(uint8_t *output, \
|
||||
const uint8_t *input, unsigned size) \
|
||||
{ \
|
||||
function(input, size, output); \
|
||||
}
|
||||
|
||||
DEFINE_CRYPTO_WRAPPER(md5, MD5)
|
||||
DEFINE_CRYPTO_WRAPPER(sha1, SHA1)
|
||||
DEFINE_CRYPTO_WRAPPER(sha256, SHA256)
|
||||
DEFINE_CRYPTO_WRAPPER(sha512, SHA512)
|
||||
DEFINE_CRYPTO_WRAPPER(ripemd160, RIPEMD160)
|
||||
|
||||
static void run_crypto_aes128(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
AES_KEY aes;
|
||||
unsigned i;
|
||||
|
||||
AES_set_encrypt_key(hardcoded_key, 128, &aes);
|
||||
size -= 15;
|
||||
for (i = 0; i < size; i += 16)
|
||||
AES_encrypt(input + i, output + i, &aes);
|
||||
}
|
||||
|
||||
static void run_crypto_blowfish(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
BF_KEY blowfish;
|
||||
unsigned i;
|
||||
|
||||
BF_set_key(&blowfish, 16, hardcoded_key);
|
||||
for (i = 0; i < size; i += 8)
|
||||
BF_ecb_encrypt(input + i, output + i, &blowfish, 1);
|
||||
}
|
||||
|
||||
static void run_crypto_camellia(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
CAMELLIA_KEY camellia;
|
||||
unsigned i;
|
||||
|
||||
Camellia_set_key(hardcoded_key, 128, &camellia);
|
||||
size -= 15;
|
||||
for (i = 0; i < size; i += 16)
|
||||
Camellia_ecb_encrypt(input + i, output + i, &camellia, 1);
|
||||
}
|
||||
|
||||
static void run_crypto_cast128(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
CAST_KEY cast;
|
||||
unsigned i;
|
||||
|
||||
CAST_set_key(&cast, 16, hardcoded_key);
|
||||
for (i = 0; i < size; i += 8)
|
||||
CAST_ecb_encrypt(input + i, output + i, &cast, 1);
|
||||
}
|
||||
|
||||
static void run_crypto_rc4(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
RC4_KEY rc4;
|
||||
|
||||
RC4_set_key(&rc4, 16, hardcoded_key);
|
||||
RC4(&rc4, size, input, output);
|
||||
}
|
||||
|
||||
#define IMPL_USE_crypto(...) IMPL_USE(__VA_ARGS__)
|
||||
#else
|
||||
#define IMPL_USE_crypto(...) /* ignore */
|
||||
#endif
|
||||
|
||||
/***************************************************************************
|
||||
* gcrypt: GnuTLS's libgcrypt
|
||||
***************************************************************************/
|
||||
|
||||
#if (USE_EXT_LIBS) & USE_gcrypt
|
||||
|
||||
#include <gcrypt.h>
|
||||
|
||||
#define DEFINE_GCRYPT_WRAPPER(suffix, algo) \
|
||||
static void run_gcrypt_ ## suffix(uint8_t *output, \
|
||||
const uint8_t *input, unsigned size) \
|
||||
{ \
|
||||
gcry_md_hash_buffer(GCRY_MD_ ## algo, output, input, size); \
|
||||
}
|
||||
|
||||
DEFINE_GCRYPT_WRAPPER(md5, MD5)
|
||||
DEFINE_GCRYPT_WRAPPER(sha1, SHA1)
|
||||
DEFINE_GCRYPT_WRAPPER(sha256, SHA256)
|
||||
DEFINE_GCRYPT_WRAPPER(sha512, SHA512)
|
||||
DEFINE_GCRYPT_WRAPPER(ripemd160, RMD160)
|
||||
|
||||
static void run_gcrypt_aes128(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
static gcry_cipher_hd_t aes;
|
||||
if (!aes)
|
||||
gcry_cipher_open(&aes, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_ECB, 0);
|
||||
gcry_cipher_setkey(aes, hardcoded_key, 16);
|
||||
gcry_cipher_encrypt(aes, output, size, input, size);
|
||||
}
|
||||
|
||||
static void run_gcrypt_blowfish(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
static gcry_cipher_hd_t blowfish;
|
||||
if (!blowfish)
|
||||
gcry_cipher_open(&blowfish, GCRY_CIPHER_BLOWFISH, GCRY_CIPHER_MODE_ECB, 0);
|
||||
gcry_cipher_setkey(blowfish, hardcoded_key, 16);
|
||||
gcry_cipher_encrypt(blowfish, output, size, input, size);
|
||||
}
|
||||
|
||||
static void run_gcrypt_camellia(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
static gcry_cipher_hd_t camellia;
|
||||
if (!camellia)
|
||||
gcry_cipher_open(&camellia, GCRY_CIPHER_CAMELLIA128, GCRY_CIPHER_MODE_ECB, 0);
|
||||
gcry_cipher_setkey(camellia, hardcoded_key, 16);
|
||||
gcry_cipher_encrypt(camellia, output, size, input, size);
|
||||
}
|
||||
|
||||
static void run_gcrypt_cast128(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
static gcry_cipher_hd_t cast;
|
||||
if (!cast)
|
||||
gcry_cipher_open(&cast, GCRY_CIPHER_CAST5, GCRY_CIPHER_MODE_ECB, 0);
|
||||
gcry_cipher_setkey(cast, hardcoded_key, 16);
|
||||
gcry_cipher_encrypt(cast, output, size, input, size);
|
||||
}
|
||||
|
||||
static void run_gcrypt_twofish(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
static gcry_cipher_hd_t twofish;
|
||||
if (!twofish)
|
||||
gcry_cipher_open(&twofish, GCRY_CIPHER_TWOFISH128, GCRY_CIPHER_MODE_ECB, 0);
|
||||
gcry_cipher_setkey(twofish, hardcoded_key, 16);
|
||||
gcry_cipher_encrypt(twofish, output, size, input, size);
|
||||
}
|
||||
|
||||
#define IMPL_USE_gcrypt(...) IMPL_USE(__VA_ARGS__)
|
||||
#else
|
||||
#define IMPL_USE_gcrypt(...) /* ignore */
|
||||
#endif
|
||||
|
||||
/***************************************************************************
|
||||
* tomcrypt: LibTomCrypt
|
||||
***************************************************************************/
|
||||
|
||||
#if (USE_EXT_LIBS) & USE_tomcrypt
|
||||
|
||||
#include <tomcrypt.h>
|
||||
|
||||
#define DEFINE_TOMCRYPT_WRAPPER(suffix, namespace, algo) \
|
||||
static void run_tomcrypt_ ## suffix(uint8_t *output, \
|
||||
const uint8_t *input, unsigned size) \
|
||||
{ \
|
||||
hash_state md; \
|
||||
namespace ## _init(&md); \
|
||||
namespace ## _process(&md, input, size); \
|
||||
namespace ## _done(&md, output); \
|
||||
}
|
||||
|
||||
DEFINE_TOMCRYPT_WRAPPER(md5, md5, MD5)
|
||||
DEFINE_TOMCRYPT_WRAPPER(sha1, sha1, SHA1)
|
||||
DEFINE_TOMCRYPT_WRAPPER(sha256, sha256, SHA256)
|
||||
DEFINE_TOMCRYPT_WRAPPER(sha512, sha512, SHA512)
|
||||
DEFINE_TOMCRYPT_WRAPPER(ripemd128, rmd128, RIPEMD128)
|
||||
DEFINE_TOMCRYPT_WRAPPER(ripemd160, rmd160, RIPEMD160)
|
||||
|
||||
static void run_tomcrypt_aes128(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
symmetric_key aes;
|
||||
unsigned i;
|
||||
|
||||
aes_setup(hardcoded_key, 16, 0, &aes);
|
||||
size -= 15;
|
||||
for (i = 0; i < size; i += 16)
|
||||
aes_ecb_encrypt(input + i, output + i, &aes);
|
||||
}
|
||||
|
||||
static void run_tomcrypt_blowfish(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
symmetric_key blowfish;
|
||||
unsigned i;
|
||||
|
||||
blowfish_setup(hardcoded_key, 16, 0, &blowfish);
|
||||
for (i = 0; i < size; i += 8)
|
||||
blowfish_ecb_encrypt(input + i, output + i, &blowfish);
|
||||
}
|
||||
|
||||
static void run_tomcrypt_camellia(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
symmetric_key camellia;
|
||||
unsigned i;
|
||||
|
||||
camellia_setup(hardcoded_key, 16, 0, &camellia);
|
||||
size -= 15;
|
||||
for (i = 0; i < size; i += 16)
|
||||
camellia_ecb_encrypt(input + i, output + i, &camellia);
|
||||
}
|
||||
|
||||
static void run_tomcrypt_cast128(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
symmetric_key cast;
|
||||
unsigned i;
|
||||
|
||||
cast5_setup(hardcoded_key, 16, 0, &cast);
|
||||
for (i = 0; i < size; i += 8)
|
||||
cast5_ecb_encrypt(input + i, output + i, &cast);
|
||||
}
|
||||
|
||||
static void run_tomcrypt_twofish(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
symmetric_key twofish;
|
||||
unsigned i;
|
||||
|
||||
twofish_setup(hardcoded_key, 16, 0, &twofish);
|
||||
size -= 15;
|
||||
for (i = 0; i < size; i += 16)
|
||||
twofish_ecb_encrypt(input + i, output + i, &twofish);
|
||||
}
|
||||
|
||||
static void run_tomcrypt_xtea(uint8_t *output,
|
||||
const uint8_t *input, unsigned size)
|
||||
{
|
||||
symmetric_key xtea;
|
||||
unsigned i;
|
||||
|
||||
xtea_setup(hardcoded_key, 16, 0, &xtea);
|
||||
for (i = 0; i < size; i += 8)
|
||||
xtea_ecb_encrypt(input + i, output + i, &xtea);
|
||||
}
|
||||
|
||||
|
||||
#define IMPL_USE_tomcrypt(...) IMPL_USE(__VA_ARGS__)
|
||||
#else
|
||||
#define IMPL_USE_tomcrypt(...) /* ignore */
|
||||
#endif
|
||||
|
||||
/***************************************************************************
|
||||
* Driver code
|
||||
***************************************************************************/
|
||||
|
||||
static unsigned crc32(const uint8_t *data, unsigned size)
|
||||
{
|
||||
return av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, data, size);
|
||||
}
|
||||
|
||||
static void run_implementation(const uint8_t *input, uint8_t *output,
|
||||
struct hash_impl *impl, unsigned size)
|
||||
{
|
||||
uint64_t t0, t1;
|
||||
unsigned nruns = specified_runs ? specified_runs : (1 << 30) / size;
|
||||
unsigned outlen = 0, outcrc = 0;
|
||||
unsigned i, j, val;
|
||||
double mtime, ttime = 0, ttime2 = 0, stime;
|
||||
uint8_t outref[MAX_OUTPUT_SIZE];
|
||||
|
||||
if (enabled_libs && !av_stristr(enabled_libs, impl->lib) ||
|
||||
enabled_algos && !av_stristr(enabled_algos, impl->name))
|
||||
return;
|
||||
if (!sscanf(impl->output, "crc:%x", &outcrc)) {
|
||||
outlen = strlen(impl->output) / 2;
|
||||
for (i = 0; i < outlen; i++) {
|
||||
sscanf(impl->output + i * 2, "%02x", &val);
|
||||
outref[i] = val;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < 8; i++) /* heat caches */
|
||||
impl->run(output, input, size);
|
||||
for (i = 0; i < nruns; i++) {
|
||||
memset(output, 0, size); /* avoid leftovers from previous runs */
|
||||
t0 = AV_READ_TIME();
|
||||
impl->run(output, input, size);
|
||||
t1 = AV_READ_TIME();
|
||||
if (outlen ? memcmp(output, outref, outlen) :
|
||||
crc32(output, size) != outcrc) {
|
||||
fprintf(stderr, "Expected: ");
|
||||
if (outlen)
|
||||
for (j = 0; j < outlen; j++)
|
||||
fprintf(stderr, "%02x", output[j]);
|
||||
else
|
||||
fprintf(stderr, "%08x", crc32(output, size));
|
||||
fprintf(stderr, "\n");
|
||||
fatal_error("output mismatch");
|
||||
}
|
||||
mtime = (double)(t1 - t0) / size;
|
||||
ttime += mtime;
|
||||
ttime2 += mtime * mtime;
|
||||
}
|
||||
|
||||
ttime /= nruns;
|
||||
ttime2 /= nruns;
|
||||
stime = sqrt(ttime2 - ttime * ttime);
|
||||
printf("%-10s %-12s size: %7d runs: %6d time: %8.3f +- %.3f\n",
|
||||
impl->lib, impl->name, size, nruns, ttime, stime);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
#define IMPL_USE(lib, name, symbol, output) \
|
||||
{ #lib, name, run_ ## lib ## _ ## symbol, output },
|
||||
#define IMPL(lib, ...) IMPL_USE_ ## lib(lib, __VA_ARGS__)
|
||||
#define IMPL_ALL(...) \
|
||||
IMPL(lavu, __VA_ARGS__) \
|
||||
IMPL(crypto, __VA_ARGS__) \
|
||||
IMPL(gcrypt, __VA_ARGS__) \
|
||||
IMPL(tomcrypt, __VA_ARGS__)
|
||||
|
||||
struct hash_impl implementations[] = {
|
||||
IMPL_ALL("MD5", md5, "aa26ff5b895356bcffd9292ba9f89e66")
|
||||
IMPL_ALL("SHA-1", sha1, "1fd8bd1fa02f5b0fe916b0d71750726b096c5744")
|
||||
IMPL_ALL("SHA-256", sha256, "14028ac673b3087e51a1d407fbf0df4deeec8f217119e13b07bf2138f93db8c5")
|
||||
IMPL_ALL("SHA-512", sha512, "3afdd44a80d99af15c87bd724cb717243193767835ce866dd5d58c02d674bb57"
|
||||
"7c25b9e118c200a189fcd5a01ef106a4e200061f3e97dbf50ba065745fd46bef")
|
||||
IMPL(lavu, "RIPEMD-128", ripemd128, "9ab8bfba2ddccc5d99c9d4cdfb844a5f")
|
||||
IMPL(tomcrypt, "RIPEMD-128", ripemd128, "9ab8bfba2ddccc5d99c9d4cdfb844a5f")
|
||||
IMPL_ALL("RIPEMD-160", ripemd160, "62a5321e4fc8784903bb43ab7752c75f8b25af00")
|
||||
IMPL_ALL("AES-128", aes128, "crc:ff6bc888")
|
||||
IMPL_ALL("CAMELLIA", camellia, "crc:7abb59a7")
|
||||
IMPL_ALL("CAST-128", cast128, "crc:456aa584")
|
||||
IMPL_ALL("BLOWFISH", blowfish, "crc:33e8aa74")
|
||||
IMPL(lavu, "TWOFISH", twofish, "crc:9edbd5c1")
|
||||
IMPL(gcrypt, "TWOFISH", twofish, "crc:9edbd5c1")
|
||||
IMPL(tomcrypt, "TWOFISH", twofish, "crc:9edbd5c1")
|
||||
IMPL(lavu, "RC4", rc4, "crc:538d37b2")
|
||||
IMPL(crypto, "RC4", rc4, "crc:538d37b2")
|
||||
IMPL(lavu, "XTEA", xtea, "crc:931fc270")
|
||||
IMPL(tomcrypt, "XTEA", xtea, "crc:931fc270")
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
uint8_t *input = av_malloc(MAX_INPUT_SIZE * 2);
|
||||
uint8_t *output = input + MAX_INPUT_SIZE;
|
||||
unsigned i, impl, size;
|
||||
int opt;
|
||||
|
||||
while ((opt = getopt(argc, argv, "hl:a:r:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'l':
|
||||
enabled_libs = optarg;
|
||||
break;
|
||||
case 'a':
|
||||
enabled_algos = optarg;
|
||||
break;
|
||||
case 'r':
|
||||
specified_runs = strtol(optarg, NULL, 0);
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
fprintf(stderr, "Usage: %s [-l libs] [-a algos] [-r runs]\n",
|
||||
argv[0]);
|
||||
if ((USE_EXT_LIBS)) {
|
||||
char buf[1024];
|
||||
snprintf(buf, sizeof(buf), "%s%s%s",
|
||||
((USE_EXT_LIBS) & USE_crypto) ? "+crypto" : "",
|
||||
((USE_EXT_LIBS) & USE_gcrypt) ? "+gcrypt" : "",
|
||||
((USE_EXT_LIBS) & USE_tomcrypt) ? "+tomcrypt" : "");
|
||||
fprintf(stderr, "Built with the following external libraries:\n"
|
||||
"make VERSUS=%s\n", buf + 1);
|
||||
} else {
|
||||
fprintf(stderr, "Built without external libraries; use\n"
|
||||
"make VERSUS=crypto+gcrypt+tomcrypt tools/crypto_bench\n"
|
||||
"to enable them.\n");
|
||||
}
|
||||
exit(opt != 'h');
|
||||
}
|
||||
}
|
||||
|
||||
if (!input)
|
||||
fatal_error("out of memory");
|
||||
for (i = 0; i < MAX_INPUT_SIZE; i += 4)
|
||||
AV_WB32(input + i, i);
|
||||
|
||||
size = MAX_INPUT_SIZE;
|
||||
for (impl = 0; impl < FF_ARRAY_ELEMS(implementations); impl++)
|
||||
run_implementation(input, output, &implementations[impl], size);
|
||||
|
||||
av_free(input);
|
||||
|
||||
return 0;
|
||||
}
|
148
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/cws2fws.c
Normal file
148
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/cws2fws.c
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* cws2fws by Alex Beregszaszi
|
||||
* This file is placed in the public domain.
|
||||
* Use the program however you see fit.
|
||||
*
|
||||
* This utility converts compressed Macromedia Flash files to uncompressed ones.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if HAVE_IO_H
|
||||
#include <io.h>
|
||||
#endif
|
||||
#include <zlib.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
#define dbgprintf printf
|
||||
#else
|
||||
#define dbgprintf(...) do { if (0) printf(__VA_ARGS__); } while (0)
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fd_in, fd_out, comp_len, uncomp_len, i, last_out;
|
||||
char buf_in[1024], buf_out[65536];
|
||||
z_stream zstream;
|
||||
struct stat statbuf;
|
||||
int ret = 1;
|
||||
|
||||
if (argc < 3) {
|
||||
printf("Usage: %s <infile.swf> <outfile.swf>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fd_in = open(argv[1], O_RDONLY);
|
||||
if (fd_in < 0) {
|
||||
perror("Error opening input file");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fd_out = open(argv[2], O_WRONLY | O_CREAT, 00644);
|
||||
if (fd_out < 0) {
|
||||
perror("Error opening output file");
|
||||
close(fd_in);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (read(fd_in, &buf_in, 8) != 8) {
|
||||
printf("Header error\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S') {
|
||||
printf("Not a compressed flash file\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (fstat(fd_in, &statbuf) < 0) {
|
||||
perror("fstat failed");
|
||||
return 1;
|
||||
}
|
||||
comp_len = statbuf.st_size;
|
||||
uncomp_len = buf_in[4] | (buf_in[5] << 8) | (buf_in[6] << 16) | (buf_in[7] << 24);
|
||||
|
||||
printf("Compressed size: %d Uncompressed size: %d\n",
|
||||
comp_len - 4, uncomp_len - 4);
|
||||
|
||||
// write out modified header
|
||||
buf_in[0] = 'F';
|
||||
if (write(fd_out, &buf_in, 8) < 8) {
|
||||
perror("Error writing output file");
|
||||
goto out;
|
||||
}
|
||||
|
||||
zstream.zalloc = NULL;
|
||||
zstream.zfree = NULL;
|
||||
zstream.opaque = NULL;
|
||||
if (inflateInit(&zstream) != Z_OK) {
|
||||
fprintf(stderr, "inflateInit failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < comp_len - 8;) {
|
||||
int ret, len = read(fd_in, &buf_in, 1024);
|
||||
|
||||
dbgprintf("read %d bytes\n", len);
|
||||
|
||||
last_out = zstream.total_out;
|
||||
|
||||
zstream.next_in = &buf_in[0];
|
||||
zstream.avail_in = len;
|
||||
zstream.next_out = &buf_out[0];
|
||||
zstream.avail_out = 65536;
|
||||
|
||||
ret = inflate(&zstream, Z_SYNC_FLUSH);
|
||||
if (ret != Z_STREAM_END && ret != Z_OK) {
|
||||
printf("Error while decompressing: %d\n", ret);
|
||||
inflateEnd(&zstream);
|
||||
goto out;
|
||||
}
|
||||
|
||||
dbgprintf("a_in: %d t_in: %lu a_out: %d t_out: %lu -- %lu out\n",
|
||||
zstream.avail_in, zstream.total_in, zstream.avail_out,
|
||||
zstream.total_out, zstream.total_out - last_out);
|
||||
|
||||
if (write(fd_out, &buf_out, zstream.total_out - last_out) <
|
||||
zstream.total_out - last_out) {
|
||||
perror("Error writing output file");
|
||||
inflateEnd(&zstream);
|
||||
goto out;
|
||||
}
|
||||
|
||||
i += len;
|
||||
|
||||
if (ret == Z_STREAM_END || ret == Z_BUF_ERROR)
|
||||
break;
|
||||
}
|
||||
|
||||
if (zstream.total_out != uncomp_len - 8) {
|
||||
printf("Size mismatch (%lu != %d), updating header...\n",
|
||||
zstream.total_out, uncomp_len - 8);
|
||||
|
||||
buf_in[0] = (zstream.total_out + 8) & 0xff;
|
||||
buf_in[1] = ((zstream.total_out + 8) >> 8) & 0xff;
|
||||
buf_in[2] = ((zstream.total_out + 8) >> 16) & 0xff;
|
||||
buf_in[3] = ((zstream.total_out + 8) >> 24) & 0xff;
|
||||
|
||||
if ( lseek(fd_out, 4, SEEK_SET) < 0
|
||||
|| write(fd_out, &buf_in, 4) < 4) {
|
||||
perror("Error writing output file");
|
||||
inflateEnd(&zstream);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
inflateEnd(&zstream);
|
||||
out:
|
||||
close(fd_in);
|
||||
close(fd_out);
|
||||
return ret;
|
||||
}
|
127
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/dvd2concat
Normal file
127
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/dvd2concat
Normal file
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
# Copyright (c) 2014 Nicolas George
|
||||
#
|
||||
# This file is part of FFmpeg.
|
||||
#
|
||||
# FFmpeg is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public License
|
||||
# as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# FFmpeg 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 Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=head1 NAME
|
||||
|
||||
dvd2concat - create a concat script for a DVD title
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
tools/dvd2concat I<path/to/dvd/structure> > I<file.concat>
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This script uses B<lsdvd> to produce concat script for a DVD title.
|
||||
The resulting script can be used to play the DVD using B<ffplay>, to
|
||||
transcode it using B<ffmpeg> or any other similar use.
|
||||
|
||||
I<path/to/dvd/structure> is the path to the DVD structure hierarchy; it
|
||||
normally contains a directory named B<VIDEO_TS>. It must not be encrypted
|
||||
with CSS.
|
||||
|
||||
I<file.concat> is the output file. It can be used a input to ffmpeg.
|
||||
It will require the B<-safe 0> option.
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Getopt::Long ":config" => "require_order";
|
||||
use Pod::Usage;
|
||||
|
||||
my $title;
|
||||
|
||||
GetOptions (
|
||||
"help|usage|?|h" => sub { pod2usage({ -verbose => 1, -exitval => 0 }) },
|
||||
"manpage|m" => sub { pod2usage({ -verbose => 2, -exitval => 0 }) },
|
||||
"title|t=i" => \$title,
|
||||
) and @ARGV == 1 or pod2usage({ -verbose => 1, -exitval => 1 });
|
||||
my ($path) = @ARGV;
|
||||
|
||||
my $lsdvd_message =
|
||||
"Make sure your lsdvd version has the two following patches applied:\n" .
|
||||
"http://sourceforge.net/p/lsdvd/feature-requests/1/\n" .
|
||||
"https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=603826\n";
|
||||
|
||||
my $lsdvd = do {
|
||||
open my $l, "-|", "lsdvd", "-Op", "-x", $path
|
||||
or die "You need to install lsdvd for this script to work.\n$lsdvd_message";
|
||||
local $/;
|
||||
<$l>;
|
||||
};
|
||||
my %lsdvd = eval $lsdvd;
|
||||
die $@ if $@;
|
||||
|
||||
if (!defined $title) {
|
||||
$title = $lsdvd{longest_track};
|
||||
warn "Using longest title $title\n";
|
||||
}
|
||||
my $track = $lsdvd{track}[$title - 1]
|
||||
or die "Title $title does not exist (1-", scalar(@{$lsdvd{track}}), ")\n";
|
||||
my $vts_base = sprintf "%s/VIDEO_TS/VTS_%02d_", $path, $track->{vts};
|
||||
my @frag;
|
||||
for my $i (1 .. 9) {
|
||||
my $file = sprintf "%s%d.VOB", $vts_base, $i;
|
||||
my $size = -s $file or last;
|
||||
push @frag, { file => $file, size => $size >> 11 };
|
||||
}
|
||||
|
||||
my $concat = "ffconcat version 1.0\n";
|
||||
$concat .= "\nstream\nexact_stream_id 0x1E0\n";
|
||||
for my $audio (@{$track->{audio}}) {
|
||||
$concat .= "\nstream\nexact_stream_id " . $audio->{streamid} . "\n";
|
||||
}
|
||||
for my $subp (@{$track->{subp}}) {
|
||||
$concat .= "\nstream\nexact_stream_id " . $subp->{streamid} . "\n";
|
||||
}
|
||||
for my $cell (@{$track->{cell}}) {
|
||||
my $off = $cell->{first_sector};
|
||||
die "Your lsdvd version does not print cell sectors.\n$lsdvd_message"
|
||||
unless defined $off;
|
||||
my $size = $cell->{last_sector} + 1 - $cell->{first_sector};
|
||||
|
||||
my $frag = 0;
|
||||
while ($frag < @frag) {
|
||||
last if $off < $frag[$frag]->{size};
|
||||
$off -= $frag[$frag++]->{size};
|
||||
}
|
||||
die "Cell beyond VOB data\n" unless $frag < @frag;
|
||||
my $cur_off = $off;
|
||||
my $cur_size = $size;
|
||||
my @files;
|
||||
while ($cur_size > $frag[$frag]->{size} - $cur_off) {
|
||||
push @files, $frag[$frag]->{file};
|
||||
$cur_size -= $frag[$frag]->{size} - $cur_off;
|
||||
$cur_off = 0;
|
||||
die "Cell end beyond VOB data\n" unless ++$frag < @frag;
|
||||
}
|
||||
push @files, $frag[$frag]->{file};
|
||||
my $file = @files == 1 ? $files[0] : "concat:" . join("|", @files);
|
||||
my $start = $off << 11;
|
||||
my $end = ($off + $size) << 11;
|
||||
$file = "subfile,,start,${start},end,${end},,:$file";
|
||||
|
||||
my $dur = int(1000 * $cell->{length});
|
||||
$concat .= sprintf "\nfile '%s'\nduration %02d:%02d:%02d.%03d\n", $file,
|
||||
int($dur / 3600000), int($dur / 60000) % 60, int($dur / 1000) % 60,
|
||||
$dur % 1000;
|
||||
}
|
||||
|
||||
print $concat;
|
143
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/enum_options.c
Normal file
143
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/enum_options.c
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Anton Khirnov
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* enumerate avoptions and format them in texinfo format
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "libavformat/avformat.h"
|
||||
#include "libavcodec/avcodec.h"
|
||||
#include "libavutil/log.h"
|
||||
#include "libavutil/opt.h"
|
||||
|
||||
static void print_usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: enum_options type\n"
|
||||
"type: format codec\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void print_option(const AVClass *class, const AVOption *o)
|
||||
{
|
||||
printf("@item -%s @var{", o->name);
|
||||
switch (o->type) {
|
||||
case FF_OPT_TYPE_BINARY: printf("hexadecimal string"); break;
|
||||
case FF_OPT_TYPE_STRING: printf("string"); break;
|
||||
case FF_OPT_TYPE_INT:
|
||||
case FF_OPT_TYPE_INT64: printf("integer"); break;
|
||||
case FF_OPT_TYPE_FLOAT:
|
||||
case FF_OPT_TYPE_DOUBLE: printf("float"); break;
|
||||
case FF_OPT_TYPE_RATIONAL: printf("rational number"); break;
|
||||
case FF_OPT_TYPE_FLAGS: printf("flags"); break;
|
||||
default: printf("value"); break;
|
||||
}
|
||||
printf("} (@emph{");
|
||||
|
||||
if (o->flags & AV_OPT_FLAG_ENCODING_PARAM) {
|
||||
printf("input");
|
||||
if (o->flags & AV_OPT_FLAG_ENCODING_PARAM)
|
||||
printf("/");
|
||||
}
|
||||
if (o->flags & AV_OPT_FLAG_ENCODING_PARAM)
|
||||
printf("output");
|
||||
|
||||
printf("})\n");
|
||||
if (o->help)
|
||||
printf("%s\n", o->help);
|
||||
|
||||
if (o->unit) {
|
||||
const AVOption *u = NULL;
|
||||
printf("\nPossible values:\n@table @samp\n");
|
||||
|
||||
while ((u = av_next_option(&class, u)))
|
||||
if (u->type == FF_OPT_TYPE_CONST && u->unit && !strcmp(u->unit, o->unit))
|
||||
printf("@item %s\n%s\n", u->name, u->help ? u->help : "");
|
||||
printf("@end table\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void show_opts(const AVClass *class)
|
||||
{
|
||||
const AVOption *o = NULL;
|
||||
|
||||
printf("@table @option\n");
|
||||
while ((o = av_next_option(&class, o)))
|
||||
if (o->type != FF_OPT_TYPE_CONST)
|
||||
print_option(class, o);
|
||||
printf("@end table\n");
|
||||
}
|
||||
|
||||
static void show_format_opts(void)
|
||||
{
|
||||
AVInputFormat *iformat = NULL;
|
||||
AVOutputFormat *oformat = NULL;
|
||||
|
||||
printf("@section Generic format AVOptions\n");
|
||||
show_opts(avformat_get_class());
|
||||
|
||||
printf("@section Format-specific AVOptions\n");
|
||||
while ((iformat = av_iformat_next(iformat))) {
|
||||
if (!iformat->priv_class)
|
||||
continue;
|
||||
printf("@subsection %s AVOptions\n", iformat->priv_class->class_name);
|
||||
show_opts(iformat->priv_class);
|
||||
}
|
||||
while ((oformat = av_oformat_next(oformat))) {
|
||||
if (!oformat->priv_class)
|
||||
continue;
|
||||
printf("@subsection %s AVOptions\n", oformat->priv_class->class_name);
|
||||
show_opts(oformat->priv_class);
|
||||
}
|
||||
}
|
||||
|
||||
static void show_codec_opts(void)
|
||||
{
|
||||
AVCodec *c = NULL;
|
||||
|
||||
printf("@section Generic codec AVOptions\n");
|
||||
show_opts(avcodec_get_class());
|
||||
|
||||
printf("@section Codec-specific AVOptions\n");
|
||||
while ((c = av_codec_next(c))) {
|
||||
if (!c->priv_class)
|
||||
continue;
|
||||
printf("@subsection %s AVOptions\n", c->priv_class->class_name);
|
||||
show_opts(c->priv_class);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
print_usage();
|
||||
|
||||
av_register_all();
|
||||
|
||||
if (!strcmp(argv[1], "format"))
|
||||
show_format_opts();
|
||||
else if (!strcmp(argv[1], "codec"))
|
||||
show_codec_opts();
|
||||
else
|
||||
print_usage();
|
||||
|
||||
return 0;
|
||||
}
|
180
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/ffescape.c
Normal file
180
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/ffescape.c
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Stefano Sabatini
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h> /* getopt */
|
||||
#endif
|
||||
|
||||
#include "libavutil/log.h"
|
||||
#include "libavutil/bprint.h"
|
||||
|
||||
#if !HAVE_GETOPT
|
||||
#include "compat/getopt.c"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file
|
||||
* escaping utility
|
||||
*/
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Escape an input string, adopting the av_get_token() escaping logic\n");
|
||||
printf("usage: ffescape [OPTIONS]\n");
|
||||
printf("\n"
|
||||
"Options:\n"
|
||||
"-e echo each input line on output\n"
|
||||
"-f flag select an escape flag, can assume the values 'whitespace' and 'strict'\n"
|
||||
"-h print this help\n"
|
||||
"-i INFILE set INFILE as input file, stdin if omitted\n"
|
||||
"-l LEVEL set the number of escaping levels, 1 if omitted\n"
|
||||
"-m ESCAPE_MODE select escape mode between 'auto', 'backslash', 'quote'\n"
|
||||
"-o OUTFILE set OUTFILE as output file, stdout if omitted\n"
|
||||
"-p PROMPT set output prompt, is '=> ' by default\n"
|
||||
"-s SPECIAL_CHARS set the list of special characters\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
AVBPrint src;
|
||||
char *src_buf, *dst_buf;
|
||||
const char *outfilename = NULL, *infilename = NULL;
|
||||
FILE *outfile = NULL, *infile = NULL;
|
||||
const char *prompt = "=> ";
|
||||
enum AVEscapeMode escape_mode = AV_ESCAPE_MODE_AUTO;
|
||||
int escape_flags = 0;
|
||||
int level = 1;
|
||||
int echo = 0;
|
||||
char *special_chars = NULL;
|
||||
int c;
|
||||
|
||||
while ((c = getopt(argc, argv, "ef:hi:l:o:m:p:s:")) != -1) {
|
||||
switch (c) {
|
||||
case 'e':
|
||||
echo = 1;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
return 0;
|
||||
case 'i':
|
||||
infilename = optarg;
|
||||
break;
|
||||
case 'f':
|
||||
if (!strcmp(optarg, "whitespace")) escape_flags |= AV_ESCAPE_FLAG_WHITESPACE;
|
||||
else if (!strcmp(optarg, "strict")) escape_flags |= AV_ESCAPE_FLAG_STRICT;
|
||||
else {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Invalid value '%s' for option -f, "
|
||||
"valid arguments are 'whitespace', and 'strict'\n", optarg);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case 'l':
|
||||
{
|
||||
char *tail;
|
||||
long int li = strtol(optarg, &tail, 10);
|
||||
if (*tail || li > INT_MAX || li < 0) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Invalid value '%s' for option -l, argument must be a non negative integer\n",
|
||||
optarg);
|
||||
return 1;
|
||||
}
|
||||
level = li;
|
||||
break;
|
||||
}
|
||||
case 'm':
|
||||
if (!strcmp(optarg, "auto")) escape_mode = AV_ESCAPE_MODE_AUTO;
|
||||
else if (!strcmp(optarg, "backslash")) escape_mode = AV_ESCAPE_MODE_BACKSLASH;
|
||||
else if (!strcmp(optarg, "quote")) escape_mode = AV_ESCAPE_MODE_QUOTE;
|
||||
else {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Invalid value '%s' for option -m, "
|
||||
"valid arguments are 'backslash', and 'quote'\n", optarg);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
outfilename = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
prompt = optarg;
|
||||
break;
|
||||
case 's':
|
||||
special_chars = optarg;
|
||||
break;
|
||||
case '?':
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!infilename || !strcmp(infilename, "-")) {
|
||||
infilename = "stdin";
|
||||
infile = stdin;
|
||||
} else {
|
||||
infile = fopen(infilename, "r");
|
||||
}
|
||||
if (!infile) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Impossible to open input file '%s': %s\n", infilename, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!outfilename || !strcmp(outfilename, "-")) {
|
||||
outfilename = "stdout";
|
||||
outfile = stdout;
|
||||
} else {
|
||||
outfile = fopen(outfilename, "w");
|
||||
}
|
||||
if (!outfile) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Impossible to open output file '%s': %s\n", outfilename, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* grab the input and store it in src */
|
||||
av_bprint_init(&src, 1, AV_BPRINT_SIZE_UNLIMITED);
|
||||
while ((c = fgetc(infile)) != EOF)
|
||||
av_bprint_chars(&src, c, 1);
|
||||
av_bprint_chars(&src, 0, 1);
|
||||
|
||||
if (!av_bprint_is_complete(&src)) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Could not allocate a buffer for the source string\n");
|
||||
av_bprint_finalize(&src, NULL);
|
||||
return 1;
|
||||
}
|
||||
av_bprint_finalize(&src, &src_buf);
|
||||
|
||||
if (echo)
|
||||
fprintf(outfile, "%s", src_buf);
|
||||
|
||||
/* escape */
|
||||
dst_buf = src_buf;
|
||||
while (level--) {
|
||||
if (av_escape(&dst_buf, src_buf, special_chars, escape_mode, escape_flags) < 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Could not escape string\n");
|
||||
return 1;
|
||||
}
|
||||
av_free(src_buf);
|
||||
src_buf = dst_buf;
|
||||
}
|
||||
|
||||
fprintf(outfile, "%s%s", prompt, dst_buf);
|
||||
av_free(dst_buf);
|
||||
return 0;
|
||||
}
|
139
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/ffeval.c
Normal file
139
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/ffeval.c
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Stefano Sabatini
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h> /* getopt */
|
||||
#endif
|
||||
|
||||
#include "libavutil/eval.h"
|
||||
#include "libavutil/mem.h"
|
||||
|
||||
#if !HAVE_GETOPT
|
||||
#include "compat/getopt.c"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file
|
||||
* simple arithmetic expression evaluator
|
||||
*/
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Simple expression evalutor, please *don't* turn me to a feature-complete language interpreter\n");
|
||||
printf("usage: ffeval [OPTIONS]\n");
|
||||
printf("\n"
|
||||
"Options:\n"
|
||||
"-e echo each input line on output\n"
|
||||
"-h print this help\n"
|
||||
"-i INFILE set INFILE as input file, stdin if omitted\n"
|
||||
"-o OUTFILE set OUTFILE as output file, stdout if omitted\n"
|
||||
"-p PROMPT set output prompt\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int buf_size = 0;
|
||||
char *buf = NULL;
|
||||
const char *outfilename = NULL, *infilename = NULL;
|
||||
FILE *outfile = NULL, *infile = NULL;
|
||||
const char *prompt = "=> ";
|
||||
int count = 0, echo = 0;
|
||||
int c;
|
||||
|
||||
#define GROW_ARRAY() \
|
||||
do { \
|
||||
if (!av_dynarray2_add((void **)&buf, &buf_size, 1, NULL)) { \
|
||||
av_log(NULL, AV_LOG_ERROR, \
|
||||
"Memory allocation problem occurred\n"); \
|
||||
return 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
GROW_ARRAY();
|
||||
while ((c = getopt(argc, argv, "ehi:o:p:")) != -1) {
|
||||
switch (c) {
|
||||
case 'e':
|
||||
echo = 1;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
return 0;
|
||||
case 'i':
|
||||
infilename = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
outfilename = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
prompt = optarg;
|
||||
break;
|
||||
case '?':
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!infilename || !strcmp(infilename, "-")) {
|
||||
infilename = "stdin";
|
||||
infile = stdin;
|
||||
} else {
|
||||
infile = fopen(infilename, "r");
|
||||
}
|
||||
if (!infile) {
|
||||
fprintf(stderr, "Impossible to open input file '%s': %s\n", infilename, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!outfilename || !strcmp(outfilename, "-")) {
|
||||
outfilename = "stdout";
|
||||
outfile = stdout;
|
||||
} else {
|
||||
outfile = fopen(outfilename, "w");
|
||||
}
|
||||
if (!outfile) {
|
||||
fprintf(stderr, "Impossible to open output file '%s': %s\n", outfilename, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
while ((c = fgetc(infile)) != EOF) {
|
||||
if (c == '\n') {
|
||||
double d;
|
||||
|
||||
buf[count] = 0;
|
||||
if (buf[0] != '#') {
|
||||
int ret = av_expr_parse_and_eval(&d, buf,
|
||||
NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, 0, NULL);
|
||||
if (echo)
|
||||
fprintf(outfile, "%s ", buf);
|
||||
if (ret >= 0) fprintf(outfile, "%s%f\n", prompt, d);
|
||||
else fprintf(outfile, "%s%f (%s)\n", prompt, d, av_err2str(ret));
|
||||
}
|
||||
count = 0;
|
||||
} else {
|
||||
if (count >= buf_size-1)
|
||||
GROW_ARRAY();
|
||||
buf[count++] = c;
|
||||
}
|
||||
}
|
||||
|
||||
av_free(buf);
|
||||
return 0;
|
||||
}
|
152
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/ffhash.c
Normal file
152
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/ffhash.c
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (c) 2002 Fabrice Bellard
|
||||
* Copyright (c) 2013 Michael Niedermayer
|
||||
* Copyright (c) 2013 James Almer
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "libavutil/avstring.h"
|
||||
#include "libavutil/error.h"
|
||||
#include "libavutil/hash.h"
|
||||
#include "libavutil/mem.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if HAVE_IO_H
|
||||
#include <io.h>
|
||||
#endif
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define SIZE 65536
|
||||
|
||||
static struct AVHashContext *hash;
|
||||
static int out_b64;
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
int i = 0;
|
||||
const char *name;
|
||||
|
||||
printf("usage: ffhash [b64:]algorithm [input]...\n");
|
||||
printf("Supported hash algorithms:");
|
||||
do {
|
||||
name = av_hash_names(i);
|
||||
if (name)
|
||||
printf(" %s", name);
|
||||
i++;
|
||||
} while(name);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void finish(void)
|
||||
{
|
||||
char res[2 * AV_HASH_MAX_SIZE + 4];
|
||||
|
||||
printf("%s=", av_hash_get_name(hash));
|
||||
if (out_b64) {
|
||||
av_hash_final_b64(hash, res, sizeof(res));
|
||||
printf("b64:%s", res);
|
||||
} else {
|
||||
av_hash_final_hex(hash, res, sizeof(res));
|
||||
printf("0x%s", res);
|
||||
}
|
||||
}
|
||||
|
||||
static int check(char *file)
|
||||
{
|
||||
uint8_t buffer[SIZE];
|
||||
int fd, flags = O_RDONLY;
|
||||
int ret = 0;
|
||||
|
||||
#ifdef O_BINARY
|
||||
flags |= O_BINARY;
|
||||
#endif
|
||||
if (file) fd = open(file, flags);
|
||||
else fd = 0;
|
||||
if (fd == -1) {
|
||||
printf("%s=OPEN-FAILED: %s:", av_hash_get_name(hash), strerror(errno));
|
||||
ret = 1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
av_hash_init(hash);
|
||||
for (;;) {
|
||||
int size = read(fd, buffer, SIZE);
|
||||
if (size < 0) {
|
||||
int err = errno;
|
||||
close(fd);
|
||||
finish();
|
||||
printf("+READ-FAILED: %s", strerror(err));
|
||||
ret = 2;
|
||||
goto end;
|
||||
} else if(!size)
|
||||
break;
|
||||
av_hash_update(hash, buffer, size);
|
||||
}
|
||||
close(fd);
|
||||
|
||||
finish();
|
||||
end:
|
||||
if (file)
|
||||
printf(" *%s", file);
|
||||
printf("\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int ret = 0;
|
||||
const char *hash_name;
|
||||
|
||||
if (argc == 1) {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
hash_name = argv[1];
|
||||
out_b64 = av_strstart(hash_name, "b64:", &hash_name);
|
||||
if ((ret = av_hash_alloc(&hash, hash_name)) < 0) {
|
||||
switch(ret) {
|
||||
case AVERROR(EINVAL):
|
||||
printf("Invalid hash type: %s\n", hash_name);
|
||||
break;
|
||||
case AVERROR(ENOMEM):
|
||||
printf("%s\n", strerror(errno));
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 2; i < argc; i++)
|
||||
ret |= check(argv[i]);
|
||||
|
||||
if (argc < 3)
|
||||
ret |= check(NULL);
|
||||
|
||||
av_hash_freep(&hash);
|
||||
|
||||
return ret;
|
||||
}
|
124
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/fourcc2pixfmt.c
Normal file
124
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/fourcc2pixfmt.c
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Stefano Sabatini
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h> /* getopt */
|
||||
#endif
|
||||
|
||||
#include "libavutil/pixdesc.h"
|
||||
#include "libavcodec/avcodec.h"
|
||||
#include "libavutil/common.h"
|
||||
#include "libavcodec/raw.h"
|
||||
|
||||
#undef printf
|
||||
#undef fprintf
|
||||
|
||||
#if !HAVE_GETOPT
|
||||
#include "compat/getopt.c"
|
||||
#endif
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Show the relationships between rawvideo pixel formats and FourCC tags.\n");
|
||||
printf("usage: fourcc2pixfmt [OPTIONS]\n");
|
||||
printf("\n"
|
||||
"Options:\n"
|
||||
"-l list the pixel format for each fourcc\n"
|
||||
"-L list the fourccs for each pixel format\n"
|
||||
"-p PIX_FMT given a pixel format, print the list of associated fourccs (one per line)\n"
|
||||
"-h print this help\n");
|
||||
}
|
||||
|
||||
static void print_pix_fmt_fourccs(enum AVPixelFormat pix_fmt, const PixelFormatTag *pix_fmt_tags, char sep)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++) {
|
||||
if (pix_fmt_tags[i].pix_fmt == pix_fmt) {
|
||||
char buf[32];
|
||||
av_get_codec_tag_string(buf, sizeof(buf), pix_fmt_tags[i].fourcc);
|
||||
printf("%s%c", buf, sep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, list_fourcc_pix_fmt = 0, list_pix_fmt_fourccs = 0;
|
||||
const PixelFormatTag *pix_fmt_tags = avpriv_get_raw_pix_fmt_tags();
|
||||
const char *pix_fmt_name = NULL;
|
||||
char c;
|
||||
|
||||
if (argc == 1) {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
while ((c = getopt(argc, argv, "hp:lL")) != -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
usage();
|
||||
return 0;
|
||||
case 'l':
|
||||
list_fourcc_pix_fmt = 1;
|
||||
break;
|
||||
case 'L':
|
||||
list_pix_fmt_fourccs = 1;
|
||||
break;
|
||||
case 'p':
|
||||
pix_fmt_name = optarg;
|
||||
break;
|
||||
case '?':
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (list_fourcc_pix_fmt) {
|
||||
for (i = 0; pix_fmt_tags[i].pix_fmt != AV_PIX_FMT_NONE; i++) {
|
||||
char buf[32];
|
||||
av_get_codec_tag_string(buf, sizeof(buf), pix_fmt_tags[i].fourcc);
|
||||
printf("%s: %s\n", buf, av_get_pix_fmt_name(pix_fmt_tags[i].pix_fmt));
|
||||
}
|
||||
}
|
||||
|
||||
if (list_pix_fmt_fourccs) {
|
||||
for (i = 0; av_pix_fmt_desc_get(i); i++) {
|
||||
const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(i);
|
||||
if (!pix_desc->name || pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
|
||||
continue;
|
||||
printf("%s: ", pix_desc->name);
|
||||
print_pix_fmt_fourccs(i, pix_fmt_tags, ' ');
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (pix_fmt_name) {
|
||||
enum AVPixelFormat pix_fmt = av_get_pix_fmt(pix_fmt_name);
|
||||
if (pix_fmt == AV_PIX_FMT_NONE) {
|
||||
fprintf(stderr, "Invalid pixel format selected '%s'\n", pix_fmt_name);
|
||||
return 1;
|
||||
}
|
||||
print_pix_fmt_fourccs(pix_fmt, pix_fmt_tags, '\n');
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
121
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/gen-rc
Normal file
121
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/gen-rc
Normal file
@@ -0,0 +1,121 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2012 James Almer
|
||||
# Copyright (c) 2013 Tiancheng "Timothy" Gu
|
||||
#
|
||||
# This file is part of FFmpeg.
|
||||
#
|
||||
# FFmpeg is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# FFmpeg 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 Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
## Help
|
||||
die() {
|
||||
cat <<EOF >&2
|
||||
This script is used to generate Windows resources file for the FFmpeg libraries.
|
||||
The output .rc file is to be compiled by windres(1). It is mainly useful for
|
||||
FFmpeg developers to tweak and regenerate all resources files at once.
|
||||
|
||||
Usage: $0 <libname> <comment>
|
||||
|
||||
The script will output the file to '<libname>/<libname-without-lib>res.rc'.
|
||||
|
||||
Example: $0 libavcodec 'FFmpeg codecs library'
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Script to generate all:
|
||||
# (to remove prefix '# ' and add 'tools/' as prefix: sed -r 's/^.{2}/tools\//')
|
||||
# gen-rc libavutil "FFmpeg utility library"
|
||||
# gen-rc libavcodec "FFmpeg codec library"
|
||||
# gen-rc libavformat "FFmpeg container format library"
|
||||
# gen-rc libavdevice "FFmpeg device handling library"
|
||||
# gen-rc libavfilter "FFmpeg audio/video filtering library"
|
||||
# gen-rc libpostproc "FFmpeg postprocessing library"
|
||||
# gen-rc libavresample "Libav audio resampling library"
|
||||
# gen-rc libswscale "FFmpeg image rescaling library"
|
||||
# gen-rc libswresample "FFmpeg audio resampling library"
|
||||
|
||||
## Sanity checks and argument parsing
|
||||
if test $# -lt 2 || test $# -gt 3; then
|
||||
die
|
||||
fi
|
||||
|
||||
name=$1
|
||||
shortname=${name#lib}
|
||||
comment=$2
|
||||
capname=`echo $name | awk '{print toupper($0)}'`
|
||||
version=${capname}_VERSION
|
||||
|
||||
mkdir -p "$name"
|
||||
output="$name/${shortname}res.rc"
|
||||
|
||||
## REAL magic
|
||||
cat <<EOF > $output
|
||||
/*
|
||||
* Windows resource file for $name
|
||||
*
|
||||
* Copyright (C) 2012 James Almer
|
||||
* Copyright (C) 2013 Tiancheng "Timothy" Gu
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include "$name/version.h"
|
||||
#include "libavutil/ffversion.h"
|
||||
#include "config.h"
|
||||
|
||||
1 VERSIONINFO
|
||||
FILEVERSION ${version}_MAJOR, ${version}_MINOR, ${version}_MICRO, 0
|
||||
PRODUCTVERSION ${version}_MAJOR, ${version}_MINOR, ${version}_MICRO, 0
|
||||
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
|
||||
FILEOS VOS_NT_WINDOWS32
|
||||
FILETYPE VFT_DLL
|
||||
{
|
||||
BLOCK "StringFileInfo"
|
||||
{
|
||||
BLOCK "040904B0"
|
||||
{
|
||||
VALUE "CompanyName", "FFmpeg Project"
|
||||
VALUE "FileDescription", "$comment"
|
||||
VALUE "FileVersion", AV_STRINGIFY($version)
|
||||
VALUE "InternalName", "$name"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2000-" AV_STRINGIFY(CONFIG_THIS_YEAR) " FFmpeg Project"
|
||||
VALUE "OriginalFilename", "$shortname" BUILDSUF "-" AV_STRINGIFY(${version}_MAJOR) SLIBSUF
|
||||
VALUE "ProductName", "FFmpeg"
|
||||
VALUE "ProductVersion", FFMPEG_VERSION
|
||||
}
|
||||
}
|
||||
|
||||
BLOCK "VarFileInfo"
|
||||
{
|
||||
VALUE "Translation", 0x0409, 0x04B0
|
||||
}
|
||||
}
|
||||
EOF
|
206
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/graph2dot.c
Normal file
206
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/graph2dot.c
Normal file
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2010 Stefano Sabatini
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h> /* getopt */
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libavutil/channel_layout.h"
|
||||
#include "libavutil/mem.h"
|
||||
#include "libavutil/pixdesc.h"
|
||||
#include "libavfilter/avfilter.h"
|
||||
|
||||
#if !HAVE_GETOPT
|
||||
#include "compat/getopt.c"
|
||||
#endif
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Convert a libavfilter graph to a dot file.\n");
|
||||
printf("Usage: graph2dot [OPTIONS]\n");
|
||||
printf("\n"
|
||||
"Options:\n"
|
||||
"-i INFILE set INFILE as input file, stdin if omitted\n"
|
||||
"-o OUTFILE set OUTFILE as output file, stdout if omitted\n"
|
||||
"-h print this help\n");
|
||||
}
|
||||
|
||||
struct line {
|
||||
char data[256];
|
||||
struct line *next;
|
||||
};
|
||||
|
||||
static void print_digraph(FILE *outfile, AVFilterGraph *graph)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
fprintf(outfile, "digraph G {\n");
|
||||
fprintf(outfile, "node [shape=box]\n");
|
||||
fprintf(outfile, "rankdir=LR\n");
|
||||
|
||||
for (i = 0; i < graph->nb_filters; i++) {
|
||||
char filter_ctx_label[128];
|
||||
const AVFilterContext *filter_ctx = graph->filters[i];
|
||||
|
||||
snprintf(filter_ctx_label, sizeof(filter_ctx_label), "%s\\n(%s)",
|
||||
filter_ctx->name,
|
||||
filter_ctx->filter->name);
|
||||
|
||||
for (j = 0; j < filter_ctx->nb_outputs; j++) {
|
||||
AVFilterLink *link = filter_ctx->outputs[j];
|
||||
if (link) {
|
||||
char dst_filter_ctx_label[128];
|
||||
const AVFilterContext *dst_filter_ctx = link->dst;
|
||||
|
||||
snprintf(dst_filter_ctx_label, sizeof(dst_filter_ctx_label),
|
||||
"%s\\n(%s)",
|
||||
dst_filter_ctx->name,
|
||||
dst_filter_ctx->filter->name);
|
||||
|
||||
fprintf(outfile, "\"%s\" -> \"%s\" [ label= \"inpad:%s -> outpad:%s\\n",
|
||||
filter_ctx_label, dst_filter_ctx_label,
|
||||
avfilter_pad_get_name(link->srcpad, 0),
|
||||
avfilter_pad_get_name(link->dstpad, 0));
|
||||
|
||||
if (link->type == AVMEDIA_TYPE_VIDEO) {
|
||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
|
||||
fprintf(outfile,
|
||||
"fmt:%s w:%d h:%d tb:%d/%d",
|
||||
desc->name,
|
||||
link->w, link->h,
|
||||
link->time_base.num, link->time_base.den);
|
||||
} else if (link->type == AVMEDIA_TYPE_AUDIO) {
|
||||
char buf[255];
|
||||
av_get_channel_layout_string(buf, sizeof(buf), -1,
|
||||
link->channel_layout);
|
||||
fprintf(outfile,
|
||||
"fmt:%s sr:%d cl:%s tb:%d/%d",
|
||||
av_get_sample_fmt_name(link->format),
|
||||
link->sample_rate, buf,
|
||||
link->time_base.num, link->time_base.den);
|
||||
}
|
||||
fprintf(outfile, "\" ];\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
fprintf(outfile, "}\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *outfilename = NULL;
|
||||
const char *infilename = NULL;
|
||||
FILE *outfile = NULL;
|
||||
FILE *infile = NULL;
|
||||
char *graph_string = NULL;
|
||||
AVFilterGraph *graph = av_mallocz(sizeof(AVFilterGraph));
|
||||
char c;
|
||||
|
||||
av_log_set_level(AV_LOG_DEBUG);
|
||||
|
||||
while ((c = getopt(argc, argv, "hi:o:")) != -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
usage();
|
||||
return 0;
|
||||
case 'i':
|
||||
infilename = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
outfilename = optarg;
|
||||
break;
|
||||
case '?':
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!infilename || !strcmp(infilename, "-"))
|
||||
infilename = "/dev/stdin";
|
||||
infile = fopen(infilename, "r");
|
||||
if (!infile) {
|
||||
fprintf(stderr, "Failed to open input file '%s': %s\n",
|
||||
infilename, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!outfilename || !strcmp(outfilename, "-"))
|
||||
outfilename = "/dev/stdout";
|
||||
outfile = fopen(outfilename, "w");
|
||||
if (!outfile) {
|
||||
fprintf(stderr, "Failed to open output file '%s': %s\n",
|
||||
outfilename, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* read from infile and put it in a buffer */
|
||||
{
|
||||
int64_t count = 0;
|
||||
struct line *line, *last_line, *first_line;
|
||||
char *p;
|
||||
last_line = first_line = av_malloc(sizeof(struct line));
|
||||
if (!last_line) {
|
||||
fprintf(stderr, "Memory allocation failure\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (fgets(last_line->data, sizeof(last_line->data), infile)) {
|
||||
struct line *new_line = av_malloc(sizeof(struct line));
|
||||
if (!new_line) {
|
||||
fprintf(stderr, "Memory allocation failure\n");
|
||||
return 1;
|
||||
}
|
||||
count += strlen(last_line->data);
|
||||
last_line->next = new_line;
|
||||
last_line = new_line;
|
||||
}
|
||||
last_line->next = NULL;
|
||||
|
||||
graph_string = av_malloc(count + 1);
|
||||
if (!graph_string) {
|
||||
fprintf(stderr, "Memory allocation failure\n");
|
||||
return 1;
|
||||
}
|
||||
p = graph_string;
|
||||
for (line = first_line; line->next; line = line->next) {
|
||||
size_t l = strlen(line->data);
|
||||
memcpy(p, line->data, l);
|
||||
p += l;
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
avfilter_register_all();
|
||||
|
||||
if (avfilter_graph_parse(graph, graph_string, NULL, NULL, NULL) < 0) {
|
||||
fprintf(stderr, "Failed to parse the graph description\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (avfilter_graph_config(graph, NULL) < 0)
|
||||
return 1;
|
||||
|
||||
print_digraph(outfile, graph);
|
||||
fflush(outfile);
|
||||
|
||||
return 0;
|
||||
}
|
841
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/ismindex.c
Normal file
841
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/ismindex.c
Normal file
@@ -0,0 +1,841 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Martin Storsjo
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* To create a simple file for smooth streaming:
|
||||
* ffmpeg <normal input/transcoding options> -movflags frag_keyframe foo.ismv
|
||||
* ismindex -n foo foo.ismv
|
||||
* This step creates foo.ism and foo.ismc that is required by IIS for
|
||||
* serving it.
|
||||
*
|
||||
* With -ismf, it also creates foo.ismf, which maps fragment names to
|
||||
* start-end offsets in the ismv, for use in your own streaming server.
|
||||
*
|
||||
* By adding -path-prefix path/, the produced foo.ism will refer to the
|
||||
* files foo.ismv as "path/foo.ismv" - the prefix for the generated ismc
|
||||
* file can be set with the -ismc-prefix option similarly.
|
||||
*
|
||||
* To pre-split files for serving as static files by a web server without
|
||||
* any extra server support, create the ismv file as above, and split it:
|
||||
* ismindex -split foo.ismv
|
||||
* This step creates a file Manifest and directories QualityLevel(...),
|
||||
* that can be read directly by a smooth streaming player.
|
||||
*
|
||||
* The -output dir option can be used to request that output files
|
||||
* (both .ism/.ismc, or Manifest/QualityLevels* when splitting)
|
||||
* should be written to this directory instead of in the current directory.
|
||||
* (The directory itself isn't created if it doesn't already exist.)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cmdutils.h"
|
||||
|
||||
#include "libavformat/avformat.h"
|
||||
#include "libavformat/isom.h"
|
||||
#include "libavformat/os_support.h"
|
||||
#include "libavutil/intreadwrite.h"
|
||||
#include "libavutil/mathematics.h"
|
||||
|
||||
static int usage(const char *argv0, int ret)
|
||||
{
|
||||
fprintf(stderr, "%s [-split] [-ismf] [-n basename] [-path-prefix prefix] "
|
||||
"[-ismc-prefix prefix] [-output dir] file1 [file2] ...\n", argv0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct MoofOffset {
|
||||
int64_t time;
|
||||
int64_t offset;
|
||||
int64_t duration;
|
||||
};
|
||||
|
||||
struct Track {
|
||||
const char *name;
|
||||
int64_t duration;
|
||||
int bitrate;
|
||||
int track_id;
|
||||
int is_audio, is_video;
|
||||
int width, height;
|
||||
int chunks;
|
||||
int sample_rate, channels;
|
||||
uint8_t *codec_private;
|
||||
int codec_private_size;
|
||||
struct MoofOffset *offsets;
|
||||
int timescale;
|
||||
const char *fourcc;
|
||||
int blocksize;
|
||||
int tag;
|
||||
};
|
||||
|
||||
struct Tracks {
|
||||
int nb_tracks;
|
||||
int64_t duration;
|
||||
struct Track **tracks;
|
||||
int video_track, audio_track;
|
||||
int nb_video_tracks, nb_audio_tracks;
|
||||
};
|
||||
|
||||
static int expect_tag(int32_t got_tag, int32_t expected_tag) {
|
||||
if (got_tag != expected_tag) {
|
||||
char got_tag_str[4], expected_tag_str[4];
|
||||
AV_WB32(got_tag_str, got_tag);
|
||||
AV_WB32(expected_tag_str, expected_tag);
|
||||
fprintf(stderr, "wanted tag %.4s, got %.4s\n", expected_tag_str,
|
||||
got_tag_str);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int copy_tag(AVIOContext *in, AVIOContext *out, int32_t tag_name)
|
||||
{
|
||||
int32_t size, tag;
|
||||
|
||||
size = avio_rb32(in);
|
||||
tag = avio_rb32(in);
|
||||
avio_wb32(out, size);
|
||||
avio_wb32(out, tag);
|
||||
if (expect_tag(tag, tag_name) != 0)
|
||||
return -1;
|
||||
size -= 8;
|
||||
while (size > 0) {
|
||||
char buf[1024];
|
||||
int len = FFMIN(sizeof(buf), size);
|
||||
int got;
|
||||
if ((got = avio_read(in, buf, len)) != len) {
|
||||
fprintf(stderr, "short read, wanted %d, got %d\n", len, got);
|
||||
break;
|
||||
}
|
||||
avio_write(out, buf, len);
|
||||
size -= len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int skip_tag(AVIOContext *in, int32_t tag_name)
|
||||
{
|
||||
int64_t pos = avio_tell(in);
|
||||
int32_t size, tag;
|
||||
|
||||
size = avio_rb32(in);
|
||||
tag = avio_rb32(in);
|
||||
if (expect_tag(tag, tag_name) != 0)
|
||||
return -1;
|
||||
avio_seek(in, pos + size, SEEK_SET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int write_fragment(const char *filename, AVIOContext *in)
|
||||
{
|
||||
AVIOContext *out = NULL;
|
||||
int ret;
|
||||
|
||||
if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, NULL, NULL)) < 0) {
|
||||
char errbuf[100];
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
fprintf(stderr, "Unable to open %s: %s\n", filename, errbuf);
|
||||
return ret;
|
||||
}
|
||||
ret = copy_tag(in, out, MKBETAG('m', 'o', 'o', 'f'));
|
||||
if (!ret)
|
||||
ret = copy_tag(in, out, MKBETAG('m', 'd', 'a', 't'));
|
||||
|
||||
avio_flush(out);
|
||||
avio_close(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int skip_fragment(AVIOContext *in)
|
||||
{
|
||||
int ret;
|
||||
ret = skip_tag(in, MKBETAG('m', 'o', 'o', 'f'));
|
||||
if (!ret)
|
||||
ret = skip_tag(in, MKBETAG('m', 'd', 'a', 't'));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int write_fragments(struct Tracks *tracks, int start_index,
|
||||
AVIOContext *in, const char *basename,
|
||||
int split, int ismf, const char* output_prefix)
|
||||
{
|
||||
char dirname[2048], filename[2048], idxname[2048];
|
||||
int i, j, ret = 0, fragment_ret;
|
||||
FILE* out = NULL;
|
||||
|
||||
if (ismf) {
|
||||
snprintf(idxname, sizeof(idxname), "%s%s.ismf", output_prefix, basename);
|
||||
out = fopen(idxname, "w");
|
||||
if (!out) {
|
||||
ret = AVERROR(errno);
|
||||
perror(idxname);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
for (i = start_index; i < tracks->nb_tracks; i++) {
|
||||
struct Track *track = tracks->tracks[i];
|
||||
const char *type = track->is_video ? "video" : "audio";
|
||||
snprintf(dirname, sizeof(dirname), "%sQualityLevels(%d)", output_prefix, track->bitrate);
|
||||
if (split) {
|
||||
if (mkdir(dirname, 0777) == -1 && errno != EEXIST) {
|
||||
ret = AVERROR(errno);
|
||||
perror(dirname);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
for (j = 0; j < track->chunks; j++) {
|
||||
snprintf(filename, sizeof(filename), "%s/Fragments(%s=%"PRId64")",
|
||||
dirname, type, track->offsets[j].time);
|
||||
avio_seek(in, track->offsets[j].offset, SEEK_SET);
|
||||
if (ismf)
|
||||
fprintf(out, "%s %"PRId64, filename, avio_tell(in));
|
||||
if (split)
|
||||
fragment_ret = write_fragment(filename, in);
|
||||
else
|
||||
fragment_ret = skip_fragment(in);
|
||||
if (ismf)
|
||||
fprintf(out, " %"PRId64"\n", avio_tell(in));
|
||||
if (fragment_ret != 0) {
|
||||
fprintf(stderr, "failed fragment %d in track %d (%s)\n", j,
|
||||
track->track_id, track->name);
|
||||
ret = fragment_ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
fail:
|
||||
if (out)
|
||||
fclose(out);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int64_t read_trun_duration(AVIOContext *in, int default_duration,
|
||||
int64_t end)
|
||||
{
|
||||
int64_t dts = 0;
|
||||
int64_t pos;
|
||||
int flags, i;
|
||||
int entries;
|
||||
int64_t first_pts = 0;
|
||||
int64_t max_pts = 0;
|
||||
avio_r8(in); /* version */
|
||||
flags = avio_rb24(in);
|
||||
if (default_duration <= 0 && !(flags & MOV_TRUN_SAMPLE_DURATION)) {
|
||||
fprintf(stderr, "No sample duration in trun flags\n");
|
||||
return -1;
|
||||
}
|
||||
entries = avio_rb32(in);
|
||||
|
||||
if (flags & MOV_TRUN_DATA_OFFSET) avio_rb32(in);
|
||||
if (flags & MOV_TRUN_FIRST_SAMPLE_FLAGS) avio_rb32(in);
|
||||
|
||||
pos = avio_tell(in);
|
||||
for (i = 0; i < entries && pos < end; i++) {
|
||||
int sample_duration = default_duration;
|
||||
int64_t pts = dts;
|
||||
if (flags & MOV_TRUN_SAMPLE_DURATION) sample_duration = avio_rb32(in);
|
||||
if (flags & MOV_TRUN_SAMPLE_SIZE) avio_rb32(in);
|
||||
if (flags & MOV_TRUN_SAMPLE_FLAGS) avio_rb32(in);
|
||||
if (flags & MOV_TRUN_SAMPLE_CTS) pts += avio_rb32(in);
|
||||
if (sample_duration < 0) {
|
||||
fprintf(stderr, "Negative sample duration %d\n", sample_duration);
|
||||
return -1;
|
||||
}
|
||||
if (i == 0)
|
||||
first_pts = pts;
|
||||
max_pts = FFMAX(max_pts, pts + sample_duration);
|
||||
dts += sample_duration;
|
||||
pos = avio_tell(in);
|
||||
}
|
||||
|
||||
return max_pts - first_pts;
|
||||
}
|
||||
|
||||
static int64_t read_moof_duration(AVIOContext *in, int64_t offset)
|
||||
{
|
||||
int64_t ret = -1;
|
||||
int32_t moof_size, size, tag;
|
||||
int64_t pos = 0;
|
||||
int default_duration = 0;
|
||||
|
||||
avio_seek(in, offset, SEEK_SET);
|
||||
moof_size = avio_rb32(in);
|
||||
tag = avio_rb32(in);
|
||||
if (expect_tag(tag, MKBETAG('m', 'o', 'o', 'f')) != 0)
|
||||
goto fail;
|
||||
while (pos < offset + moof_size) {
|
||||
pos = avio_tell(in);
|
||||
size = avio_rb32(in);
|
||||
tag = avio_rb32(in);
|
||||
if (tag == MKBETAG('t', 'r', 'a', 'f')) {
|
||||
int64_t traf_pos = pos;
|
||||
int64_t traf_size = size;
|
||||
while (pos < traf_pos + traf_size) {
|
||||
pos = avio_tell(in);
|
||||
size = avio_rb32(in);
|
||||
tag = avio_rb32(in);
|
||||
if (tag == MKBETAG('t', 'f', 'h', 'd')) {
|
||||
int flags = 0;
|
||||
avio_r8(in); /* version */
|
||||
flags = avio_rb24(in);
|
||||
avio_rb32(in); /* track_id */
|
||||
if (flags & MOV_TFHD_BASE_DATA_OFFSET)
|
||||
avio_rb64(in);
|
||||
if (flags & MOV_TFHD_STSD_ID)
|
||||
avio_rb32(in);
|
||||
if (flags & MOV_TFHD_DEFAULT_DURATION)
|
||||
default_duration = avio_rb32(in);
|
||||
}
|
||||
if (tag == MKBETAG('t', 'r', 'u', 'n')) {
|
||||
return read_trun_duration(in, default_duration,
|
||||
pos + size);
|
||||
}
|
||||
avio_seek(in, pos + size, SEEK_SET);
|
||||
}
|
||||
fprintf(stderr, "Couldn't find trun\n");
|
||||
goto fail;
|
||||
}
|
||||
avio_seek(in, pos + size, SEEK_SET);
|
||||
}
|
||||
fprintf(stderr, "Couldn't find traf\n");
|
||||
|
||||
fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int read_tfra(struct Tracks *tracks, int start_index, AVIOContext *f)
|
||||
{
|
||||
int ret = AVERROR_EOF, track_id;
|
||||
int version, fieldlength, i, j;
|
||||
int64_t pos = avio_tell(f);
|
||||
uint32_t size = avio_rb32(f);
|
||||
struct Track *track = NULL;
|
||||
|
||||
if (avio_rb32(f) != MKBETAG('t', 'f', 'r', 'a'))
|
||||
goto fail;
|
||||
version = avio_r8(f);
|
||||
avio_rb24(f);
|
||||
track_id = avio_rb32(f); /* track id */
|
||||
for (i = start_index; i < tracks->nb_tracks && !track; i++)
|
||||
if (tracks->tracks[i]->track_id == track_id)
|
||||
track = tracks->tracks[i];
|
||||
if (!track) {
|
||||
/* Ok, continue parsing the next atom */
|
||||
ret = 0;
|
||||
goto fail;
|
||||
}
|
||||
fieldlength = avio_rb32(f);
|
||||
track->chunks = avio_rb32(f);
|
||||
track->offsets = av_mallocz_array(track->chunks, sizeof(*track->offsets));
|
||||
if (!track->offsets) {
|
||||
track->chunks = 0;
|
||||
ret = AVERROR(ENOMEM);
|
||||
goto fail;
|
||||
}
|
||||
// The duration here is always the difference between consecutive
|
||||
// start times.
|
||||
for (i = 0; i < track->chunks; i++) {
|
||||
if (version == 1) {
|
||||
track->offsets[i].time = avio_rb64(f);
|
||||
track->offsets[i].offset = avio_rb64(f);
|
||||
} else {
|
||||
track->offsets[i].time = avio_rb32(f);
|
||||
track->offsets[i].offset = avio_rb32(f);
|
||||
}
|
||||
for (j = 0; j < ((fieldlength >> 4) & 3) + 1; j++)
|
||||
avio_r8(f);
|
||||
for (j = 0; j < ((fieldlength >> 2) & 3) + 1; j++)
|
||||
avio_r8(f);
|
||||
for (j = 0; j < ((fieldlength >> 0) & 3) + 1; j++)
|
||||
avio_r8(f);
|
||||
if (i > 0)
|
||||
track->offsets[i - 1].duration = track->offsets[i].time -
|
||||
track->offsets[i - 1].time;
|
||||
}
|
||||
if (track->chunks > 0) {
|
||||
track->offsets[track->chunks - 1].duration = track->offsets[0].time +
|
||||
track->duration -
|
||||
track->offsets[track->chunks - 1].time;
|
||||
}
|
||||
// Now try and read the actual durations from the trun sample data.
|
||||
for (i = 0; i < track->chunks; i++) {
|
||||
int64_t duration = read_moof_duration(f, track->offsets[i].offset);
|
||||
if (duration > 0 && abs(duration - track->offsets[i].duration) > 3) {
|
||||
// 3 allows for integer duration to drift a few units,
|
||||
// e.g., for 1/3 durations
|
||||
track->offsets[i].duration = duration;
|
||||
}
|
||||
}
|
||||
if (track->chunks > 0) {
|
||||
if (track->offsets[track->chunks - 1].duration <= 0) {
|
||||
fprintf(stderr, "Calculated last chunk duration for track %d "
|
||||
"was non-positive (%"PRId64"), probably due to missing "
|
||||
"fragments ", track->track_id,
|
||||
track->offsets[track->chunks - 1].duration);
|
||||
if (track->chunks > 1) {
|
||||
track->offsets[track->chunks - 1].duration =
|
||||
track->offsets[track->chunks - 2].duration;
|
||||
} else {
|
||||
track->offsets[track->chunks - 1].duration = 1;
|
||||
}
|
||||
fprintf(stderr, "corrected to %"PRId64"\n",
|
||||
track->offsets[track->chunks - 1].duration);
|
||||
track->duration = track->offsets[track->chunks - 1].time +
|
||||
track->offsets[track->chunks - 1].duration -
|
||||
track->offsets[0].time;
|
||||
fprintf(stderr, "Track duration corrected to %"PRId64"\n",
|
||||
track->duration);
|
||||
}
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
avio_seek(f, pos + size, SEEK_SET);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int read_mfra(struct Tracks *tracks, int start_index,
|
||||
const char *file, int split, int ismf,
|
||||
const char *basename, const char* output_prefix)
|
||||
{
|
||||
int err = 0;
|
||||
const char* err_str = "";
|
||||
AVIOContext *f = NULL;
|
||||
int32_t mfra_size;
|
||||
|
||||
if ((err = avio_open2(&f, file, AVIO_FLAG_READ, NULL, NULL)) < 0)
|
||||
goto fail;
|
||||
avio_seek(f, avio_size(f) - 4, SEEK_SET);
|
||||
mfra_size = avio_rb32(f);
|
||||
avio_seek(f, -mfra_size, SEEK_CUR);
|
||||
if (avio_rb32(f) != mfra_size) {
|
||||
err = AVERROR_INVALIDDATA;
|
||||
err_str = "mfra size mismatch";
|
||||
goto fail;
|
||||
}
|
||||
if (avio_rb32(f) != MKBETAG('m', 'f', 'r', 'a')) {
|
||||
err = AVERROR_INVALIDDATA;
|
||||
err_str = "mfra tag mismatch";
|
||||
goto fail;
|
||||
}
|
||||
while (!read_tfra(tracks, start_index, f)) {
|
||||
/* Empty */
|
||||
}
|
||||
|
||||
if (split || ismf)
|
||||
err = write_fragments(tracks, start_index, f, basename, split, ismf,
|
||||
output_prefix);
|
||||
err_str = "error in write_fragments";
|
||||
|
||||
fail:
|
||||
if (f)
|
||||
avio_close(f);
|
||||
if (err)
|
||||
fprintf(stderr, "Unable to read the MFRA atom in %s (%s)\n", file, err_str);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int get_private_data(struct Track *track, AVCodecContext *codec)
|
||||
{
|
||||
track->codec_private_size = 0;
|
||||
track->codec_private = av_mallocz(codec->extradata_size);
|
||||
if (!track->codec_private)
|
||||
return AVERROR(ENOMEM);
|
||||
track->codec_private_size = codec->extradata_size;
|
||||
memcpy(track->codec_private, codec->extradata, codec->extradata_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_video_private_data(struct Track *track, AVCodecContext *codec)
|
||||
{
|
||||
AVIOContext *io = NULL;
|
||||
uint16_t sps_size, pps_size;
|
||||
int err;
|
||||
|
||||
if (codec->codec_id == AV_CODEC_ID_VC1)
|
||||
return get_private_data(track, codec);
|
||||
|
||||
if ((err = avio_open_dyn_buf(&io)) < 0)
|
||||
goto fail;
|
||||
err = AVERROR(EINVAL);
|
||||
if (codec->extradata_size < 11 || codec->extradata[0] != 1)
|
||||
goto fail;
|
||||
sps_size = AV_RB16(&codec->extradata[6]);
|
||||
if (11 + sps_size > codec->extradata_size)
|
||||
goto fail;
|
||||
avio_wb32(io, 0x00000001);
|
||||
avio_write(io, &codec->extradata[8], sps_size);
|
||||
pps_size = AV_RB16(&codec->extradata[9 + sps_size]);
|
||||
if (11 + sps_size + pps_size > codec->extradata_size)
|
||||
goto fail;
|
||||
avio_wb32(io, 0x00000001);
|
||||
avio_write(io, &codec->extradata[11 + sps_size], pps_size);
|
||||
err = 0;
|
||||
|
||||
fail:
|
||||
track->codec_private_size = avio_close_dyn_buf(io, &track->codec_private);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int handle_file(struct Tracks *tracks, const char *file, int split,
|
||||
int ismf, const char *basename,
|
||||
const char* output_prefix)
|
||||
{
|
||||
AVFormatContext *ctx = NULL;
|
||||
int err = 0, i, orig_tracks = tracks->nb_tracks;
|
||||
char errbuf[50], *ptr;
|
||||
struct Track *track;
|
||||
|
||||
err = avformat_open_input(&ctx, file, NULL, NULL);
|
||||
if (err < 0) {
|
||||
av_strerror(err, errbuf, sizeof(errbuf));
|
||||
fprintf(stderr, "Unable to open %s: %s\n", file, errbuf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
err = avformat_find_stream_info(ctx, NULL);
|
||||
if (err < 0) {
|
||||
av_strerror(err, errbuf, sizeof(errbuf));
|
||||
fprintf(stderr, "Unable to identify %s: %s\n", file, errbuf);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (ctx->nb_streams < 1) {
|
||||
fprintf(stderr, "No streams found in %s\n", file);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
for (i = 0; i < ctx->nb_streams; i++) {
|
||||
struct Track **temp;
|
||||
AVStream *st = ctx->streams[i];
|
||||
|
||||
if (st->codec->bit_rate == 0) {
|
||||
fprintf(stderr, "Skipping track %d in %s as it has zero bitrate\n",
|
||||
st->id, file);
|
||||
continue;
|
||||
}
|
||||
|
||||
track = av_mallocz(sizeof(*track));
|
||||
if (!track) {
|
||||
err = AVERROR(ENOMEM);
|
||||
goto fail;
|
||||
}
|
||||
temp = av_realloc_array(tracks->tracks,
|
||||
tracks->nb_tracks + 1,
|
||||
sizeof(*tracks->tracks));
|
||||
if (!temp) {
|
||||
av_free(track);
|
||||
err = AVERROR(ENOMEM);
|
||||
goto fail;
|
||||
}
|
||||
tracks->tracks = temp;
|
||||
tracks->tracks[tracks->nb_tracks] = track;
|
||||
|
||||
track->name = file;
|
||||
if ((ptr = strrchr(file, '/')))
|
||||
track->name = ptr + 1;
|
||||
|
||||
track->bitrate = st->codec->bit_rate;
|
||||
track->track_id = st->id;
|
||||
track->timescale = st->time_base.den;
|
||||
track->duration = st->duration;
|
||||
track->is_audio = st->codec->codec_type == AVMEDIA_TYPE_AUDIO;
|
||||
track->is_video = st->codec->codec_type == AVMEDIA_TYPE_VIDEO;
|
||||
|
||||
if (!track->is_audio && !track->is_video) {
|
||||
fprintf(stderr,
|
||||
"Track %d in %s is neither video nor audio, skipping\n",
|
||||
track->track_id, file);
|
||||
av_freep(&tracks->tracks[tracks->nb_tracks]);
|
||||
continue;
|
||||
}
|
||||
|
||||
tracks->duration = FFMAX(tracks->duration,
|
||||
av_rescale_rnd(track->duration, AV_TIME_BASE,
|
||||
track->timescale, AV_ROUND_UP));
|
||||
|
||||
if (track->is_audio) {
|
||||
if (tracks->audio_track < 0)
|
||||
tracks->audio_track = tracks->nb_tracks;
|
||||
tracks->nb_audio_tracks++;
|
||||
track->channels = st->codec->channels;
|
||||
track->sample_rate = st->codec->sample_rate;
|
||||
if (st->codec->codec_id == AV_CODEC_ID_AAC) {
|
||||
track->fourcc = "AACL";
|
||||
track->tag = 255;
|
||||
track->blocksize = 4;
|
||||
} else if (st->codec->codec_id == AV_CODEC_ID_WMAPRO) {
|
||||
track->fourcc = "WMAP";
|
||||
track->tag = st->codec->codec_tag;
|
||||
track->blocksize = st->codec->block_align;
|
||||
}
|
||||
get_private_data(track, st->codec);
|
||||
}
|
||||
if (track->is_video) {
|
||||
if (tracks->video_track < 0)
|
||||
tracks->video_track = tracks->nb_tracks;
|
||||
tracks->nb_video_tracks++;
|
||||
track->width = st->codec->width;
|
||||
track->height = st->codec->height;
|
||||
if (st->codec->codec_id == AV_CODEC_ID_H264)
|
||||
track->fourcc = "H264";
|
||||
else if (st->codec->codec_id == AV_CODEC_ID_VC1)
|
||||
track->fourcc = "WVC1";
|
||||
get_video_private_data(track, st->codec);
|
||||
}
|
||||
|
||||
tracks->nb_tracks++;
|
||||
}
|
||||
|
||||
avformat_close_input(&ctx);
|
||||
|
||||
err = read_mfra(tracks, orig_tracks, file, split, ismf, basename,
|
||||
output_prefix);
|
||||
|
||||
fail:
|
||||
if (ctx)
|
||||
avformat_close_input(&ctx);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void output_server_manifest(struct Tracks *tracks, const char *basename,
|
||||
const char *output_prefix,
|
||||
const char *path_prefix,
|
||||
const char *ismc_prefix)
|
||||
{
|
||||
char filename[1000];
|
||||
FILE *out;
|
||||
int i;
|
||||
|
||||
snprintf(filename, sizeof(filename), "%s%s.ism", output_prefix, basename);
|
||||
out = fopen(filename, "w");
|
||||
if (!out) {
|
||||
perror(filename);
|
||||
return;
|
||||
}
|
||||
fprintf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
|
||||
fprintf(out, "<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
|
||||
fprintf(out, "\t<head>\n");
|
||||
fprintf(out, "\t\t<meta name=\"clientManifestRelativePath\" "
|
||||
"content=\"%s%s.ismc\" />\n", ismc_prefix, basename);
|
||||
fprintf(out, "\t</head>\n");
|
||||
fprintf(out, "\t<body>\n");
|
||||
fprintf(out, "\t\t<switch>\n");
|
||||
for (i = 0; i < tracks->nb_tracks; i++) {
|
||||
struct Track *track = tracks->tracks[i];
|
||||
const char *type = track->is_video ? "video" : "audio";
|
||||
fprintf(out, "\t\t\t<%s src=\"%s%s\" systemBitrate=\"%d\">\n",
|
||||
type, path_prefix, track->name, track->bitrate);
|
||||
fprintf(out, "\t\t\t\t<param name=\"trackID\" value=\"%d\" "
|
||||
"valueType=\"data\" />\n", track->track_id);
|
||||
fprintf(out, "\t\t\t</%s>\n", type);
|
||||
}
|
||||
fprintf(out, "\t\t</switch>\n");
|
||||
fprintf(out, "\t</body>\n");
|
||||
fprintf(out, "</smil>\n");
|
||||
fclose(out);
|
||||
}
|
||||
|
||||
static void print_track_chunks(FILE *out, struct Tracks *tracks, int main,
|
||||
const char *type)
|
||||
{
|
||||
int i, j;
|
||||
int64_t pos = 0;
|
||||
struct Track *track = tracks->tracks[main];
|
||||
int should_print_time_mismatch = 1;
|
||||
|
||||
for (i = 0; i < track->chunks; i++) {
|
||||
for (j = main + 1; j < tracks->nb_tracks; j++) {
|
||||
if (tracks->tracks[j]->is_audio == track->is_audio) {
|
||||
if (track->offsets[i].duration != tracks->tracks[j]->offsets[i].duration) {
|
||||
fprintf(stderr, "Mismatched duration of %s chunk %d in %s (%d) and %s (%d)\n",
|
||||
type, i, track->name, main, tracks->tracks[j]->name, j);
|
||||
should_print_time_mismatch = 1;
|
||||
}
|
||||
if (track->offsets[i].time != tracks->tracks[j]->offsets[i].time) {
|
||||
if (should_print_time_mismatch)
|
||||
fprintf(stderr, "Mismatched (start) time of %s chunk %d in %s (%d) and %s (%d)\n",
|
||||
type, i, track->name, main, tracks->tracks[j]->name, j);
|
||||
should_print_time_mismatch = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
fprintf(out, "\t\t<c n=\"%d\" d=\"%"PRId64"\" ",
|
||||
i, track->offsets[i].duration);
|
||||
if (pos != track->offsets[i].time) {
|
||||
fprintf(out, "t=\"%"PRId64"\" ", track->offsets[i].time);
|
||||
pos = track->offsets[i].time;
|
||||
}
|
||||
pos += track->offsets[i].duration;
|
||||
fprintf(out, "/>\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void output_client_manifest(struct Tracks *tracks, const char *basename,
|
||||
const char *output_prefix, int split)
|
||||
{
|
||||
char filename[1000];
|
||||
FILE *out;
|
||||
int i, j;
|
||||
|
||||
if (split)
|
||||
snprintf(filename, sizeof(filename), "%sManifest", output_prefix);
|
||||
else
|
||||
snprintf(filename, sizeof(filename), "%s%s.ismc", output_prefix, basename);
|
||||
out = fopen(filename, "w");
|
||||
if (!out) {
|
||||
perror(filename);
|
||||
return;
|
||||
}
|
||||
fprintf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
|
||||
fprintf(out, "<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" "
|
||||
"Duration=\"%"PRId64 "\">\n", tracks->duration * 10);
|
||||
if (tracks->video_track >= 0) {
|
||||
struct Track *track = tracks->tracks[tracks->video_track];
|
||||
struct Track *first_track = track;
|
||||
int index = 0;
|
||||
fprintf(out,
|
||||
"\t<StreamIndex Type=\"video\" QualityLevels=\"%d\" "
|
||||
"Chunks=\"%d\" "
|
||||
"Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n",
|
||||
tracks->nb_video_tracks, track->chunks);
|
||||
for (i = 0; i < tracks->nb_tracks; i++) {
|
||||
track = tracks->tracks[i];
|
||||
if (!track->is_video)
|
||||
continue;
|
||||
fprintf(out,
|
||||
"\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
|
||||
"FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" "
|
||||
"CodecPrivateData=\"",
|
||||
index, track->bitrate, track->fourcc, track->width, track->height);
|
||||
for (j = 0; j < track->codec_private_size; j++)
|
||||
fprintf(out, "%02X", track->codec_private[j]);
|
||||
fprintf(out, "\" />\n");
|
||||
index++;
|
||||
if (track->chunks != first_track->chunks)
|
||||
fprintf(stderr, "Mismatched number of video chunks in %s (id: %d, chunks %d) and %s (id: %d, chunks %d)\n",
|
||||
track->name, track->track_id, track->chunks, first_track->name, first_track->track_id, first_track->chunks);
|
||||
}
|
||||
print_track_chunks(out, tracks, tracks->video_track, "video");
|
||||
fprintf(out, "\t</StreamIndex>\n");
|
||||
}
|
||||
if (tracks->audio_track >= 0) {
|
||||
struct Track *track = tracks->tracks[tracks->audio_track];
|
||||
struct Track *first_track = track;
|
||||
int index = 0;
|
||||
fprintf(out,
|
||||
"\t<StreamIndex Type=\"audio\" QualityLevels=\"%d\" "
|
||||
"Chunks=\"%d\" "
|
||||
"Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n",
|
||||
tracks->nb_audio_tracks, track->chunks);
|
||||
for (i = 0; i < tracks->nb_tracks; i++) {
|
||||
track = tracks->tracks[i];
|
||||
if (!track->is_audio)
|
||||
continue;
|
||||
fprintf(out,
|
||||
"\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
|
||||
"FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" "
|
||||
"BitsPerSample=\"16\" PacketSize=\"%d\" "
|
||||
"AudioTag=\"%d\" CodecPrivateData=\"",
|
||||
index, track->bitrate, track->fourcc, track->sample_rate,
|
||||
track->channels, track->blocksize, track->tag);
|
||||
for (j = 0; j < track->codec_private_size; j++)
|
||||
fprintf(out, "%02X", track->codec_private[j]);
|
||||
fprintf(out, "\" />\n");
|
||||
index++;
|
||||
if (track->chunks != first_track->chunks)
|
||||
fprintf(stderr, "Mismatched number of audio chunks in %s and %s\n",
|
||||
track->name, first_track->name);
|
||||
}
|
||||
print_track_chunks(out, tracks, tracks->audio_track, "audio");
|
||||
fprintf(out, "\t</StreamIndex>\n");
|
||||
}
|
||||
fprintf(out, "</SmoothStreamingMedia>\n");
|
||||
fclose(out);
|
||||
}
|
||||
|
||||
static void clean_tracks(struct Tracks *tracks)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < tracks->nb_tracks; i++) {
|
||||
av_freep(&tracks->tracks[i]->codec_private);
|
||||
av_freep(&tracks->tracks[i]->offsets);
|
||||
av_freep(&tracks->tracks[i]);
|
||||
}
|
||||
av_freep(&tracks->tracks);
|
||||
tracks->nb_tracks = 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *basename = NULL;
|
||||
const char *path_prefix = "", *ismc_prefix = "";
|
||||
const char *output_prefix = "";
|
||||
char output_prefix_buf[2048];
|
||||
int split = 0, ismf = 0, i;
|
||||
struct Tracks tracks = { 0, .video_track = -1, .audio_track = -1 };
|
||||
|
||||
av_register_all();
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (!strcmp(argv[i], "-n")) {
|
||||
basename = argv[i + 1];
|
||||
i++;
|
||||
} else if (!strcmp(argv[i], "-path-prefix")) {
|
||||
path_prefix = argv[i + 1];
|
||||
i++;
|
||||
} else if (!strcmp(argv[i], "-ismc-prefix")) {
|
||||
ismc_prefix = argv[i + 1];
|
||||
i++;
|
||||
} else if (!strcmp(argv[i], "-output")) {
|
||||
output_prefix = argv[i + 1];
|
||||
i++;
|
||||
if (output_prefix[strlen(output_prefix) - 1] != '/') {
|
||||
snprintf(output_prefix_buf, sizeof(output_prefix_buf),
|
||||
"%s/", output_prefix);
|
||||
output_prefix = output_prefix_buf;
|
||||
}
|
||||
} else if (!strcmp(argv[i], "-split")) {
|
||||
split = 1;
|
||||
} else if (!strcmp(argv[i], "-ismf")) {
|
||||
ismf = 1;
|
||||
} else if (argv[i][0] == '-') {
|
||||
return usage(argv[0], 1);
|
||||
} else {
|
||||
if (!basename)
|
||||
ismf = 0;
|
||||
if (handle_file(&tracks, argv[i], split, ismf,
|
||||
basename, output_prefix))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (!tracks.nb_tracks || (!basename && !split))
|
||||
return usage(argv[0], 1);
|
||||
|
||||
if (!split)
|
||||
output_server_manifest(&tracks, basename, output_prefix,
|
||||
path_prefix, ismc_prefix);
|
||||
output_client_manifest(&tracks, basename, output_prefix, split);
|
||||
|
||||
clean_tracks(&tracks);
|
||||
|
||||
return 0;
|
||||
}
|
114
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/make_chlayout_test
Normal file
114
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/make_chlayout_test
Normal file
@@ -0,0 +1,114 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
# Copyright (c) 2012 Nicolas George
|
||||
#
|
||||
# This file is part of FFmpeg.
|
||||
#
|
||||
# FFmpeg is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# FFmpeg 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 Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=head1 NAME
|
||||
|
||||
make_chlayout_test - produce a multichannel test file with the channels
|
||||
clearly identified
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
tools/make_chlayout_test I<channels> I<out_options>
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This script uses B<ffmpeg> and B<libflite> to produce a file with audio
|
||||
channels clearly identified by their name. The resulting file can be used to
|
||||
check that the layout and order of channels is correctly handled by a piece
|
||||
of software, either a part of B<FFmpeg> or not.
|
||||
|
||||
I<channels> is a list of channels or channel layouts, separated by '+'.
|
||||
|
||||
I<out_options> is a list of valid ffmpeg outout options, including the
|
||||
output file.
|
||||
|
||||
Note that some output codecs or formats can not handle arbitrary channel
|
||||
layout.
|
||||
|
||||
This script requires a B<ffmpeg> binary, either in the source tree or in the
|
||||
search path; it must have the flite audio source enabled.
|
||||
|
||||
=head1 EXAMPLES
|
||||
|
||||
Check that the speakers are correctly plugged:
|
||||
|
||||
tools/make_chlayout_test FL+FR -f alsa default
|
||||
|
||||
Produce a 5.1 FLAC file:
|
||||
|
||||
tools/make_chlayout_test 5.1 surround.flac
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Getopt::Long ":config" => "require_order";
|
||||
use Pod::Usage;
|
||||
|
||||
GetOptions (
|
||||
"help|usage|?|h" => sub { pod2usage({ -verbose => 1, -exitval => 0 }) },
|
||||
"manpage|m" => sub { pod2usage({ -verbose => 2, -exitval => 0 }) },
|
||||
) and @ARGV >= 2 or pod2usage({ -verbose => 1, -exitval => 1 });
|
||||
|
||||
my $channels = shift @ARGV;
|
||||
my @out_options = @ARGV;
|
||||
|
||||
my $ffmpeg = exists $ENV{FFMPEG} ? $ENV{FFMPEG} :
|
||||
$0 =~ /(.*)\// && -e "$1/../ffmpeg" ? "$1/../ffmpeg" :
|
||||
"ffmpeg";
|
||||
|
||||
my %channel_label_to_descr;
|
||||
my %layout_to_channels;
|
||||
|
||||
{
|
||||
open my $stderr, ">&STDERR";
|
||||
open STDERR, ">", "/dev/null";
|
||||
open my $f, "-|", $ffmpeg, "-layouts" or die "$ffmpeg: $!\n";
|
||||
open STDERR, ">&", $stderr;
|
||||
while (<$f>) {
|
||||
chomp;
|
||||
next if /^NAME/ or /:$/ or /^$/; # skip headings
|
||||
my ($name, $descr) = split " ", $_, 2;
|
||||
next unless $descr;
|
||||
if ($descr =~ /^[[:upper:]]+(?:\+[[:upper:]]+)*$/) {
|
||||
$layout_to_channels{$name} = [ split /\+/, $descr ];
|
||||
} else {
|
||||
$channel_label_to_descr{$name} = $descr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my @channels = map { @{$layout_to_channels{$_} // [$_]} } split /\+/, $channels;
|
||||
|
||||
my $layout = join "+", @channels;
|
||||
my $graph = "";
|
||||
my $concat_in = "";
|
||||
for my $i (0 .. $#channels) {
|
||||
my $label = $channels[$i];
|
||||
my $descr = $channel_label_to_descr{$label}
|
||||
or die "Channel $label not found\n";
|
||||
$graph .= "flite=text='${descr}', aformat=channel_layouts=mono, " .
|
||||
"pan=${layout}:${label}=c0 [ch$i] ;\n";
|
||||
$concat_in .= "[ch$i] ";
|
||||
}
|
||||
$graph .= "${concat_in}concat=v=0:a=1:n=" . scalar(@channels);
|
||||
|
||||
exec $ffmpeg, "-f", "lavfi", "-i", $graph, @out_options
|
||||
or die "$ffmpeg: $!\n";
|
@@ -0,0 +1,36 @@
|
||||
#!/bin/sh
|
||||
|
||||
srcdir=${0%/*}/..
|
||||
|
||||
while read -r field equal value; do
|
||||
case "$field $equal" in
|
||||
".id =")
|
||||
eval "known_${value%,}=1"
|
||||
;;
|
||||
esac
|
||||
done < $srcdir/libavcodec/codec_desc.c
|
||||
|
||||
known_AV_CODEC_ID_NONE=1
|
||||
known_AV_CODEC_ID_FIRST_AUDIO=1
|
||||
known_AV_CODEC_ID_FIRST_SUBTITLE=1
|
||||
known_AV_CODEC_ID_FIRST_UNKNOWN=1
|
||||
known_AV_CODEC_ID_PROBE=1
|
||||
known_AV_CODEC_ID_MPEG2TS=1
|
||||
known_AV_CODEC_ID_MPEG4SYSTEMS=1
|
||||
known_AV_CODEC_ID_FFMETADATA=1
|
||||
|
||||
in=0
|
||||
while read -r line; do
|
||||
case "$in-$line" in
|
||||
0-"enum AVCodecID"*) in=1;;
|
||||
1-*"};"*) in=0;;
|
||||
1-*AV_CODEC_ID_*,*)
|
||||
cid="${line%%[, =]*}"
|
||||
eval "known=\$known_$cid"
|
||||
case "$known" in
|
||||
1) ;;
|
||||
*) echo "$cid missing";;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
done < $srcdir/libavcodec/avcodec.h
|
33
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/normalize.py
Normal file
33
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/normalize.py
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python2
|
||||
|
||||
import sys, subprocess
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
ifile = sys.argv[1]
|
||||
encopt = sys.argv[2:-1]
|
||||
ofile = sys.argv[-1]
|
||||
else:
|
||||
print 'usage: %s <input> [encode_options] <output>' % sys.argv[0]
|
||||
sys.exit(1)
|
||||
|
||||
analysis_cmd = 'ffprobe -v error -of compact=p=0:nk=1 '
|
||||
analysis_cmd += '-show_entries frame_tags=lavfi.r128.I -f lavfi '
|
||||
analysis_cmd += "amovie='%s',ebur128=metadata=1" % ifile
|
||||
try:
|
||||
probe_out = subprocess.check_output(analysis_cmd, shell=True)
|
||||
except subprocess.CalledProcessError, e:
|
||||
sys.exit(e.returncode)
|
||||
loudness = ref = -23
|
||||
for line in probe_out.splitlines():
|
||||
sline = line.rstrip()
|
||||
if sline:
|
||||
loudness = sline
|
||||
adjust = ref - float(loudness)
|
||||
if abs(adjust) < 0.0001:
|
||||
print 'No normalization needed for ' + ifile
|
||||
else:
|
||||
print "Adjust %s by %.1fdB" % (ifile, adjust)
|
||||
norm_cmd = ['ffmpeg', '-i', ifile, '-af', 'volume=%fdB' % adjust]
|
||||
norm_cmd += encopt + [ofile]
|
||||
print ' => %s' % ' '.join(norm_cmd)
|
||||
subprocess.call(norm_cmd)
|
181
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/patcheck
Normal file
181
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/patcheck
Normal file
@@ -0,0 +1,181 @@
|
||||
#!/bin/sh
|
||||
|
||||
# if no argument provided, write stdin to a file and re-run the script
|
||||
if [ $# = 0 ]; then
|
||||
cat > patcheck.stdout
|
||||
$0 patcheck.stdout
|
||||
rm -f patcheck.stdout
|
||||
exit
|
||||
fi
|
||||
|
||||
GREP=grep
|
||||
EGREP=egrep
|
||||
TMP=patcheck.tmp
|
||||
OPT="-nH"
|
||||
#FILES=$($GREP '^+++' $* | sed 's/+++ //g')
|
||||
|
||||
echo patCHeck 1e10.0
|
||||
echo This tool is intended to help a human check/review patches. It is very far from
|
||||
echo being free of false positives and negatives, and its output are just hints of what
|
||||
echo may or may not be bad. When you use it and it misses something or detects
|
||||
echo something wrong, fix it and send a patch to the ffmpeg-devel mailing list.
|
||||
echo License: GPL, Author: Michael Niedermayer
|
||||
|
||||
ERE_PRITYP='(unsigned *|)(char|short|long|int|long *int|short *int|void|float|double|(u|)int(8|16|32|64)_t)'
|
||||
ERE_TYPES='(const|static|av_cold|inline| *)*('$ERE_PRITYP'|[a-zA-Z][a-zA-Z0-9_]*)[* ]{1,}[a-zA-Z][a-zA-Z0-9_]*'
|
||||
ERE_FUNCS="$ERE_TYPES"' *\('
|
||||
|
||||
hiegrep(){
|
||||
arg="$1"
|
||||
msg="$2"
|
||||
shift 2
|
||||
$GREP $OPT '^+' $* | $GREP -v ':+++'| $EGREP --color=always -- "$arg"> $TMP && printf "\n$msg\n"
|
||||
cat $TMP
|
||||
}
|
||||
|
||||
hiegrep2(){
|
||||
arg="$1"
|
||||
varg="$2"
|
||||
msg="$3"
|
||||
shift 3
|
||||
$GREP $OPT '^+' $* | $GREP -v ':+++' | $EGREP -v -- "$varg" | $EGREP --color=always -- "$arg" > $TMP && printf "\n$msg\n"
|
||||
cat $TMP
|
||||
}
|
||||
|
||||
hiegrep 'static[^(]*\*[a-zA-Z_]*\[' 'pointer array is not const' $*
|
||||
hiegrep '[[:space:]]$' 'trailing whitespace' $*
|
||||
hiegrep "$(echo x | tr 'x' '\t')" 'tabs' $*
|
||||
#hiegrep ':\+$' 'Empty lines' $*
|
||||
hiegrep ';;' 'double ;' $*
|
||||
hiegrep2 '\b_[a-zA-Z0-9_]{1,}' '__(asm|attribute)([^a-zA-Z0-9]|$)' 'reserved identifer' $*
|
||||
hiegrep '//[-/<\* ]*$' 'empty comment' $*
|
||||
hiegrep '/\*[-<\* ]*\*/' 'empty comment' $*
|
||||
hiegrep 'for *\( *'"$ERE_PRITYP"' ' 'not gcc 2.95 compatible' $*
|
||||
hiegrep '(static|inline|const) *\1[^_a-zA-Z]' 'duplicate word' $*
|
||||
hiegrep 'INIT_VLC_USE_STATIC' 'forbidden ancient vlc type' $*
|
||||
hiegrep '=[-+\*\&] ' 'looks like compound assignment' $*
|
||||
hiegrep2 '/\*\* *[a-zA-Z0-9].*' '\*/' 'Inconsistently formatted doxygen comment' $*
|
||||
hiegrep '; */\*\*[^<]' 'Misformatted doxygen comment' $*
|
||||
hiegrep '//!|/\*!' 'inconsistent doxygen syntax' $*
|
||||
|
||||
hiegrep2 '(int|unsigned|static|void)[a-zA-Z0-9 _]*(init|end)[a-zA-Z0-9 _]*\(.*[^;]$' '(av_cold|:\+[^a-zA-Z_])' 'These functions may need av_cold, please review the whole patch for similar functions needing av_cold' $*
|
||||
|
||||
hiegrep '\+= *1 *;' 'can be simplified to ++' $*
|
||||
hiegrep '-= *1 *;' 'can be simplified to --' $*
|
||||
hiegrep '((!|=)= *(0|NULL)[^0-9a-z]|[^0-9a-z](0|NULL) *(!|=)=)' 'x==0 / x!=0 can be simplified to !x / x' $*
|
||||
|
||||
$EGREP $OPT '^\+ *(const *|)static' $*| $EGREP --color=always '[^=]= *(0|NULL)[^0-9a-zA-Z]'> $TMP && printf '\nuseless 0 init\n'
|
||||
cat $TMP
|
||||
hiegrep '# *ifdef * (HAVE|CONFIG)_' 'ifdefs that should be #if' $*
|
||||
|
||||
hiegrep '\b(awnser|cant|dont|wont|doesnt|usefull|successfull|occured|teh|alot|wether|skiped|skiping|heigth|informations|colums|loosy|loosing|ouput|seperate|preceed|upto|paket|posible|unkown|inpossible|dimention|acheive|funtions|overriden|outputing|seperation|initalize|compatibilty|bistream|knwon|unknwon|choosen|additonal|gurantee|availble|wich)\b' 'common typos' $*
|
||||
|
||||
hiegrep 'av_log\( *NULL' 'Missing context in av_log' $*
|
||||
hiegrep '[^sn]printf' 'Please use av_log' $*
|
||||
hiegrep '\bmalloc' 'Please use av_malloc' $*
|
||||
hiegrep '\) *av_malloc' 'useless casts' $*
|
||||
hiegrep ':\+ *'"$ERE_PRITYP"' *inline' 'non static inline or strangely ordered inline+static' $*
|
||||
hiegrep "$ERE_FUNCS"' *\)' 'missing void' $*
|
||||
hiegrep '(sprintf|strcat|strcpy)' 'Possible security issue, make sure this is safe or use snprintf/av_strl*' $*
|
||||
hiegrep '/ *(2|4|8|16|32|64|128|256|512|1024|2048|4096|8192|16384|32768|65536)[^0-9]' 'divide by 2^x could use >> maybe' $*
|
||||
hiegrep '#(el|)if *(0|1)' 'useless #if' $*
|
||||
hiegrep 'if *\( *(0|1) *\)' 'useless if()' $*
|
||||
hiegrep '& *[a-zA-Z0-9_]* *\[ *0 *\]' 'useless & [0]' $*
|
||||
hiegrep '(\( *[0-9] *(&&|\|\|)|(&&|\|\|) *[0-9] *\))' 'overriding condition' $*
|
||||
hiegrep '(:\+|,|;)( *|static|\*)*'"$ERE_PRITYP"' *\*( |\*)*(src|source|input|in[^a-z])' 'missing const?' $*
|
||||
hiegrep '(:\+|,|;)( *|static|\*)*'"$ERE_PRITYP"' *(src|source|input|in)([0-9A-Z_][0-9A-Za-z_]*){1,} *\[' 'missing const (test2)?' $*
|
||||
hiegrep ' *static *'"$ERE_FUNCS"'[^)]*\);' 'static prototype, maybe you should reorder your functions' $*
|
||||
hiegrep '@file: *[a-zA-Z0-9_]' 'doxy filetag with filename can in the future cause problems when forgotten during a rename' $*
|
||||
hiegrep '\bassert' 'Please use av_assert0, av_assert1 or av_assert2' $*
|
||||
|
||||
hiegrep2 '\.long_name *=' 'NULL_IF_CONFIG_SMAL' 'missing NULL_IF_CONFIG_SMAL' $*
|
||||
hiegrep2 '\.pix_fmts *= *\(' 'const' 'missing const for pix_fmts array' $*
|
||||
hiegrep2 '\.sample_fmts *= *\(' 'const' 'missing const for sample_fmts array' $*
|
||||
hiegrep2 '\.supported_framerates *= *\(' 'const' 'missing const for supported_framerates array' $*
|
||||
hiegrep2 '\.channel_layouts *= *\(' 'const' 'missing const for channel_layouts array' $*
|
||||
|
||||
#$EGREP $OPT '^\+.*const ' $*| $GREP -v 'static'> $TMP && printf '\nnon static const\n'
|
||||
#cat $TMP
|
||||
|
||||
hiegrep2 "$ERE_TYPES" '(static|av_|ff_|typedef|:\+[^a-zA-Z_])' 'Non static with no ff_/av_ prefix' $*
|
||||
|
||||
hiegrep ':\+[^}#]*else' 'missing } prior to else' $*
|
||||
hiegrep '(if|while|for)\(' 'missing whitespace between keyword and ( (feel free to ignore)' $*
|
||||
hiegrep '(else|do){' 'missing whitespace between keyword and { (feel free to ignore)' $*
|
||||
hiegrep '}(else|while)' 'missing whitespace between } and keyword (feel free to ignore)' $*
|
||||
|
||||
#FIXME this should print the previous statement maybe
|
||||
hiegrep ':\+ *{ *$' '{ should be on the same line as the related previous statement' $*
|
||||
|
||||
|
||||
rm $TMP
|
||||
for i in $($GREP -H '^+.*@param' $*| sed 's/^\([^:]*\):.*@param\(\[.*\]\|\) *\([a-zA-Z0-9_]*\) .*$/\1:\3/') ; do
|
||||
doxpar=$(echo $i | sed 's/^.*:\(.*\)$/\1/')
|
||||
file=$(echo $i | sed 's/^\([^:]*\):.*$/\1/')
|
||||
$GREP " *$doxpar *[),]" $file | $GREP -v '@param' >/dev/null || $GREP --color=always "@param *$doxpar" $file >>$TMP
|
||||
done
|
||||
if test -e $TMP ; then
|
||||
printf '\nmismatching doxy params\n'
|
||||
cat $TMP
|
||||
fi
|
||||
|
||||
$EGREP -B2 $OPT '^(\+|) *('"$ERE_TYPES"'|# *define)' $* | $EGREP -A2 --color=always '(:|-)\+[^/]*/(\*([^*]|$)|/([^/]|$))' > $TMP && printf "\n Non doxy comments\n"
|
||||
cat $TMP
|
||||
|
||||
rm $TMP
|
||||
for i in \
|
||||
$($EGREP -H '^\+ *'"$ERE_TYPES" $* |\
|
||||
$GREP -v '(' | $EGREP -v '\Wgoto\W' |\
|
||||
xargs -d '\n' -n 1 |\
|
||||
$GREP -o '[* ][* ]*[a-zA-Z][0-9a-zA-Z_]* *[,;=]' |\
|
||||
sed 's/.[* ]*\([a-zA-Z][0-9a-zA-Z_]*\) *[,;=]/\1/') \
|
||||
; do
|
||||
echo $i | $GREP '^NULL$' && continue
|
||||
$EGREP $i' *(\+|-|\*|/|\||&|%|)=[^=]' $* >/dev/null || echo "possibly never written:"$i >> $TMP
|
||||
$EGREP '(=|\(|return).*'$i'(==|[^=])*$' $* >/dev/null || echo "possibly never read :"$i >> $TMP
|
||||
$EGREP -o $i' *((\+|-|\*|/|\||&|%|)=[^=]|\+\+|--) *(0x|)[0-9]*(;|)' $* |\
|
||||
$EGREP -v $i' *= *(0x|)[0-9]{1,};'>/dev/null || echo "possibly constant :"$i >> $TMP
|
||||
done
|
||||
if test -e $TMP ; then
|
||||
printf '\npossibly unused variables\n'
|
||||
cat $TMP
|
||||
fi
|
||||
|
||||
$GREP '^+++ .*Changelog' $* >/dev/null || printf "\nMissing changelog entry (ignore if minor change)\n"
|
||||
|
||||
cat $* | tr '\n' '@' | $EGREP --color=always -o '(fprintf|av_log|printf)\([^)]*\)[+ ;@]*\1' >$TMP && printf "\nMergeable calls\n"
|
||||
cat $TMP | tr '@' '\n'
|
||||
|
||||
cat $* | tr '\n' '@' | $EGREP --color=always -o '\+ *if *\( *([A-Za-z0-9_]*) *[<>]=? *[0-9]* *\) * \1 *= *[0-9]* *;[ @\\+]*else *if *\( *\1 *[<>]=? *[0-9]* *\) *\1 *= *[0-9]* *;' >$TMP && printf "\nav_clip / av_clip_uint8 / av_clip_int16 / ...\n"
|
||||
cat $TMP | tr '@' '\n'
|
||||
|
||||
cat $* | tr '\n' '@' | $EGREP --color=always -o '\+ *if *\( *([A-Za-z0-9_]*) *[<>]=? *([A-Za-z0-9_]*) *\)[ @\\+]*(\1|\2) *= *(\1|\2) *;' >$TMP && printf "\nFFMIN/FFMAX\n"
|
||||
cat $TMP | tr '@' '\n'
|
||||
|
||||
cat $* | tr '\n' '@' | $EGREP --color=always -o '\+ *if *\( *([A-Za-z0-9_]*) *\)[ @\\+]*av_free(p|) *\( *(&|) *\1[^-.]' >$TMP && printf "\nav_free(NULL) is safe\n"
|
||||
cat $TMP | tr '@' '\n'
|
||||
|
||||
cat $* | tr '\n' '@' | $EGREP --color=always -o '[^a-zA-Z0-9_]([a-zA-Z0-9_]*) *= *av_malloc *\([^)]*\)[ @;\\+]*memset *\( *\1' >$TMP && printf "\nav_mallocz()\n"
|
||||
cat $TMP | tr '@' '\n'
|
||||
|
||||
|
||||
# does not work
|
||||
#cat $* | tr '\n' '@' | $EGREP -o '[^a-zA-Z_0-9]([a-zA-Z][a-zA-Z_0-9]*) *=[^=].*\1' | $EGREP -o '[^a-zA-Z_0-9]([a-zA-Z][a-zA-Z_0-9]*) *=[^=].*\1 *=[^=]' >$TMP && printf "\nPossibly written 2x before read\n"
|
||||
#cat $TMP | tr '@' '\n'
|
||||
|
||||
exit
|
||||
|
||||
TODO/idea list:
|
||||
|
||||
for all demuxers & muxers
|
||||
$EGREP for "avctx->priv_data"
|
||||
|
||||
vertical align =
|
||||
/* and * align
|
||||
arrays fitting in smaller types
|
||||
variables written to twice with no interspaced read
|
||||
memset(block, 0, 6*64*sizeof(int16_t)); -> clear_blocks
|
||||
check existence of long_name in AVCodec
|
||||
check that the patch does not touch codec & (de)muxer layer at the same time ->split
|
||||
|
||||
write a regression test containing at least a line that triggers each warning once
|
137
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/pktdumper.c
Normal file
137
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/pktdumper.c
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (c) 2005 Francois Revol
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <limits.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if HAVE_IO_H
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#include "libavutil/avstring.h"
|
||||
#include "libavutil/time.h"
|
||||
#include "libavformat/avformat.h"
|
||||
|
||||
#define FILENAME_BUF_SIZE 4096
|
||||
#define PKTFILESUFF "_%08" PRId64 "_%02d_%010" PRId64 "_%06d_%c.bin"
|
||||
|
||||
static int usage(int ret)
|
||||
{
|
||||
fprintf(stderr, "Dump (up to maxpkts) AVPackets as they are demuxed by libavformat.\n");
|
||||
fprintf(stderr, "Each packet is dumped in its own file named like\n");
|
||||
fprintf(stderr, "$(basename file.ext)_$PKTNUM_$STREAMINDEX_$STAMP_$SIZE_$FLAGS.bin\n");
|
||||
fprintf(stderr, "pktdumper [-nw] file [maxpkts]\n");
|
||||
fprintf(stderr, "-n\twrite No file at all, only demux.\n");
|
||||
fprintf(stderr, "-w\tWait at end of processing instead of quitting.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char fntemplate[FILENAME_BUF_SIZE];
|
||||
char pktfilename[FILENAME_BUF_SIZE];
|
||||
AVFormatContext *fctx = NULL;
|
||||
AVPacket pkt;
|
||||
int64_t pktnum = 0;
|
||||
int64_t maxpkts = 0;
|
||||
int donotquit = 0;
|
||||
int nowrite = 0;
|
||||
int err;
|
||||
|
||||
if ((argc > 1) && !strncmp(argv[1], "-", 1)) {
|
||||
if (strchr(argv[1], 'w'))
|
||||
donotquit = 1;
|
||||
if (strchr(argv[1], 'n'))
|
||||
nowrite = 1;
|
||||
argv++;
|
||||
argc--;
|
||||
}
|
||||
if (argc < 2)
|
||||
return usage(1);
|
||||
if (argc > 2)
|
||||
maxpkts = atoi(argv[2]);
|
||||
av_strlcpy(fntemplate, argv[1], sizeof(fntemplate));
|
||||
if (strrchr(argv[1], '/'))
|
||||
av_strlcpy(fntemplate, strrchr(argv[1], '/') + 1, sizeof(fntemplate));
|
||||
if (strrchr(fntemplate, '.'))
|
||||
*strrchr(fntemplate, '.') = '\0';
|
||||
if (strchr(fntemplate, '%')) {
|
||||
fprintf(stderr, "cannot use filenames containing '%%'\n");
|
||||
return usage(1);
|
||||
}
|
||||
if (strlen(fntemplate) + sizeof(PKTFILESUFF) >= sizeof(fntemplate) - 1) {
|
||||
fprintf(stderr, "filename too long\n");
|
||||
return usage(1);
|
||||
}
|
||||
strcat(fntemplate, PKTFILESUFF);
|
||||
printf("FNTEMPLATE: '%s'\n", fntemplate);
|
||||
|
||||
// register all file formats
|
||||
av_register_all();
|
||||
|
||||
err = avformat_open_input(&fctx, argv[1], NULL, NULL);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "cannot open input: error %d\n", err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
err = avformat_find_stream_info(fctx, NULL);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "avformat_find_stream_info: error %d\n", err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
av_init_packet(&pkt);
|
||||
|
||||
while ((err = av_read_frame(fctx, &pkt)) >= 0) {
|
||||
int fd;
|
||||
snprintf(pktfilename, sizeof(pktfilename), fntemplate, pktnum,
|
||||
pkt.stream_index, pkt.pts, pkt.size,
|
||||
(pkt.flags & AV_PKT_FLAG_KEY) ? 'K' : '_');
|
||||
printf(PKTFILESUFF "\n", pktnum, pkt.stream_index, pkt.pts, pkt.size,
|
||||
(pkt.flags & AV_PKT_FLAG_KEY) ? 'K' : '_');
|
||||
if (!nowrite) {
|
||||
fd = open(pktfilename, O_WRONLY | O_CREAT, 0644);
|
||||
err = write(fd, pkt.data, pkt.size);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "write: error %d\n", err);
|
||||
return 1;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
av_free_packet(&pkt);
|
||||
pktnum++;
|
||||
if (maxpkts && (pktnum >= maxpkts))
|
||||
break;
|
||||
}
|
||||
|
||||
avformat_close_input(&fctx);
|
||||
|
||||
while (donotquit)
|
||||
av_usleep(60 * 1000000);
|
||||
|
||||
return 0;
|
||||
}
|
164
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/plotframes
Normal file
164
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/plotframes
Normal file
@@ -0,0 +1,164 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
# Copyright (c) 2007-2013 Stefano Sabatini
|
||||
#
|
||||
# This file is part of FFmpeg.
|
||||
#
|
||||
# FFmpeg is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# FFmpeg 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 Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=head1 NAME
|
||||
|
||||
plotframes - Plot video frame sizes using ffprobe and gnuplot
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
plotframes [I<options>] [I<input>]
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
plotframes reads a multimedia files with ffprobe, and plots the
|
||||
collected video sizes with gnuplot.
|
||||
|
||||
=head1 OPTIONS
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<--input|-i> I<infile>
|
||||
|
||||
Specify multimedia file to read. This is the file passed to the
|
||||
ffprobe command. If not specified it is the first argument passed to
|
||||
the script.
|
||||
|
||||
=item B<--help|--usage|-h|-?>
|
||||
|
||||
Print a brief help message and exit.
|
||||
|
||||
=item B<--manpage|-m>
|
||||
|
||||
Print the man page.
|
||||
|
||||
=item B<--output|-o> I<outfile>
|
||||
|
||||
Set the name of the output used by gnuplot. If not specified no output
|
||||
is created. Must be used in conjunction with the B<terminal> option.
|
||||
|
||||
=item B<--stream|--s> I<stream_specifier>
|
||||
|
||||
Specify stream. The value must be a string containing a stream
|
||||
specifier. Default value is "v".
|
||||
|
||||
=item B<--terminal|-t> I<terminal>
|
||||
|
||||
Set the name of the terminal used by gnuplot. By default it is
|
||||
"x11". Must be used in conjunction with the B<output> option. Check
|
||||
the gnuplot manual for the valid values.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
ffprobe(1), gnuplot(1)
|
||||
|
||||
=cut
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
use File::Temp;
|
||||
use JSON -support_by_pp;
|
||||
use Getopt::Long;
|
||||
use Pod::Usage;
|
||||
|
||||
my $input = $ARGV[0];
|
||||
my $stream_specifier = "v";
|
||||
my $gnuplot_terminal = "x11";
|
||||
my $gnuplot_output;
|
||||
|
||||
GetOptions (
|
||||
'input|i=s' => \$input,
|
||||
'help|usage|?|h' => sub { pod2usage ( { -verbose => 1, -exitval => 0 }) },
|
||||
'manpage|m' => sub { pod2usage ( { -verbose => 2, -exitval => 0 }) },
|
||||
'stream|s=s' => \$stream_specifier,
|
||||
'terminal|t=s' => \$gnuplot_terminal,
|
||||
'output|o=s' => \$gnuplot_output,
|
||||
) or pod2usage( { -message=> "Parsing error", -verbose => 1, -exitval => 1 });
|
||||
|
||||
die "You must specify an input file\n" unless $input;
|
||||
|
||||
# fetch data
|
||||
my @cmd = (qw{ffprobe -show_entries frame -select_streams}, $stream_specifier, "-of", "json", $input);
|
||||
print STDERR "Executing command: @cmd\n";
|
||||
my $json_struct;
|
||||
{
|
||||
open(FH, "-|", @cmd) or die "ffprobe command failed: $!\n";
|
||||
local $/;
|
||||
my $json_text = <FH>;
|
||||
close FH;
|
||||
die "ffprobe command failed" if $?;
|
||||
eval { $json_struct = decode_json($json_text); };
|
||||
die "JSON parsing error: $@\n" if $@;
|
||||
}
|
||||
|
||||
# collect and print frame statistics per pict_type
|
||||
my %stats;
|
||||
my $frames = $json_struct->{frames};
|
||||
my $frame_count = 0;
|
||||
foreach my $frame (@{$frames}) {
|
||||
my $type = $frame->{pict_type};
|
||||
$frame->{count} = $frame_count++;
|
||||
if (not $stats{$type}) {
|
||||
$stats{$type}->{tmpfile} = File::Temp->new(SUFFIX => '.dat');
|
||||
my $fn = $stats{$type}->{tmpfile}->filename;
|
||||
open($stats{$type}->{fh}, ">", $fn) or die "Can't open $fn";
|
||||
}
|
||||
|
||||
print { $stats{$type}->{fh} }
|
||||
"$frame->{count} ", $frame->{pkt_size} * 8 / 1000, "\n";
|
||||
}
|
||||
foreach (keys %stats) { close $stats{$_}->{fh}; }
|
||||
|
||||
# write gnuplot script
|
||||
my %type_color_map = (
|
||||
"I" => "red",
|
||||
"P" => "green",
|
||||
"B" => "blue"
|
||||
);
|
||||
|
||||
my $gnuplot_script_tmpfile = File::Temp->new(SUFFIX => '.gnuplot');
|
||||
my $fn = $gnuplot_script_tmpfile->filename;
|
||||
open(FH, ">", $fn) or die "Couldn't open $fn: $!";
|
||||
print FH << "EOF";
|
||||
set title "video frame sizes"
|
||||
set xlabel "frame time"
|
||||
set ylabel "frame size (Kbits)"
|
||||
set grid
|
||||
set terminal "$gnuplot_terminal"
|
||||
EOF
|
||||
|
||||
print FH "set output \"$gnuplot_output\"\n" if $gnuplot_output;
|
||||
print FH "plot";
|
||||
my $sep = "";
|
||||
foreach my $type (keys %stats) {
|
||||
my $fn = $stats{$type}->{tmpfile}->filename;
|
||||
print FH "$sep\"$fn\" title \"$type frames\" with impulses";
|
||||
print FH " linecolor rgb \"$type_color_map{$type}\"" if $type_color_map{$type};
|
||||
$sep = ", ";
|
||||
}
|
||||
close FH;
|
||||
|
||||
# launch gnuplot with the generated script
|
||||
system ("gnuplot", "--persist", $gnuplot_script_tmpfile->filename);
|
203
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/probetest.c
Normal file
203
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/probetest.c
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libavformat/avformat.h"
|
||||
#include "libavcodec/put_bits.h"
|
||||
#include "libavutil/lfg.h"
|
||||
#include "libavutil/timer.h"
|
||||
|
||||
#define MAX_FORMATS 1000 //this must be larger than the number of formats
|
||||
static int score_array[MAX_FORMATS];
|
||||
static int64_t time_array[MAX_FORMATS];
|
||||
static int failures = 0;
|
||||
static const char *single_format;
|
||||
|
||||
#ifndef AV_READ_TIME
|
||||
#define AV_READ_TIME(x) 0
|
||||
#endif
|
||||
|
||||
static void probe(AVProbeData *pd, int type, int p, int size)
|
||||
{
|
||||
int i = 0;
|
||||
AVInputFormat *fmt = NULL;
|
||||
|
||||
while ((fmt = av_iformat_next(fmt))) {
|
||||
if (fmt->flags & AVFMT_NOFILE)
|
||||
continue;
|
||||
if (fmt->read_probe &&
|
||||
(!single_format || !strcmp(single_format, fmt->name))
|
||||
) {
|
||||
int score;
|
||||
int64_t start = AV_READ_TIME();
|
||||
score = fmt->read_probe(pd);
|
||||
time_array[i] += AV_READ_TIME() - start;
|
||||
if (score > score_array[i] && score > AVPROBE_SCORE_MAX / 4) {
|
||||
score_array[i] = score;
|
||||
fprintf(stderr,
|
||||
"Failure of %s probing code with score=%d type=%d p=%X size=%d\n",
|
||||
fmt->name, score, type, p, size);
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
static void print_times(void)
|
||||
{
|
||||
int i = 0;
|
||||
AVInputFormat *fmt = NULL;
|
||||
|
||||
while ((fmt = av_iformat_next(fmt))) {
|
||||
if (fmt->flags & AVFMT_NOFILE)
|
||||
continue;
|
||||
if (time_array[i] > 1000000) {
|
||||
fprintf(stderr, "%12"PRIu64" cycles, %12s\n",
|
||||
time_array[i], fmt->name);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
static int read_int(char *arg) {
|
||||
int ret;
|
||||
|
||||
if (!arg || !*arg)
|
||||
return -1;
|
||||
ret = strtol(arg, &arg, 0);
|
||||
if (*arg)
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned int p, i, type, size, retry;
|
||||
AVProbeData pd = { 0 };
|
||||
AVLFG state;
|
||||
PutBitContext pb;
|
||||
int retry_count= 4097;
|
||||
int max_size = 65537;
|
||||
int j;
|
||||
|
||||
for (j = i = 1; i<argc; i++) {
|
||||
if (!strcmp(argv[i], "-f") && i+1<argc && !single_format) {
|
||||
single_format = argv[++i];
|
||||
} else if (read_int(argv[i])>0 && j == 1) {
|
||||
retry_count = read_int(argv[i]);
|
||||
j++;
|
||||
} else if (read_int(argv[i])>0 && j == 2) {
|
||||
max_size = read_int(argv[i]);
|
||||
j++;
|
||||
} else {
|
||||
fprintf(stderr, "probetest [-f <input format>] [<retry_count> [<max_size>]]\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (max_size > 1000000000U/8) {
|
||||
fprintf(stderr, "max_size out of bounds\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (retry_count > 1000000000U) {
|
||||
fprintf(stderr, "retry_count out of bounds\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
avcodec_register_all();
|
||||
av_register_all();
|
||||
|
||||
av_lfg_init(&state, 0xdeadbeef);
|
||||
|
||||
pd.buf = NULL;
|
||||
for (size = 1; size < max_size; size *= 2) {
|
||||
pd.buf_size = size;
|
||||
pd.buf = av_realloc(pd.buf, size + AVPROBE_PADDING_SIZE);
|
||||
pd.filename = "";
|
||||
|
||||
if (!pd.buf) {
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(pd.buf, 0, size + AVPROBE_PADDING_SIZE);
|
||||
|
||||
fprintf(stderr, "testing size=%d\n", size);
|
||||
|
||||
for (retry = 0; retry < retry_count; retry += FFMAX(size, 32)) {
|
||||
for (type = 0; type < 4; type++) {
|
||||
for (p = 0; p < 4096; p++) {
|
||||
unsigned hist = 0;
|
||||
init_put_bits(&pb, pd.buf, size);
|
||||
switch (type) {
|
||||
case 0:
|
||||
for (i = 0; i < size * 8; i++)
|
||||
put_bits(&pb, 1, (av_lfg_get(&state) & 0xFFFFFFFF) > p << 20);
|
||||
break;
|
||||
case 1:
|
||||
for (i = 0; i < size * 8; i++) {
|
||||
unsigned int p2 = hist ? p & 0x3F : (p >> 6);
|
||||
unsigned int v = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 26;
|
||||
put_bits(&pb, 1, v);
|
||||
hist = v;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
for (i = 0; i < size * 8; i++) {
|
||||
unsigned int p2 = (p >> (hist * 3)) & 7;
|
||||
unsigned int v = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 29;
|
||||
put_bits(&pb, 1, v);
|
||||
hist = (2 * hist + v) & 3;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
for (i = 0; i < size; i++) {
|
||||
int c = 0;
|
||||
while (p & 63) {
|
||||
c = (av_lfg_get(&state) & 0xFFFFFFFF) >> 24;
|
||||
if (c >= 'a' && c <= 'z' && (p & 1))
|
||||
break;
|
||||
else if (c >= 'A' && c <= 'Z' && (p & 2))
|
||||
break;
|
||||
else if (c >= '0' && c <= '9' && (p & 4))
|
||||
break;
|
||||
else if (c == ' ' && (p & 8))
|
||||
break;
|
||||
else if (c == 0 && (p & 16))
|
||||
break;
|
||||
else if (c == 1 && (p & 32))
|
||||
break;
|
||||
}
|
||||
pd.buf[i] = c;
|
||||
}
|
||||
}
|
||||
flush_put_bits(&pb);
|
||||
probe(&pd, type, p, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(AV_READ_TIME())
|
||||
print_times();
|
||||
return failures;
|
||||
}
|
365
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/qt-faststart.c
Normal file
365
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/qt-faststart.c
Normal file
@@ -0,0 +1,365 @@
|
||||
/*
|
||||
* qt-faststart.c, v0.2
|
||||
* by Mike Melanson (melanson@pcisys.net)
|
||||
* This file is placed in the public domain. Use the program however you
|
||||
* see fit.
|
||||
*
|
||||
* This utility rearranges a Quicktime file such that the moov atom
|
||||
* is in front of the data, thus facilitating network streaming.
|
||||
*
|
||||
* To compile this program, start from the base directory from which you
|
||||
* are building FFmpeg and type:
|
||||
* make tools/qt-faststart
|
||||
* The qt-faststart program will be built in the tools/ directory. If you
|
||||
* do not build the program in this manner, correct results are not
|
||||
* guaranteed, particularly on 64-bit platforms.
|
||||
* Invoke the program with:
|
||||
* qt-faststart <infile.mov> <outfile.mov>
|
||||
*
|
||||
* Notes: Quicktime files can come in many configurations of top-level
|
||||
* atoms. This utility stipulates that the very last atom in the file needs
|
||||
* to be a moov atom. When given such a file, this utility will rearrange
|
||||
* the top-level atoms by shifting the moov atom from the back of the file
|
||||
* to the front, and patch the chunk offsets along the way. This utility
|
||||
* presently only operates on uncompressed moov atoms.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#undef fseeko
|
||||
#define fseeko(x, y, z) fseeko64(x, y, z)
|
||||
#undef ftello
|
||||
#define ftello(x) ftello64(x)
|
||||
#elif defined(_WIN32)
|
||||
#undef fseeko
|
||||
#define fseeko(x, y, z) _fseeki64(x, y, z)
|
||||
#undef ftello
|
||||
#define ftello(x) _ftelli64(x)
|
||||
#endif
|
||||
|
||||
#define MIN(a,b) ((a) > (b) ? (b) : (a))
|
||||
|
||||
#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
|
||||
|
||||
#define BE_32(x) (((uint32_t)(((uint8_t*)(x))[0]) << 24) | \
|
||||
(((uint8_t*)(x))[1] << 16) | \
|
||||
(((uint8_t*)(x))[2] << 8) | \
|
||||
((uint8_t*)(x))[3])
|
||||
|
||||
#define BE_64(x) (((uint64_t)(((uint8_t*)(x))[0]) << 56) | \
|
||||
((uint64_t)(((uint8_t*)(x))[1]) << 48) | \
|
||||
((uint64_t)(((uint8_t*)(x))[2]) << 40) | \
|
||||
((uint64_t)(((uint8_t*)(x))[3]) << 32) | \
|
||||
((uint64_t)(((uint8_t*)(x))[4]) << 24) | \
|
||||
((uint64_t)(((uint8_t*)(x))[5]) << 16) | \
|
||||
((uint64_t)(((uint8_t*)(x))[6]) << 8) | \
|
||||
((uint64_t)( (uint8_t*)(x))[7]))
|
||||
|
||||
#define BE_FOURCC(ch0, ch1, ch2, ch3) \
|
||||
( (uint32_t)(unsigned char)(ch3) | \
|
||||
((uint32_t)(unsigned char)(ch2) << 8) | \
|
||||
((uint32_t)(unsigned char)(ch1) << 16) | \
|
||||
((uint32_t)(unsigned char)(ch0) << 24) )
|
||||
|
||||
#define QT_ATOM BE_FOURCC
|
||||
/* top level atoms */
|
||||
#define FREE_ATOM QT_ATOM('f', 'r', 'e', 'e')
|
||||
#define JUNK_ATOM QT_ATOM('j', 'u', 'n', 'k')
|
||||
#define MDAT_ATOM QT_ATOM('m', 'd', 'a', 't')
|
||||
#define MOOV_ATOM QT_ATOM('m', 'o', 'o', 'v')
|
||||
#define PNOT_ATOM QT_ATOM('p', 'n', 'o', 't')
|
||||
#define SKIP_ATOM QT_ATOM('s', 'k', 'i', 'p')
|
||||
#define WIDE_ATOM QT_ATOM('w', 'i', 'd', 'e')
|
||||
#define PICT_ATOM QT_ATOM('P', 'I', 'C', 'T')
|
||||
#define FTYP_ATOM QT_ATOM('f', 't', 'y', 'p')
|
||||
#define UUID_ATOM QT_ATOM('u', 'u', 'i', 'd')
|
||||
|
||||
#define CMOV_ATOM QT_ATOM('c', 'm', 'o', 'v')
|
||||
#define STCO_ATOM QT_ATOM('s', 't', 'c', 'o')
|
||||
#define CO64_ATOM QT_ATOM('c', 'o', '6', '4')
|
||||
|
||||
#define ATOM_PREAMBLE_SIZE 8
|
||||
#define COPY_BUFFER_SIZE 33554432
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *infile = NULL;
|
||||
FILE *outfile = NULL;
|
||||
unsigned char atom_bytes[ATOM_PREAMBLE_SIZE];
|
||||
uint32_t atom_type = 0;
|
||||
uint64_t atom_size = 0;
|
||||
uint64_t atom_offset = 0;
|
||||
int64_t last_offset;
|
||||
unsigned char *moov_atom = NULL;
|
||||
unsigned char *ftyp_atom = NULL;
|
||||
uint64_t moov_atom_size;
|
||||
uint64_t ftyp_atom_size = 0;
|
||||
uint64_t i, j;
|
||||
uint32_t offset_count;
|
||||
uint64_t current_offset;
|
||||
int64_t start_offset = 0;
|
||||
unsigned char *copy_buffer = NULL;
|
||||
int bytes_to_copy;
|
||||
|
||||
if (argc != 3) {
|
||||
printf("Usage: qt-faststart <infile.mov> <outfile.mov>\n"
|
||||
"Note: alternatively you can use -movflags +faststart in ffmpeg\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], argv[2])) {
|
||||
fprintf(stderr, "input and output files need to be different\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
infile = fopen(argv[1], "rb");
|
||||
if (!infile) {
|
||||
perror(argv[1]);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
/* traverse through the atoms in the file to make sure that 'moov' is
|
||||
* at the end */
|
||||
while (!feof(infile)) {
|
||||
if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
|
||||
break;
|
||||
}
|
||||
atom_size = BE_32(&atom_bytes[0]);
|
||||
atom_type = BE_32(&atom_bytes[4]);
|
||||
|
||||
/* keep ftyp atom */
|
||||
if (atom_type == FTYP_ATOM) {
|
||||
ftyp_atom_size = atom_size;
|
||||
free(ftyp_atom);
|
||||
ftyp_atom = malloc(ftyp_atom_size);
|
||||
if (!ftyp_atom) {
|
||||
printf("could not allocate %"PRIu64" bytes for ftyp atom\n",
|
||||
atom_size);
|
||||
goto error_out;
|
||||
}
|
||||
if (fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR) ||
|
||||
fread(ftyp_atom, atom_size, 1, infile) != 1 ||
|
||||
(start_offset = ftello(infile)) < 0) {
|
||||
perror(argv[1]);
|
||||
goto error_out;
|
||||
}
|
||||
} else {
|
||||
int ret;
|
||||
/* 64-bit special case */
|
||||
if (atom_size == 1) {
|
||||
if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
|
||||
break;
|
||||
}
|
||||
atom_size = BE_64(&atom_bytes[0]);
|
||||
ret = fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE * 2, SEEK_CUR);
|
||||
} else {
|
||||
ret = fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR);
|
||||
}
|
||||
if (ret) {
|
||||
perror(argv[1]);
|
||||
goto error_out;
|
||||
}
|
||||
}
|
||||
printf("%c%c%c%c %10"PRIu64" %"PRIu64"\n",
|
||||
(atom_type >> 24) & 255,
|
||||
(atom_type >> 16) & 255,
|
||||
(atom_type >> 8) & 255,
|
||||
(atom_type >> 0) & 255,
|
||||
atom_offset,
|
||||
atom_size);
|
||||
if ((atom_type != FREE_ATOM) &&
|
||||
(atom_type != JUNK_ATOM) &&
|
||||
(atom_type != MDAT_ATOM) &&
|
||||
(atom_type != MOOV_ATOM) &&
|
||||
(atom_type != PNOT_ATOM) &&
|
||||
(atom_type != SKIP_ATOM) &&
|
||||
(atom_type != WIDE_ATOM) &&
|
||||
(atom_type != PICT_ATOM) &&
|
||||
(atom_type != UUID_ATOM) &&
|
||||
(atom_type != FTYP_ATOM)) {
|
||||
printf("encountered non-QT top-level atom (is this a QuickTime file?)\n");
|
||||
break;
|
||||
}
|
||||
atom_offset += atom_size;
|
||||
|
||||
/* The atom header is 8 (or 16 bytes), if the atom size (which
|
||||
* includes these 8 or 16 bytes) is less than that, we won't be
|
||||
* able to continue scanning sensibly after this atom, so break. */
|
||||
if (atom_size < 8)
|
||||
break;
|
||||
}
|
||||
|
||||
if (atom_type != MOOV_ATOM) {
|
||||
printf("last atom in file was not a moov atom\n");
|
||||
free(ftyp_atom);
|
||||
fclose(infile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* moov atom was, in fact, the last atom in the chunk; load the whole
|
||||
* moov atom */
|
||||
if (fseeko(infile, -atom_size, SEEK_END)) {
|
||||
perror(argv[1]);
|
||||
goto error_out;
|
||||
}
|
||||
last_offset = ftello(infile);
|
||||
if (last_offset < 0) {
|
||||
perror(argv[1]);
|
||||
goto error_out;
|
||||
}
|
||||
moov_atom_size = atom_size;
|
||||
moov_atom = malloc(moov_atom_size);
|
||||
if (!moov_atom) {
|
||||
printf("could not allocate %"PRIu64" bytes for moov atom\n", atom_size);
|
||||
goto error_out;
|
||||
}
|
||||
if (fread(moov_atom, atom_size, 1, infile) != 1) {
|
||||
perror(argv[1]);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
/* this utility does not support compressed atoms yet, so disqualify
|
||||
* files with compressed QT atoms */
|
||||
if (BE_32(&moov_atom[12]) == CMOV_ATOM) {
|
||||
printf("this utility does not support compressed moov atoms yet\n");
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
/* close; will be re-opened later */
|
||||
fclose(infile);
|
||||
infile = NULL;
|
||||
|
||||
/* crawl through the moov chunk in search of stco or co64 atoms */
|
||||
for (i = 4; i < moov_atom_size - 4; i++) {
|
||||
atom_type = BE_32(&moov_atom[i]);
|
||||
if (atom_type == STCO_ATOM) {
|
||||
printf(" patching stco atom...\n");
|
||||
atom_size = BE_32(&moov_atom[i - 4]);
|
||||
if (i + atom_size - 4 > moov_atom_size) {
|
||||
printf(" bad atom size\n");
|
||||
goto error_out;
|
||||
}
|
||||
offset_count = BE_32(&moov_atom[i + 8]);
|
||||
if (i + 12 + offset_count * UINT64_C(4) > moov_atom_size) {
|
||||
printf(" bad atom size/element count\n");
|
||||
goto error_out;
|
||||
}
|
||||
for (j = 0; j < offset_count; j++) {
|
||||
current_offset = BE_32(&moov_atom[i + 12 + j * 4]);
|
||||
current_offset += moov_atom_size;
|
||||
moov_atom[i + 12 + j * 4 + 0] = (current_offset >> 24) & 0xFF;
|
||||
moov_atom[i + 12 + j * 4 + 1] = (current_offset >> 16) & 0xFF;
|
||||
moov_atom[i + 12 + j * 4 + 2] = (current_offset >> 8) & 0xFF;
|
||||
moov_atom[i + 12 + j * 4 + 3] = (current_offset >> 0) & 0xFF;
|
||||
}
|
||||
i += atom_size - 4;
|
||||
} else if (atom_type == CO64_ATOM) {
|
||||
printf(" patching co64 atom...\n");
|
||||
atom_size = BE_32(&moov_atom[i - 4]);
|
||||
if (i + atom_size - 4 > moov_atom_size) {
|
||||
printf(" bad atom size\n");
|
||||
goto error_out;
|
||||
}
|
||||
offset_count = BE_32(&moov_atom[i + 8]);
|
||||
if (i + 12 + offset_count * UINT64_C(8) > moov_atom_size) {
|
||||
printf(" bad atom size/element count\n");
|
||||
goto error_out;
|
||||
}
|
||||
for (j = 0; j < offset_count; j++) {
|
||||
current_offset = BE_64(&moov_atom[i + 12 + j * 8]);
|
||||
current_offset += moov_atom_size;
|
||||
moov_atom[i + 12 + j * 8 + 0] = (current_offset >> 56) & 0xFF;
|
||||
moov_atom[i + 12 + j * 8 + 1] = (current_offset >> 48) & 0xFF;
|
||||
moov_atom[i + 12 + j * 8 + 2] = (current_offset >> 40) & 0xFF;
|
||||
moov_atom[i + 12 + j * 8 + 3] = (current_offset >> 32) & 0xFF;
|
||||
moov_atom[i + 12 + j * 8 + 4] = (current_offset >> 24) & 0xFF;
|
||||
moov_atom[i + 12 + j * 8 + 5] = (current_offset >> 16) & 0xFF;
|
||||
moov_atom[i + 12 + j * 8 + 6] = (current_offset >> 8) & 0xFF;
|
||||
moov_atom[i + 12 + j * 8 + 7] = (current_offset >> 0) & 0xFF;
|
||||
}
|
||||
i += atom_size - 4;
|
||||
}
|
||||
}
|
||||
|
||||
/* re-open the input file and open the output file */
|
||||
infile = fopen(argv[1], "rb");
|
||||
if (!infile) {
|
||||
perror(argv[1]);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
if (start_offset > 0) { /* seek after ftyp atom */
|
||||
if (fseeko(infile, start_offset, SEEK_SET)) {
|
||||
perror(argv[1]);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
last_offset -= start_offset;
|
||||
}
|
||||
|
||||
outfile = fopen(argv[2], "wb");
|
||||
if (!outfile) {
|
||||
perror(argv[2]);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
/* dump the same ftyp atom */
|
||||
if (ftyp_atom_size > 0) {
|
||||
printf(" writing ftyp atom...\n");
|
||||
if (fwrite(ftyp_atom, ftyp_atom_size, 1, outfile) != 1) {
|
||||
perror(argv[2]);
|
||||
goto error_out;
|
||||
}
|
||||
}
|
||||
|
||||
/* dump the new moov atom */
|
||||
printf(" writing moov atom...\n");
|
||||
if (fwrite(moov_atom, moov_atom_size, 1, outfile) != 1) {
|
||||
perror(argv[2]);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
/* copy the remainder of the infile, from offset 0 -> last_offset - 1 */
|
||||
bytes_to_copy = MIN(COPY_BUFFER_SIZE, last_offset);
|
||||
copy_buffer = malloc(bytes_to_copy);
|
||||
if (!copy_buffer) {
|
||||
printf("could not allocate %d bytes for copy_buffer\n", bytes_to_copy);
|
||||
goto error_out;
|
||||
}
|
||||
printf(" copying rest of file...\n");
|
||||
while (last_offset) {
|
||||
bytes_to_copy = MIN(bytes_to_copy, last_offset);
|
||||
|
||||
if (fread(copy_buffer, bytes_to_copy, 1, infile) != 1) {
|
||||
perror(argv[1]);
|
||||
goto error_out;
|
||||
}
|
||||
if (fwrite(copy_buffer, bytes_to_copy, 1, outfile) != 1) {
|
||||
perror(argv[2]);
|
||||
goto error_out;
|
||||
}
|
||||
last_offset -= bytes_to_copy;
|
||||
}
|
||||
|
||||
fclose(infile);
|
||||
fclose(outfile);
|
||||
free(moov_atom);
|
||||
free(ftyp_atom);
|
||||
free(copy_buffer);
|
||||
|
||||
return 0;
|
||||
|
||||
error_out:
|
||||
if (infile)
|
||||
fclose(infile);
|
||||
if (outfile)
|
||||
fclose(outfile);
|
||||
free(moov_atom);
|
||||
free(ftyp_atom);
|
||||
free(copy_buffer);
|
||||
return 1;
|
||||
}
|
105
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/seek_print.c
Normal file
105
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/seek_print.c
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Nicolas George
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h> /* getopt */
|
||||
#endif
|
||||
|
||||
#include "libavformat/avformat.h"
|
||||
#include "libavutil/timestamp.h"
|
||||
|
||||
#if !HAVE_GETOPT
|
||||
#include "compat/getopt.c"
|
||||
#endif
|
||||
|
||||
static void usage(int ret)
|
||||
{
|
||||
fprintf(ret ? stderr : stdout,
|
||||
"Usage: seek_print file [command ...]\n"
|
||||
"Commands:\n"
|
||||
" read\n"
|
||||
" seek:stream:min_ts:ts:max_ts:flags\n"
|
||||
);
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int opt, ret, stream, flags;
|
||||
const char *filename;
|
||||
AVFormatContext *avf = NULL;
|
||||
int64_t min_ts, max_ts, ts;
|
||||
AVPacket packet;
|
||||
|
||||
while ((opt = getopt(argc, argv, "h")) != -1) {
|
||||
switch (opt) {
|
||||
case 'h':
|
||||
usage(0);
|
||||
default:
|
||||
usage(1);
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (!argc)
|
||||
usage(1);
|
||||
filename = *argv;
|
||||
argv++;
|
||||
argc--;
|
||||
|
||||
av_register_all();
|
||||
if ((ret = avformat_open_input(&avf, filename, NULL, NULL)) < 0) {
|
||||
fprintf(stderr, "%s: %s\n", filename, av_err2str(ret));
|
||||
return 1;
|
||||
}
|
||||
if ((ret = avformat_find_stream_info(avf, NULL)) < 0) {
|
||||
fprintf(stderr, "%s: could not find codec parameters: %s\n", filename,
|
||||
av_err2str(ret));
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (; argc; argc--, argv++) {
|
||||
if (!strcmp(*argv, "read")) {
|
||||
ret = av_read_frame(avf, &packet);
|
||||
if (ret < 0) {
|
||||
printf("read: %d (%s)\n", ret, av_err2str(ret));
|
||||
} else {
|
||||
AVRational *tb = &avf->streams[packet.stream_index]->time_base;
|
||||
printf("read: %d size=%d stream=%d dts=%s (%s) pts=%s (%s)\n",
|
||||
ret, packet.size, packet.stream_index,
|
||||
av_ts2str(packet.dts), av_ts2timestr(packet.dts, tb),
|
||||
av_ts2str(packet.pts), av_ts2timestr(packet.pts, tb));
|
||||
av_free_packet(&packet);
|
||||
}
|
||||
} else if (sscanf(*argv, "seek:%i:%"SCNi64":%"SCNi64":%"SCNi64":%i",
|
||||
&stream, &min_ts, &ts, &max_ts, &flags) == 5) {
|
||||
ret = avformat_seek_file(avf, stream, min_ts, ts, max_ts, flags);
|
||||
printf("seek: %d (%s)\n", ret, av_err2str(ret));
|
||||
} else {
|
||||
fprintf(stderr, "'%s': unknown command\n", *argv);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
avformat_close_input(&avf);
|
||||
|
||||
return 0;
|
||||
}
|
386
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/sidxindex.c
Normal file
386
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/sidxindex.c
Normal file
@@ -0,0 +1,386 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Martin Storsjo
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libavformat/avformat.h"
|
||||
#include "libavutil/avstring.h"
|
||||
#include "libavutil/intreadwrite.h"
|
||||
#include "libavutil/mathematics.h"
|
||||
|
||||
static int usage(const char *argv0, int ret)
|
||||
{
|
||||
fprintf(stderr, "%s -out foo.mpd file1\n", argv0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct Track {
|
||||
const char *name;
|
||||
int64_t duration;
|
||||
int bitrate;
|
||||
int track_id;
|
||||
int is_audio, is_video;
|
||||
int width, height;
|
||||
int sample_rate, channels;
|
||||
int timescale;
|
||||
char codec_str[30];
|
||||
int64_t sidx_start, sidx_length;
|
||||
};
|
||||
|
||||
struct Tracks {
|
||||
int nb_tracks;
|
||||
int64_t duration;
|
||||
struct Track **tracks;
|
||||
int multiple_tracks_per_file;
|
||||
};
|
||||
|
||||
static void set_codec_str(AVCodecContext *codec, char *str, int size)
|
||||
{
|
||||
switch (codec->codec_id) {
|
||||
case AV_CODEC_ID_H264:
|
||||
snprintf(str, size, "avc1");
|
||||
if (codec->extradata_size >= 4 && codec->extradata[0] == 1) {
|
||||
av_strlcatf(str, size, ".%02x%02x%02x",
|
||||
codec->extradata[1], codec->extradata[2], codec->extradata[3]);
|
||||
}
|
||||
break;
|
||||
case AV_CODEC_ID_AAC:
|
||||
snprintf(str, size, "mp4a.40"); // 0x40 is the mp4 object type for AAC
|
||||
if (codec->extradata_size >= 2) {
|
||||
int aot = codec->extradata[0] >> 3;
|
||||
if (aot == 31)
|
||||
aot = ((AV_RB16(codec->extradata) >> 5) & 0x3f) + 32;
|
||||
av_strlcatf(str, size, ".%d", aot);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int find_sidx(struct Tracks *tracks, int start_index,
|
||||
const char *file)
|
||||
{
|
||||
int err = 0;
|
||||
AVIOContext *f = NULL;
|
||||
int i;
|
||||
|
||||
if ((err = avio_open2(&f, file, AVIO_FLAG_READ, NULL, NULL)) < 0)
|
||||
goto fail;
|
||||
|
||||
while (!f->eof_reached) {
|
||||
int64_t pos = avio_tell(f);
|
||||
int32_t size, tag;
|
||||
|
||||
size = avio_rb32(f);
|
||||
tag = avio_rb32(f);
|
||||
if (size < 8)
|
||||
break;
|
||||
if (tag == MKBETAG('s', 'i', 'd', 'x')) {
|
||||
for (i = start_index; i < tracks->nb_tracks; i++) {
|
||||
struct Track *track = tracks->tracks[i];
|
||||
if (!track->sidx_start) {
|
||||
track->sidx_start = pos;
|
||||
track->sidx_length = size;
|
||||
} else if (pos == track->sidx_start + track->sidx_length) {
|
||||
track->sidx_length = pos + size - track->sidx_start;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (avio_seek(f, pos + size, SEEK_SET) != pos + size)
|
||||
break;
|
||||
}
|
||||
|
||||
fail:
|
||||
if (f)
|
||||
avio_close(f);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int handle_file(struct Tracks *tracks, const char *file)
|
||||
{
|
||||
AVFormatContext *ctx = NULL;
|
||||
int err = 0, i, orig_tracks = tracks->nb_tracks;
|
||||
char errbuf[50], *ptr;
|
||||
struct Track *track;
|
||||
|
||||
err = avformat_open_input(&ctx, file, NULL, NULL);
|
||||
if (err < 0) {
|
||||
av_strerror(err, errbuf, sizeof(errbuf));
|
||||
fprintf(stderr, "Unable to open %s: %s\n", file, errbuf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
err = avformat_find_stream_info(ctx, NULL);
|
||||
if (err < 0) {
|
||||
av_strerror(err, errbuf, sizeof(errbuf));
|
||||
fprintf(stderr, "Unable to identify %s: %s\n", file, errbuf);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (ctx->nb_streams < 1) {
|
||||
fprintf(stderr, "No streams found in %s\n", file);
|
||||
goto fail;
|
||||
}
|
||||
if (ctx->nb_streams > 1)
|
||||
tracks->multiple_tracks_per_file = 1;
|
||||
|
||||
for (i = 0; i < ctx->nb_streams; i++) {
|
||||
struct Track **temp;
|
||||
AVStream *st = ctx->streams[i];
|
||||
|
||||
if (st->codec->bit_rate == 0) {
|
||||
fprintf(stderr, "Skipping track %d in %s as it has zero bitrate\n",
|
||||
st->id, file);
|
||||
continue;
|
||||
}
|
||||
|
||||
track = av_mallocz(sizeof(*track));
|
||||
if (!track) {
|
||||
err = AVERROR(ENOMEM);
|
||||
goto fail;
|
||||
}
|
||||
temp = av_realloc_array(tracks->tracks, tracks->nb_tracks + 1,
|
||||
sizeof(*tracks->tracks));
|
||||
if (!temp) {
|
||||
av_free(track);
|
||||
err = AVERROR(ENOMEM);
|
||||
goto fail;
|
||||
}
|
||||
tracks->tracks = temp;
|
||||
tracks->tracks[tracks->nb_tracks] = track;
|
||||
|
||||
track->name = file;
|
||||
if ((ptr = strrchr(file, '/')))
|
||||
track->name = ptr + 1;
|
||||
|
||||
track->bitrate = st->codec->bit_rate;
|
||||
track->track_id = st->id;
|
||||
track->timescale = st->time_base.den;
|
||||
track->duration = st->duration;
|
||||
track->is_audio = st->codec->codec_type == AVMEDIA_TYPE_AUDIO;
|
||||
track->is_video = st->codec->codec_type == AVMEDIA_TYPE_VIDEO;
|
||||
|
||||
if (!track->is_audio && !track->is_video) {
|
||||
fprintf(stderr,
|
||||
"Track %d in %s is neither video nor audio, skipping\n",
|
||||
track->track_id, file);
|
||||
av_freep(&tracks->tracks[tracks->nb_tracks]);
|
||||
continue;
|
||||
}
|
||||
|
||||
tracks->duration = FFMAX(tracks->duration,
|
||||
av_rescale_rnd(track->duration, AV_TIME_BASE,
|
||||
track->timescale, AV_ROUND_UP));
|
||||
|
||||
if (track->is_audio) {
|
||||
track->channels = st->codec->channels;
|
||||
track->sample_rate = st->codec->sample_rate;
|
||||
}
|
||||
if (track->is_video) {
|
||||
track->width = st->codec->width;
|
||||
track->height = st->codec->height;
|
||||
}
|
||||
set_codec_str(st->codec, track->codec_str, sizeof(track->codec_str));
|
||||
|
||||
tracks->nb_tracks++;
|
||||
}
|
||||
|
||||
avformat_close_input(&ctx);
|
||||
|
||||
err = find_sidx(tracks, orig_tracks, file);
|
||||
|
||||
fail:
|
||||
if (ctx)
|
||||
avformat_close_input(&ctx);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void write_time(FILE *out, int64_t time, int decimals, enum AVRounding round)
|
||||
{
|
||||
int seconds = time / AV_TIME_BASE;
|
||||
int fractions = time % AV_TIME_BASE;
|
||||
int minutes = seconds / 60;
|
||||
int hours = minutes / 60;
|
||||
fractions = av_rescale_rnd(fractions, pow(10, decimals), AV_TIME_BASE, round);
|
||||
seconds %= 60;
|
||||
minutes %= 60;
|
||||
fprintf(out, "PT");
|
||||
if (hours)
|
||||
fprintf(out, "%dH", hours);
|
||||
if (hours || minutes)
|
||||
fprintf(out, "%dM", minutes);
|
||||
fprintf(out, "%d.%0*dS", seconds, decimals, fractions);
|
||||
}
|
||||
|
||||
static int output_mpd(struct Tracks *tracks, const char *filename)
|
||||
{
|
||||
FILE *out;
|
||||
int i, j, ret = 0;
|
||||
struct Track **adaptation_sets_buf[2] = { NULL };
|
||||
struct Track ***adaptation_sets;
|
||||
int nb_tracks_buf[2] = { 0 };
|
||||
int *nb_tracks;
|
||||
int set, nb_sets;
|
||||
|
||||
if (!tracks->multiple_tracks_per_file) {
|
||||
adaptation_sets = adaptation_sets_buf;
|
||||
nb_tracks = nb_tracks_buf;
|
||||
nb_sets = 2;
|
||||
for (i = 0; i < 2; i++) {
|
||||
adaptation_sets[i] = av_malloc_array(tracks->nb_tracks, sizeof(*adaptation_sets[i]));
|
||||
if (!adaptation_sets[i]) {
|
||||
ret = AVERROR(ENOMEM);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < tracks->nb_tracks; i++) {
|
||||
int set_index = -1;
|
||||
if (tracks->tracks[i]->is_video)
|
||||
set_index = 0;
|
||||
else if (tracks->tracks[i]->is_audio)
|
||||
set_index = 1;
|
||||
else
|
||||
continue;
|
||||
adaptation_sets[set_index][nb_tracks[set_index]++] = tracks->tracks[i];
|
||||
}
|
||||
} else {
|
||||
adaptation_sets = &tracks->tracks;
|
||||
nb_tracks = &tracks->nb_tracks;
|
||||
nb_sets = 1;
|
||||
}
|
||||
|
||||
out = fopen(filename, "w");
|
||||
if (!out) {
|
||||
ret = AVERROR(errno);
|
||||
perror(filename);
|
||||
return ret;
|
||||
}
|
||||
fprintf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
|
||||
fprintf(out, "<MPD xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
|
||||
"\txmlns=\"urn:mpeg:dash:schema:mpd:2011\"\n"
|
||||
"\txmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
|
||||
"\txsi:schemaLocation=\"urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd\"\n"
|
||||
"\tprofiles=\"urn:mpeg:dash:profile:isoff-on-demand:2011\"\n"
|
||||
"\ttype=\"static\"\n");
|
||||
fprintf(out, "\tmediaPresentationDuration=\"");
|
||||
write_time(out, tracks->duration, 1, AV_ROUND_DOWN);
|
||||
fprintf(out, "\"\n");
|
||||
fprintf(out, "\tminBufferTime=\"PT5S\">\n");
|
||||
|
||||
fprintf(out, "\t<Period start=\"PT0.0S\">\n");
|
||||
|
||||
for (set = 0; set < nb_sets; set++) {
|
||||
if (nb_tracks[set] == 0)
|
||||
continue;
|
||||
fprintf(out, "\t\t<AdaptationSet segmentAlignment=\"true\">\n");
|
||||
if (nb_sets == 1) {
|
||||
for (i = 0; i < nb_tracks[set]; i++) {
|
||||
struct Track *track = adaptation_sets[set][i];
|
||||
if (strcmp(track->name, adaptation_sets[set][0]->name))
|
||||
break;
|
||||
fprintf(out, "\t\t\t<ContentComponent id=\"%d\" contentType=\"%s\" />\n", track->track_id, track->is_audio ? "audio" : "video");
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < nb_tracks[set]; ) {
|
||||
struct Track *first_track = adaptation_sets[set][i];
|
||||
int width = 0, height = 0, sample_rate = 0, channels = 0, bitrate = 0;
|
||||
fprintf(out, "\t\t\t<Representation id=\"%d\" codecs=\"", i);
|
||||
for (j = i; j < nb_tracks[set]; j++) {
|
||||
struct Track *track = adaptation_sets[set][j];
|
||||
if (strcmp(track->name, first_track->name))
|
||||
break;
|
||||
if (track->is_audio) {
|
||||
sample_rate = track->sample_rate;
|
||||
channels = track->channels;
|
||||
}
|
||||
if (track->is_video) {
|
||||
width = track->width;
|
||||
height = track->height;
|
||||
}
|
||||
bitrate += track->bitrate;
|
||||
if (j > i)
|
||||
fprintf(out, ",");
|
||||
fprintf(out, "%s", track->codec_str);
|
||||
}
|
||||
fprintf(out, "\" mimeType=\"%s/mp4\" bandwidth=\"%d\"",
|
||||
width ? "video" : "audio", bitrate);
|
||||
if (width > 0 && height > 0)
|
||||
fprintf(out, " width=\"%d\" height=\"%d\"", width, height);
|
||||
if (sample_rate > 0)
|
||||
fprintf(out, " audioSamplingRate=\"%d\"", sample_rate);
|
||||
fprintf(out, ">\n");
|
||||
if (channels > 0)
|
||||
fprintf(out, "\t\t\t\t<AudioChannelConfiguration schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"%d\" />\n", channels);
|
||||
fprintf(out, "\t\t\t\t<BaseURL>%s</BaseURL>\n", first_track->name);
|
||||
fprintf(out, "\t\t\t\t<SegmentBase indexRange=\"%"PRId64"-%"PRId64"\" />\n", first_track->sidx_start, first_track->sidx_start + first_track->sidx_length - 1);
|
||||
fprintf(out, "\t\t\t</Representation>\n");
|
||||
i = j;
|
||||
}
|
||||
fprintf(out, "\t\t</AdaptationSet>\n");
|
||||
}
|
||||
fprintf(out, "\t</Period>\n");
|
||||
fprintf(out, "</MPD>\n");
|
||||
|
||||
fclose(out);
|
||||
err:
|
||||
for (i = 0; i < 2; i++)
|
||||
av_free(adaptation_sets_buf[i]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void clean_tracks(struct Tracks *tracks)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < tracks->nb_tracks; i++) {
|
||||
av_freep(&tracks->tracks[i]);
|
||||
}
|
||||
av_freep(&tracks->tracks);
|
||||
tracks->nb_tracks = 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *out = NULL;
|
||||
struct Tracks tracks = { 0 };
|
||||
int i;
|
||||
|
||||
av_register_all();
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (!strcmp(argv[i], "-out")) {
|
||||
out = argv[i + 1];
|
||||
i++;
|
||||
} else if (argv[i][0] == '-') {
|
||||
return usage(argv[0], 1);
|
||||
} else {
|
||||
if (handle_file(&tracks, argv[i]))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (!tracks.nb_tracks || !out)
|
||||
return usage(argv[0], 1);
|
||||
|
||||
output_mpd(&tracks, out);
|
||||
|
||||
clean_tracks(&tracks);
|
||||
|
||||
return 0;
|
||||
}
|
87
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/trasher.c
Normal file
87
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/trasher.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2007 Michael Niedermayer
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
static uint32_t state;
|
||||
static uint32_t ran(void)
|
||||
{
|
||||
return state = state * 1664525 + 1013904223;
|
||||
}
|
||||
|
||||
static void checked_seek(FILE *stream, int64_t offset, int whence)
|
||||
{
|
||||
offset = fseek(stream, offset, whence);
|
||||
if (offset < 0) {
|
||||
fprintf(stderr, "seek failed\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *f;
|
||||
int count, maxburst, length;
|
||||
|
||||
if (argc < 5) {
|
||||
printf("USAGE: trasher <filename> <count> <maxburst> <seed>\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
f = fopen(argv[1], "rb+");
|
||||
if (!f) {
|
||||
perror(argv[1]);
|
||||
return 2;
|
||||
}
|
||||
count = atoi(argv[2]);
|
||||
maxburst = atoi(argv[3]);
|
||||
state = atoi(argv[4]);
|
||||
|
||||
checked_seek(f, 0, SEEK_END);
|
||||
length = ftell(f);
|
||||
checked_seek(f, 0, SEEK_SET);
|
||||
|
||||
while (count--) {
|
||||
int burst = 1 + ran() * (uint64_t) (abs(maxburst) - 1) / UINT32_MAX;
|
||||
int pos = ran() * (uint64_t) length / UINT32_MAX;
|
||||
checked_seek(f, pos, SEEK_SET);
|
||||
|
||||
if (maxburst < 0)
|
||||
burst = -maxburst;
|
||||
|
||||
if (pos + burst > length)
|
||||
continue;
|
||||
|
||||
while (burst--) {
|
||||
int val = ran() * 256ULL / UINT32_MAX;
|
||||
|
||||
if (maxburst < 0)
|
||||
val = 0;
|
||||
|
||||
fwrite(&val, 1, 1, f);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
279
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/uncoded_frame.c
Normal file
279
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/uncoded_frame.c
Normal file
@@ -0,0 +1,279 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "libavutil/avassert.h"
|
||||
#include "libavdevice/avdevice.h"
|
||||
#include "libavfilter/avfilter.h"
|
||||
#include "libavfilter/buffersink.h"
|
||||
#include "libavformat/avformat.h"
|
||||
|
||||
typedef struct {
|
||||
AVFormatContext *mux;
|
||||
AVStream *stream;
|
||||
AVFilterContext *sink;
|
||||
AVFilterLink *link;
|
||||
} Stream;
|
||||
|
||||
static int create_sink(Stream *st, AVFilterGraph *graph,
|
||||
AVFilterContext *f, int idx)
|
||||
{
|
||||
enum AVMediaType type = avfilter_pad_get_type(f->output_pads, idx);
|
||||
const char *sink_name;
|
||||
int ret;
|
||||
|
||||
switch (type) {
|
||||
case AVMEDIA_TYPE_VIDEO: sink_name = "buffersink"; break;
|
||||
case AVMEDIA_TYPE_AUDIO: sink_name = "abuffersink"; break;
|
||||
default:
|
||||
av_log(NULL, AV_LOG_ERROR, "Stream type not supported\n");
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
ret = avfilter_graph_create_filter(&st->sink,
|
||||
avfilter_get_by_name(sink_name),
|
||||
NULL, NULL, NULL, graph);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
ret = avfilter_link(f, idx, st->sink, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
st->link = st->sink->inputs[0];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *in_graph_desc, **out_dev_name;
|
||||
int nb_out_dev = 0, nb_streams = 0;
|
||||
AVFilterGraph *in_graph = NULL;
|
||||
Stream *streams = NULL, *st;
|
||||
AVFrame *frame = NULL;
|
||||
int i, j, run = 1, ret;
|
||||
|
||||
//av_log_set_level(AV_LOG_DEBUG);
|
||||
|
||||
if (argc < 3) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Usage: %s filter_graph dev:out [dev2:out2...]\n\n"
|
||||
"Examples:\n"
|
||||
"%s movie=file.nut:s=v+a xv:- alsa:default\n"
|
||||
"%s movie=file.nut:s=v+a uncodedframecrc:pipe:0\n",
|
||||
argv[0], argv[0], argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
in_graph_desc = argv[1];
|
||||
out_dev_name = argv + 2;
|
||||
nb_out_dev = argc - 2;
|
||||
|
||||
av_register_all();
|
||||
avdevice_register_all();
|
||||
avfilter_register_all();
|
||||
|
||||
/* Create input graph */
|
||||
if (!(in_graph = avfilter_graph_alloc())) {
|
||||
ret = AVERROR(ENOMEM);
|
||||
av_log(NULL, AV_LOG_ERROR, "Unable to alloc graph graph: %s\n",
|
||||
av_err2str(ret));
|
||||
goto fail;
|
||||
}
|
||||
ret = avfilter_graph_parse_ptr(in_graph, in_graph_desc, NULL, NULL, NULL);
|
||||
if (ret < 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Unable to parse graph: %s\n",
|
||||
av_err2str(ret));
|
||||
goto fail;
|
||||
}
|
||||
nb_streams = 0;
|
||||
for (i = 0; i < in_graph->nb_filters; i++) {
|
||||
AVFilterContext *f = in_graph->filters[i];
|
||||
for (j = 0; j < f->nb_inputs; j++) {
|
||||
if (!f->inputs[j]) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Graph has unconnected inputs\n");
|
||||
ret = AVERROR(EINVAL);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
for (j = 0; j < f->nb_outputs; j++)
|
||||
if (!f->outputs[j])
|
||||
nb_streams++;
|
||||
}
|
||||
if (!nb_streams) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Graph has no output stream\n");
|
||||
ret = AVERROR(EINVAL);
|
||||
goto fail;
|
||||
}
|
||||
if (nb_out_dev != 1 && nb_out_dev != nb_streams) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Graph has %d output streams, %d devices given\n",
|
||||
nb_streams, nb_out_dev);
|
||||
ret = AVERROR(EINVAL);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!(streams = av_calloc(nb_streams, sizeof(*streams)))) {
|
||||
ret = AVERROR(ENOMEM);
|
||||
av_log(NULL, AV_LOG_ERROR, "Could not allocate streams\n");
|
||||
}
|
||||
st = streams;
|
||||
for (i = 0; i < in_graph->nb_filters; i++) {
|
||||
AVFilterContext *f = in_graph->filters[i];
|
||||
for (j = 0; j < f->nb_outputs; j++) {
|
||||
if (!f->outputs[j]) {
|
||||
if ((ret = create_sink(st++, in_graph, f, j)) < 0)
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
av_assert0(st - streams == nb_streams);
|
||||
if ((ret = avfilter_graph_config(in_graph, NULL)) < 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Failed to configure graph\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Create output devices */
|
||||
for (i = 0; i < nb_out_dev; i++) {
|
||||
char *fmt = NULL, *dev = out_dev_name[i];
|
||||
st = &streams[i];
|
||||
if ((dev = strchr(dev, ':'))) {
|
||||
*(dev++) = 0;
|
||||
fmt = out_dev_name[i];
|
||||
}
|
||||
ret = avformat_alloc_output_context2(&st->mux, NULL, fmt, dev);
|
||||
if (ret < 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Failed to allocate output: %s\n",
|
||||
av_err2str(ret));
|
||||
goto fail;
|
||||
}
|
||||
if (!(st->mux->oformat->flags & AVFMT_NOFILE)) {
|
||||
ret = avio_open2(&st->mux->pb, st->mux->filename, AVIO_FLAG_WRITE,
|
||||
NULL, NULL);
|
||||
if (ret < 0) {
|
||||
av_log(st->mux, AV_LOG_ERROR, "Failed to init output: %s\n",
|
||||
av_err2str(ret));
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (; i < nb_streams; i++)
|
||||
streams[i].mux = streams[0].mux;
|
||||
|
||||
/* Create output device streams */
|
||||
for (i = 0; i < nb_streams; i++) {
|
||||
st = &streams[i];
|
||||
if (!(st->stream = avformat_new_stream(st->mux, NULL))) {
|
||||
ret = AVERROR(ENOMEM);
|
||||
av_log(NULL, AV_LOG_ERROR, "Failed to create output stream\n");
|
||||
goto fail;
|
||||
}
|
||||
st->stream->codec->codec_type = st->link->type;
|
||||
st->stream->time_base = st->stream->codec->time_base =
|
||||
st->link->time_base;
|
||||
switch (st->link->type) {
|
||||
case AVMEDIA_TYPE_VIDEO:
|
||||
st->stream->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
|
||||
st->stream->avg_frame_rate =
|
||||
st->stream-> r_frame_rate = av_buffersink_get_frame_rate(st->sink);
|
||||
st->stream->codec->width = st->link->w;
|
||||
st->stream->codec->height = st->link->h;
|
||||
st->stream->codec->sample_aspect_ratio = st->link->sample_aspect_ratio;
|
||||
st->stream->codec->pix_fmt = st->link->format;
|
||||
break;
|
||||
case AVMEDIA_TYPE_AUDIO:
|
||||
st->stream->codec->channel_layout = st->link->channel_layout;
|
||||
st->stream->codec->channels = avfilter_link_get_channels(st->link);
|
||||
st->stream->codec->sample_rate = st->link->sample_rate;
|
||||
st->stream->codec->sample_fmt = st->link->format;
|
||||
st->stream->codec->codec_id =
|
||||
av_get_pcm_codec(st->stream->codec->sample_fmt, -1);
|
||||
break;
|
||||
default:
|
||||
av_assert0(!"reached");
|
||||
}
|
||||
}
|
||||
|
||||
/* Init output devices */
|
||||
for (i = 0; i < nb_out_dev; i++) {
|
||||
st = &streams[i];
|
||||
if ((ret = avformat_write_header(st->mux, NULL)) < 0) {
|
||||
av_log(st->mux, AV_LOG_ERROR, "Failed to init output: %s\n",
|
||||
av_err2str(ret));
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check output devices */
|
||||
for (i = 0; i < nb_streams; i++) {
|
||||
st = &streams[i];
|
||||
ret = av_write_uncoded_frame_query(st->mux, st->stream->index);
|
||||
if (ret < 0) {
|
||||
av_log(st->mux, AV_LOG_ERROR,
|
||||
"Uncoded frames not supported on stream #%d: %s\n",
|
||||
i, av_err2str(ret));
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
while (run) {
|
||||
ret = avfilter_graph_request_oldest(in_graph);
|
||||
if (ret < 0) {
|
||||
if (ret == AVERROR_EOF) {
|
||||
run = 0;
|
||||
} else {
|
||||
av_log(NULL, AV_LOG_ERROR, "Error filtering: %s\n",
|
||||
av_err2str(ret));
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < nb_streams; i++) {
|
||||
st = &streams[i];
|
||||
while (1) {
|
||||
if (!frame && !(frame = av_frame_alloc())) {
|
||||
ret = AVERROR(ENOMEM);
|
||||
av_log(NULL, AV_LOG_ERROR, "Could not allocate frame\n");
|
||||
goto fail;
|
||||
}
|
||||
ret = av_buffersink_get_frame_flags(st->sink, frame,
|
||||
AV_BUFFERSINK_FLAG_NO_REQUEST);
|
||||
if (ret < 0) {
|
||||
if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
|
||||
av_log(NULL, AV_LOG_WARNING, "Error in sink: %s\n",
|
||||
av_err2str(ret));
|
||||
break;
|
||||
}
|
||||
if (frame->pts != AV_NOPTS_VALUE)
|
||||
frame->pts = av_rescale_q(frame->pts,
|
||||
st->link ->time_base,
|
||||
st->stream->time_base);
|
||||
ret = av_interleaved_write_uncoded_frame(st->mux,
|
||||
st->stream->index,
|
||||
frame);
|
||||
frame = NULL;
|
||||
if (ret < 0) {
|
||||
av_log(st->stream->codec, AV_LOG_ERROR,
|
||||
"Error writing frame: %s\n", av_err2str(ret));
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
for (i = 0; i < nb_out_dev; i++) {
|
||||
st = &streams[i];
|
||||
av_write_trailer(st->mux);
|
||||
}
|
||||
|
||||
fail:
|
||||
av_frame_free(&frame);
|
||||
avfilter_graph_free(&in_graph);
|
||||
if (streams) {
|
||||
for (i = 0; i < nb_out_dev; i++) {
|
||||
st = &streams[i];
|
||||
if (st->mux) {
|
||||
if (st->mux->pb)
|
||||
avio_closep(&st->mux->pb);
|
||||
avformat_free_context(st->mux);
|
||||
}
|
||||
}
|
||||
}
|
||||
av_freep(&streams);
|
||||
return ret < 0;
|
||||
}
|
2
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/unwrap-diff
Normal file
2
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/unwrap-diff
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
tr '\n' '\001' | sed 's/\x01\x01/\x01 \x01/g' | sed 's/\x01\([^-+ @]\)/ \1/g' | tr '\001' '\n'
|
184
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/yuvcmp.c
Normal file
184
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/yuvcmp.c
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* originally by Andreas Öman (andoma)
|
||||
* some changes by Alexander Strange
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int fd[2];
|
||||
int print_pixels = 0;
|
||||
int dump_blocks = 0;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
int to_skip = 0;
|
||||
|
||||
if (argc < 6) {
|
||||
fprintf(stderr, "%s [YUV file 1] [YUV file 2] width height pixelcmp|blockdump (# to skip)\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
width = atoi(argv[3]);
|
||||
height = atoi(argv[4]);
|
||||
if (argc > 6)
|
||||
to_skip = atoi(argv[6]);
|
||||
|
||||
uint8_t *Y[2], *C[2][2];
|
||||
int i, v, c, p;
|
||||
int lsiz = width * height;
|
||||
int csiz = width * height / 4;
|
||||
int x, y;
|
||||
int cwidth = width / 2;
|
||||
int fr = to_skip;
|
||||
int mb;
|
||||
char *mberrors;
|
||||
int mb_x, mb_y;
|
||||
uint8_t *a;
|
||||
uint8_t *b;
|
||||
int die = 0;
|
||||
|
||||
print_pixels = strstr(argv[5], "pixelcmp") ? 1 : 0;
|
||||
dump_blocks = strstr(argv[5], "blockdump") ? 1 : 0;
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
Y[i] = malloc(lsiz);
|
||||
C[0][i] = malloc(csiz);
|
||||
C[1][i] = malloc(csiz);
|
||||
|
||||
fd[i] = open(argv[1 + i], O_RDONLY);
|
||||
if(fd[i] == -1) {
|
||||
perror("open");
|
||||
exit(1);
|
||||
}
|
||||
fcntl(fd[i], F_NOCACHE, 1);
|
||||
|
||||
if (to_skip)
|
||||
lseek(fd[i], to_skip * (lsiz + 2*csiz), SEEK_SET);
|
||||
}
|
||||
|
||||
mb_x = width / 16;
|
||||
mb_y = height / 16;
|
||||
|
||||
mberrors = malloc(mb_x * mb_y);
|
||||
|
||||
while(!die) {
|
||||
memset(mberrors, 0, mb_x * mb_y);
|
||||
|
||||
printf("Loading frame %d\n", ++fr);
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
v = read(fd[i], Y[i], lsiz);
|
||||
if(v != lsiz) {
|
||||
fprintf(stderr, "Unable to read Y from file %d, exiting\n", i + 1);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(c = 0; c < lsiz; c++) {
|
||||
if(Y[0][c] != Y[1][c]) {
|
||||
x = c % width;
|
||||
y = c / width;
|
||||
|
||||
mb = x / 16 + (y / 16) * mb_x;
|
||||
|
||||
if(print_pixels)
|
||||
printf("Luma diff 0x%02x != 0x%02x at pixel (%4d,%-4d) mb(%d,%d) #%d\n",
|
||||
Y[0][c],
|
||||
Y[1][c],
|
||||
x, y,
|
||||
x / 16,
|
||||
y / 16,
|
||||
mb);
|
||||
|
||||
mberrors[mb] |= 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Chroma planes */
|
||||
|
||||
for(p = 0; p < 2; p++) {
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
v = read(fd[i], C[p][i], csiz);
|
||||
if(v != csiz) {
|
||||
fprintf(stderr, "Unable to read %c from file %d, exiting\n",
|
||||
"UV"[p], i + 1);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
for(c = 0; c < csiz; c++) {
|
||||
if(C[p][0][c] != C[p][1][c]) {
|
||||
x = c % cwidth;
|
||||
y = c / cwidth;
|
||||
|
||||
mb = x / 8 + (y / 8) * mb_x;
|
||||
|
||||
mberrors[mb] |= 2 << p;
|
||||
|
||||
if(print_pixels)
|
||||
|
||||
printf("c%c diff 0x%02x != 0x%02x at pixel (%4d,%-4d) "
|
||||
"mb(%3d,%-3d) #%d\n",
|
||||
p ? 'r' : 'b',
|
||||
C[p][0][c],
|
||||
C[p][1][c],
|
||||
|
||||
x, y,
|
||||
x / 8,
|
||||
y / 8,
|
||||
x / 8 + y / 8 * cwidth / 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < mb_x * mb_y; i++) {
|
||||
x = i % mb_x;
|
||||
y = i / mb_x;
|
||||
|
||||
if(mberrors[i]) {
|
||||
die = 1;
|
||||
|
||||
printf("MB (%3d,%-3d) %4d %d %c%c%c damaged\n",
|
||||
x, y, i, mberrors[i],
|
||||
mberrors[i] & 1 ? 'Y' : ' ',
|
||||
mberrors[i] & 2 ? 'U' : ' ',
|
||||
mberrors[i] & 4 ? 'V' : ' ');
|
||||
|
||||
if(dump_blocks) {
|
||||
a = Y[0] + x * 16 + y * 16 * width;
|
||||
b = Y[1] + x * 16 + y * 16 * width;
|
||||
|
||||
for(y = 0; y < 16; y++) {
|
||||
printf("%c ", "TB"[y&1]);
|
||||
for(x = 0; x < 16; x++)
|
||||
printf("%02x%c", a[x + y * width],
|
||||
a[x + y * width] != b[x + y * width] ? '<' : ' ');
|
||||
|
||||
printf("| ");
|
||||
for(x = 0; x < 16; x++)
|
||||
printf("%02x%c", b[x + y * width],
|
||||
a[x + y * width] != b[x + y * width] ? '<' : ' ');
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
167
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/zmqsend.c
Normal file
167
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/zmqsend.c
Normal file
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Stefano Sabatini
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <zmq.h>
|
||||
|
||||
#include "libavutil/mem.h"
|
||||
#include "libavutil/bprint.h"
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h> /* getopt */
|
||||
#endif
|
||||
|
||||
#if !HAVE_GETOPT
|
||||
#include "compat/getopt.c"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file
|
||||
* zmq message sender example, meant to be used with the zmq filters
|
||||
*/
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("send message to ZMQ recipient, to use with the zmq filters\n");
|
||||
printf("usage: zmqsend [OPTIONS]\n");
|
||||
printf("\n"
|
||||
"Options:\n"
|
||||
"-b ADDRESS set bind address\n"
|
||||
"-h print this help\n"
|
||||
"-i INFILE set INFILE as input file, stdin if omitted\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
AVBPrint src;
|
||||
char c, *src_buf, *recv_buf;
|
||||
int recv_buf_size, ret;
|
||||
void *zmq_ctx, *socket;
|
||||
const char *bind_address = "tcp://localhost:5555";
|
||||
const char *infilename = NULL;
|
||||
FILE *infile = NULL;
|
||||
zmq_msg_t msg;
|
||||
|
||||
while ((c = getopt(argc, argv, "b:hi:")) != -1) {
|
||||
switch (c) {
|
||||
case 'b':
|
||||
bind_address = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
return 0;
|
||||
case 'i':
|
||||
infilename = optarg;
|
||||
break;
|
||||
case '?':
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!infilename || !strcmp(infilename, "-")) {
|
||||
infilename = "stdin";
|
||||
infile = stdin;
|
||||
} else {
|
||||
infile = fopen(infilename, "r");
|
||||
}
|
||||
if (!infile) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Impossible to open input file '%s': %s\n", infilename, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
zmq_ctx = zmq_ctx_new();
|
||||
if (!zmq_ctx) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Could not create ZMQ context: %s\n", zmq_strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
socket = zmq_socket(zmq_ctx, ZMQ_REQ);
|
||||
if (!socket) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Could not create ZMQ socket: %s\n", zmq_strerror(errno));
|
||||
ret = 1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (zmq_connect(socket, bind_address) == -1) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Could not bind ZMQ responder to address '%s': %s\n",
|
||||
bind_address, zmq_strerror(errno));
|
||||
ret = 1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* grab the input and store it in src */
|
||||
av_bprint_init(&src, 1, AV_BPRINT_SIZE_UNLIMITED);
|
||||
while ((c = fgetc(infile)) != EOF)
|
||||
av_bprint_chars(&src, c, 1);
|
||||
av_bprint_chars(&src, 0, 1);
|
||||
|
||||
if (!av_bprint_is_complete(&src)) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Could not allocate a buffer for the source string\n");
|
||||
av_bprint_finalize(&src, NULL);
|
||||
ret = 1;
|
||||
goto end;
|
||||
}
|
||||
av_bprint_finalize(&src, &src_buf);
|
||||
|
||||
if (zmq_send(socket, src_buf, strlen(src_buf), 0) == -1) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Could not send message: %s\n", zmq_strerror(errno));
|
||||
ret = 1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (zmq_msg_init(&msg) == -1) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Could not initialize receiving message: %s\n", zmq_strerror(errno));
|
||||
ret = 1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (zmq_msg_recv(&msg, socket, 0) == -1) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Could not receive message: %s\n", zmq_strerror(errno));
|
||||
zmq_msg_close(&msg);
|
||||
ret = 1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
recv_buf_size = zmq_msg_size(&msg) + 1;
|
||||
recv_buf = av_malloc(recv_buf_size);
|
||||
if (!recv_buf) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Could not allocate receiving message buffer\n");
|
||||
zmq_msg_close(&msg);
|
||||
ret = 1;
|
||||
goto end;
|
||||
}
|
||||
memcpy(recv_buf, zmq_msg_data(&msg), recv_buf_size);
|
||||
recv_buf[recv_buf_size-1] = 0;
|
||||
printf("%s\n", recv_buf);
|
||||
zmq_msg_close(&msg);
|
||||
av_free(recv_buf);
|
||||
|
||||
end:
|
||||
zmq_close(socket);
|
||||
zmq_ctx_destroy(zmq_ctx);
|
||||
return ret;
|
||||
}
|
26
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/zmqshell.py
Normal file
26
contrib/sdk/sources/ffmpeg/ffmpeg-2.8/tools/zmqshell.py
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python2
|
||||
|
||||
import sys, zmq, cmd
|
||||
|
||||
class LavfiCmd(cmd.Cmd):
|
||||
prompt = 'lavfi> '
|
||||
|
||||
def __init__(self, bind_address):
|
||||
context = zmq.Context()
|
||||
self.requester = context.socket(zmq.REQ)
|
||||
self.requester.connect(bind_address)
|
||||
cmd.Cmd.__init__(self)
|
||||
|
||||
def onecmd(self, cmd):
|
||||
if cmd == 'EOF':
|
||||
sys.exit(0)
|
||||
print 'Sending command:[%s]' % cmd
|
||||
self.requester.send(cmd)
|
||||
message = self.requester.recv()
|
||||
print 'Received reply:[%s]' % message
|
||||
|
||||
try:
|
||||
bind_address = sys.argv[1] if len(sys.argv) > 1 else "tcp://localhost:5555"
|
||||
LavfiCmd(bind_address).cmdloop('FFmpeg libavfilter interactive shell')
|
||||
except KeyboardInterrupt:
|
||||
pass
|
Reference in New Issue
Block a user