QTfrontend/util/libav_iteraction.cpp
author Stepan777 <stepik-777@mail.ru>
Sat, 07 Jul 2012 17:43:10 +0400
changeset 7361 b73d7688dadc
parent 7353 0e55228e1303
child 7376 48b79b3ca592
permissions -rw-r--r--
fix frontend for ffmpeg 0.7.13
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     1
/*
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     4
 *
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     8
 *
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    12
 * GNU General Public License for more details.
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    13
 *
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    17
 */
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    18
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    19
#define __STDC_CONSTANT_MACROS
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    20
extern "C"
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    21
{
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    22
#include "libavformat/avformat.h"
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    23
}
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    24
#include <QVector>
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    25
#include <QList>
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    26
#include <QMessageBox>
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    27
#include <QComboBox>
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    28
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    29
#include "libav_iteraction.h"
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    30
#include "HWApplication.h"
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    31
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    32
struct Codec
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    33
{
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    34
    CodecID id;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    35
    bool isAudio;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    36
    QString shortName; // used for identification
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    37
    QString longName; // used for displaying to user
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    38
    bool isRecomended;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    39
};
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    40
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    41
struct Format
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    42
{
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    43
    QString shortName;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    44
    QString longName;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    45
    bool isRecomended;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    46
    QString extension;
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    47
    QVector<Codec*> codecs;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    48
};
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    49
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    50
QList<Codec> codecs;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    51
QMap<QString,Format> formats;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    52
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    53
LibavIteraction & LibavIteraction::instance()
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    54
{
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    55
    static LibavIteraction instance;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    56
    return instance;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    57
}
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    58
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    59
// test if given format supports given codec
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    60
bool FormatQueryCodec(AVOutputFormat *ofmt, enum CodecID codec_id)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    61
{  
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    62
#if LIBAVFORMAT_VERSION_MAJOR >= 54
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    63
    return avformat_query_codec(ofmt, codec_id, FF_COMPLIANCE_NORMAL) == 1;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    64
#else
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    65
    if (ofmt->codec_tag)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    66
        return !!av_codec_get_tag(ofmt->codec_tag, codec_id);
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    67
    return codec_id == ofmt->video_codec || codec_id == ofmt->audio_codec;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    68
#endif
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    69
}
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    70
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    71
LibavIteraction::LibavIteraction()
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    72
{
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    73
    // initialize libav and register all codecs and formats
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    74
    av_register_all();
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    75
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    76
    // get list of all codecs
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    77
    AVCodec* pCodec = NULL;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    78
    while (pCodec = av_codec_next(pCodec))
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    79
    {
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    80
#if LIBAVCODEC_VERSION_MAJOR >= 54
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    81
        if (!av_codec_is_encoder(pCodec))
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    82
#else
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    83
        if (!pCodec->encode)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    84
#endif
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    85
            continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    86
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    87
        if (pCodec->capabilities & CODEC_CAP_EXPERIMENTAL)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    88
            continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    89
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    90
        if (pCodec->type != AVMEDIA_TYPE_VIDEO && pCodec->type != AVMEDIA_TYPE_AUDIO)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    91
            continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    92
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    93
        // this encoders seems to be buggy
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
    94
        if (strcmp(pCodec->name, "rv10") == 0 || strcmp(pCodec->name, "rv20") == 0)
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    95
            continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    96
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    97
        // doesn't support stereo sound
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    98
        if (strcmp(pCodec->name, "real_144") == 0)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    99
            continue;
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   100
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   101
#if LIBAVCODEC_VERSION_MAJOR < 54
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   102
        // FIXME: theese doesn't work for some reason
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   103
        if (strcmp(pCodec->name, "libx264") == 0)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   104
            continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   105
        if (strcmp(pCodec->name, "libxvid") == 0)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   106
            continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   107
#endif
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   108
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   109
        if (pCodec->type == AVMEDIA_TYPE_VIDEO)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   110
        {
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   111
            if (pCodec->supported_framerates != NULL)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   112
                continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   113
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   114
            // check if codec supports yuv 4:2:0 format
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   115
            if (!pCodec->pix_fmts)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   116
                continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   117
            bool yuv420Supported = false;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   118
            for (const PixelFormat* pfmt = pCodec->pix_fmts; *pfmt != -1; pfmt++)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   119
                if (*pfmt == PIX_FMT_YUV420P)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   120
                {
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   121
                    yuv420Supported = true;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   122
                    break;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   123
                }
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   124
            if (!yuv420Supported)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   125
                continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   126
        }
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   127
        if (pCodec->type == AVMEDIA_TYPE_AUDIO)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   128
        {
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   129
            // check if codec supports signed 16-bit format
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   130
            if (!pCodec->sample_fmts)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   131
                continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   132
            bool s16Supported = false;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   133
            for (const AVSampleFormat* pfmt = pCodec->sample_fmts; *pfmt != -1; pfmt++)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   134
                if (*pfmt == AV_SAMPLE_FMT_S16/* || *pfmt == AV_SAMPLE_FMT_FLT*/)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   135
                {
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   136
                    s16Supported = true;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   137
                    break;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   138
                }
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   139
            if (!s16Supported)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   140
                continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   141
        }
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   142
        // add codec to list of codecs
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   143
        codecs.push_back(Codec());
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   144
        Codec & codec = codecs.back();
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   145
        codec.id = pCodec->id;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   146
        codec.isAudio = pCodec->type == AVMEDIA_TYPE_AUDIO;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   147
        codec.shortName = pCodec->name;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   148
        codec.longName = pCodec->long_name;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   149
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   150
        codec.isRecomended = false;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   151
        if (strcmp(pCodec->name, "libx264") == 0)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   152
        {
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   153
            codec.longName = "H.264/MPEG-4 Part 10 AVC (x264)";
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   154
            codec.isRecomended = true;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   155
        }
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   156
        else if (strcmp(pCodec->name, "libxvid") == 0)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   157
        {
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   158
            codec.longName = "MPEG-4 Part 2 (Xvid)";
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   159
            codec.isRecomended = true;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   160
        }
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   161
        else if (strcmp(pCodec->name, "libmp3lame") == 0)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   162
        {
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   163
            codec.longName = "MP3 (MPEG audio layer 3) (LAME)";
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   164
            codec.isRecomended = true;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   165
        }
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   166
        else
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   167
            codec.longName = pCodec->long_name;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   168
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   169
        if (strcmp(pCodec->name, "mpeg4") == 0 || strcmp(pCodec->name, "ac3_fixed") == 0)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   170
            codec.isRecomended = true;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   171
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   172
        // FIXME: remove next line
7353
0e55228e1303 When there are videos that are being encoded and user tries to quit display dialog with warning.
Stepan777 <stepik-777@mail.ru>
parents: 7280
diff changeset
   173
       // codec.longName += QString(" (%1)").arg(codec.shortName);
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   174
    }
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   175
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   176
    // get list of all formats
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   177
    AVOutputFormat* pFormat = NULL;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   178
    while (pFormat = av_oformat_next(pFormat))
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   179
    {
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   180
        if (!pFormat->extensions)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   181
            continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   182
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   183
        // skip some strange formats to not confuse users
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   184
        if (strstr(pFormat->long_name, "raw"))
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   185
            continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   186
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   187
        Format format;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   188
        bool hasVideoCodec = false;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   189
        for (QList<Codec>::iterator codec = codecs.begin(); codec != codecs.end(); ++codec)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   190
        {
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   191
            if (!FormatQueryCodec(pFormat, codec->id))
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   192
                continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   193
            format.codecs.push_back(&*codec);
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   194
            if (!codec->isAudio)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   195
                hasVideoCodec = true;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   196
        }
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   197
        if (!hasVideoCodec)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   198
            continue;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   199
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   200
        QString ext(pFormat->extensions);
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   201
        ext.truncate(strcspn(pFormat->extensions, ","));
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   202
        format.extension = ext;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   203
        format.shortName = pFormat->name;
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   204
        format.longName = QString("%1 (*.%2)").arg(pFormat->long_name).arg(ext);
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   205
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   206
        // FIXME: remove next line
7353
0e55228e1303 When there are videos that are being encoded and user tries to quit display dialog with warning.
Stepan777 <stepik-777@mail.ru>
parents: 7280
diff changeset
   207
       // format.longName += QString(" (%1)").arg(format.shortName);
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   208
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   209
        format.isRecomended = strcmp(pFormat->name, "mp4") == 0 || strcmp(pFormat->name, "avi") == 0;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   210
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   211
        formats[pFormat->name] = format;
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   212
    }
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   213
}
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   214
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   215
void LibavIteraction::fillFormats(QComboBox * pFormats)
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   216
{
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   217
    // first insert recomended formats
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   218
    foreach(const Format & format, formats)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   219
        if (format.isRecomended)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   220
            pFormats->addItem(format.longName, format.shortName);
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   221
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   222
    // remember where to place separator between recomended and other formats
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   223
    int sep = pFormats->count();
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   224
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   225
    // insert remaining formats
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   226
    foreach(const Format & format, formats)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   227
        if (!format.isRecomended)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   228
            pFormats->addItem(format.longName, format.shortName);
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   229
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   230
    // insert separator if necessary
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   231
    if (sep != 0 && sep != pFormats->count())
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   232
        pFormats->insertSeparator(sep);
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   233
}
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   234
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   235
void LibavIteraction::fillCodecs(const QString & fmt, QComboBox * pVCodecs, QComboBox * pACodecs)
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   236
{
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   237
    Format & format = formats[fmt];
7235
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   238
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   239
    // first insert recomended codecs
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   240
    foreach(Codec * codec, format.codecs)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   241
    {
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   242
        if (codec->isRecomended)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   243
        {
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   244
            if (codec->isAudio)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   245
                pACodecs->addItem(codec->longName, codec->shortName);
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   246
            else
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   247
                pVCodecs->addItem(codec->longName, codec->shortName);
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   248
        }
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   249
    }
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   250
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   251
    // remember where to place separators between recomended and other codecs
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   252
    int vsep = pVCodecs->count();
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   253
    int asep = pACodecs->count();
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   254
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   255
    // insert remaining codecs
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   256
    foreach(Codec * codec, format.codecs)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   257
    {
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   258
        if (!codec->isRecomended)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   259
        {
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   260
            if (codec->isAudio)
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   261
                pACodecs->addItem(codec->longName, codec->shortName);
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   262
            else
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   263
                pVCodecs->addItem(codec->longName, codec->shortName);
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   264
        }
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   265
    }
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   266
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   267
    // insert separators if necessary
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   268
    if (vsep != 0 && vsep != pVCodecs->count())
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   269
        pVCodecs->insertSeparator(vsep);
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   270
    if (asep != 0 && asep != pACodecs->count())
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   271
        pACodecs->insertSeparator(asep);
baa69bd025d9 1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   272
}
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   273
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   274
QString LibavIteraction::getExtension(const QString & format)
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   275
{
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   276
    return formats[format].extension;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   277
}
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   278
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   279
QString tr(QString a)
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   280
{
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   281
    return a;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   282
}
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   283
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   284
// get information abaout file (duration, resolution etc) in multiline string
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   285
QString LibavIteraction::getFileInfo(const QString & filepath)
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   286
{
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   287
    AVFormatContext* pContext = NULL;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   288
    QByteArray utf8path = filepath.toUtf8();
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   289
    if (avformat_open_input(&pContext, utf8path.data(), NULL, NULL) < 0)
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   290
        return "";
7361
b73d7688dadc fix frontend for ffmpeg 0.7.13
Stepan777 <stepik-777@mail.ru>
parents: 7353
diff changeset
   291
#if LIBAFORMAT_VERSION_MAJOR < 54
b73d7688dadc fix frontend for ffmpeg 0.7.13
Stepan777 <stepik-777@mail.ru>
parents: 7353
diff changeset
   292
    if (av_find_stream_info(pContext) < 0)
b73d7688dadc fix frontend for ffmpeg 0.7.13
Stepan777 <stepik-777@mail.ru>
parents: 7353
diff changeset
   293
#else
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   294
    if (avformat_find_stream_info(pContext, NULL) < 0)
7361
b73d7688dadc fix frontend for ffmpeg 0.7.13
Stepan777 <stepik-777@mail.ru>
parents: 7353
diff changeset
   295
#endif
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   296
        return "";
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   297
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   298
    int s = float(pContext->duration)/AV_TIME_BASE;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   299
    QString desc = QString(tr("Duration: %1m %2s\n")).arg(s/60).arg(s%60);
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   300
    for (int i = 0; i < pContext->nb_streams; i++)
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   301
    {
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   302
        AVStream* pStream = pContext->streams[i];
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   303
        if (!pStream)
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   304
            continue;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   305
        AVCodecContext* pCodec = pContext->streams[i]->codec;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   306
        if (!pCodec)
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   307
            continue;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   308
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   309
        if (pCodec->codec_type == AVMEDIA_TYPE_VIDEO)
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   310
        {
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   311
            desc += QString(tr("Video: %1x%2, ")).arg(pCodec->width).arg(pCodec->height);
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   312
            if (pStream->avg_frame_rate.den)
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   313
            {
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   314
                float fps = float(pStream->avg_frame_rate.num)/pStream->avg_frame_rate.den;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   315
                desc += QString(tr("%1 fps, ")).arg(fps, 0, 'f', 2);
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   316
            }
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   317
        }
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   318
        else if (pCodec->codec_type == AVMEDIA_TYPE_AUDIO)
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   319
            desc += tr("Audio: ");
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   320
        else
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   321
            continue;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   322
        AVCodec* pDecoder = avcodec_find_decoder(pCodec->codec_id);
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   323
        desc += pDecoder? pDecoder->name : "unknown";
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   324
        desc += "\n";
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   325
    }
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   326
    AVDictionaryEntry* pComment = av_dict_get(pContext->metadata, "comment", NULL, 0);
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   327
    if (pComment)
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   328
        desc += QString("\n") + pComment->value;
7361
b73d7688dadc fix frontend for ffmpeg 0.7.13
Stepan777 <stepik-777@mail.ru>
parents: 7353
diff changeset
   329
#if LIBAFORMAT_VERSION_MAJOR < 54
7280
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   330
    av_close_input_file(pContext);
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   331
#else
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   332
    avformat_close_input(&pContext);
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   333
#endif
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   334
    return desc;
fd707afbc3a2 pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents: 7235
diff changeset
   335
}