| 1 | // JpegTest.cpp : Defines the entry point for the console application.
|
|---|
| 2 | //
|
|---|
| 3 |
|
|---|
| 4 | #include "config.h"
|
|---|
| 5 | #include <ctype.h>
|
|---|
| 6 | #include <string.h>
|
|---|
| 7 | #include <math.h>
|
|---|
| 8 | #include <stdlib.h>
|
|---|
| 9 | #include <errno.h>
|
|---|
| 10 | #include <limits.h>
|
|---|
| 11 | #if HAVE_ISATTY
|
|---|
| 12 | #if HAVE_IO_H
|
|---|
| 13 | #include <io.h>
|
|---|
| 14 | #endif
|
|---|
| 15 | #if HAVE_UNISTD_H
|
|---|
| 16 | #include <unistd.h>
|
|---|
| 17 | #endif
|
|---|
| 18 | #endif
|
|---|
| 19 | #include "libavformat/avformat.h"
|
|---|
| 20 | #include "libavdevice/avdevice.h"
|
|---|
| 21 | #include "libswscale/swscale.h"
|
|---|
| 22 | #include "libswresample/swresample.h"
|
|---|
| 23 | #include "libavutil/opt.h"
|
|---|
| 24 | #include "libavutil/channel_layout.h"
|
|---|
| 25 | #include "libavutil/parseutils.h"
|
|---|
| 26 | #include "libavutil/samplefmt.h"
|
|---|
| 27 | #include "libavutil/fifo.h"
|
|---|
| 28 | #include "libavutil/intreadwrite.h"
|
|---|
| 29 | #include "libavutil/dict.h"
|
|---|
| 30 | #include "libavutil/mathematics.h"
|
|---|
| 31 | #include "libavutil/pixdesc.h"
|
|---|
| 32 | #include "libavutil/avstring.h"
|
|---|
| 33 | #include "libavutil/libm.h"
|
|---|
| 34 | #include "libavutil/imgutils.h"
|
|---|
| 35 | #include "libavutil/timestamp.h"
|
|---|
| 36 | #include "libavutil/bprint.h"
|
|---|
| 37 | #include "libavutil/time.h"
|
|---|
| 38 | #include "libavformat/os_support.h"
|
|---|
| 39 |
|
|---|
| 40 | #include "libavformat/ffm.h" // not public API
|
|---|
| 41 |
|
|---|
| 42 | # include "libavfilter/avcodec.h"
|
|---|
| 43 | # include "libavfilter/avfilter.h"
|
|---|
| 44 | # include "libavfilter/buffersrc.h"
|
|---|
| 45 | # include "libavfilter/buffersink.h"
|
|---|
| 46 |
|
|---|
| 47 | #if HAVE_SYS_RESOURCE_H
|
|---|
| 48 | #include <sys/time.h>
|
|---|
| 49 | #include <sys/types.h>
|
|---|
| 50 | #include <sys/resource.h>
|
|---|
| 51 | #elif HAVE_GETPROCESSTIMES
|
|---|
| 52 | #include <windows.h>
|
|---|
| 53 | #endif
|
|---|
| 54 | #if HAVE_GETPROCESSMEMORYINFO
|
|---|
| 55 | #include <windows.h>
|
|---|
| 56 | #include <psapi.h>
|
|---|
| 57 | #endif
|
|---|
| 58 |
|
|---|
| 59 | #if HAVE_SYS_SELECT_H
|
|---|
| 60 | #include <sys/select.h>
|
|---|
| 61 | #endif
|
|---|
| 62 |
|
|---|
| 63 | #if HAVE_TERMIOS_H
|
|---|
| 64 | #include <fcntl.h>
|
|---|
| 65 | #include <sys/ioctl.h>
|
|---|
| 66 | #include <sys/time.h>
|
|---|
| 67 | #include <termios.h>
|
|---|
| 68 | #elif HAVE_KBHIT
|
|---|
| 69 | #include <conio.h>
|
|---|
| 70 | #endif
|
|---|
| 71 |
|
|---|
| 72 | #if HAVE_PTHREADS
|
|---|
| 73 | #include <pthread.h>
|
|---|
| 74 | #endif
|
|---|
| 75 |
|
|---|
| 76 | #include <time.h>
|
|---|
| 77 |
|
|---|
| 78 | #include "ffmpeg.h"
|
|---|
| 79 | #include "cmdutils.h"
|
|---|
| 80 |
|
|---|
| 81 | #include "libavutil/avassert.h"
|
|---|
| 82 |
|
|---|
| 83 | const char program_name[] = "ffmpeg";
|
|---|
| 84 | const int program_birth_year = 2000;
|
|---|
| 85 |
|
|---|
| 86 | static FILE *vstats_file;
|
|---|
| 87 |
|
|---|
| 88 | const char *const forced_keyframes_const_names[] = {
|
|---|
| 89 | "n",
|
|---|
| 90 | "n_forced",
|
|---|
| 91 | "prev_forced_n",
|
|---|
| 92 | "prev_forced_t",
|
|---|
| 93 | "t",
|
|---|
| 94 | NULL
|
|---|
| 95 | };
|
|---|
| 96 |
|
|---|
| 97 | static void do_video_stats(OutputStream *ost, int frame_size);
|
|---|
| 98 | static int64_t getutime(void);
|
|---|
| 99 | static int64_t getmaxrss(void);
|
|---|
| 100 |
|
|---|
| 101 | static int run_as_daemon = 0;
|
|---|
| 102 | static int64_t video_size = 0;
|
|---|
| 103 | static int64_t audio_size = 0;
|
|---|
| 104 | static int64_t subtitle_size = 0;
|
|---|
| 105 | static int64_t extra_size = 0;
|
|---|
| 106 | static int nb_frames_dup = 0;
|
|---|
| 107 | static int nb_frames_drop = 0;
|
|---|
| 108 | static int64_t decode_error_stat[2];
|
|---|
| 109 |
|
|---|
| 110 | static int current_time;
|
|---|
| 111 | AVIOContext *progress_avio = NULL;
|
|---|
| 112 |
|
|---|
| 113 | static uint8_t *subtitle_out;
|
|---|
| 114 |
|
|---|
| 115 | #if HAVE_PTHREADS
|
|---|
| 116 | /* signal to input threads that they should exit; set by the main thread */
|
|---|
| 117 | static int transcoding_finished;
|
|---|
| 118 | #endif
|
|---|
| 119 |
|
|---|
| 120 | #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
|
|---|
| 121 |
|
|---|
| 122 | InputStream **input_streams = NULL;
|
|---|
| 123 | int nb_input_streams = 0;
|
|---|
| 124 | InputFile **input_files = NULL;
|
|---|
| 125 | int nb_input_files = 0;
|
|---|
| 126 |
|
|---|
| 127 | OutputStream **output_streams = NULL;
|
|---|
| 128 | int nb_output_streams = 0;
|
|---|
| 129 | OutputFile **output_files = NULL;
|
|---|
| 130 | int nb_output_files = 0;
|
|---|
| 131 |
|
|---|
| 132 | FilterGraph **filtergraphs;
|
|---|
| 133 | int nb_filtergraphs;
|
|---|
| 134 |
|
|---|
| 135 | #if HAVE_TERMIOS_H
|
|---|
| 136 |
|
|---|
| 137 | /* init terminal so that we can grab keys */
|
|---|
| 138 | static struct termios oldtty;
|
|---|
| 139 | static int restore_tty;
|
|---|
| 140 | #endif
|
|---|
| 141 |
|
|---|
| 142 | const AVIOInterruptCB int_cb = { NULL, NULL };
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 | void term_exit(void)
|
|---|
| 146 | {
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | void term_init(void)
|
|---|
| 150 | {
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | void assert_avoptions(AVDictionary *m)
|
|---|
| 154 | {
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | int guess_input_channel_layout(InputStream *ist)
|
|---|
| 158 | {
|
|---|
| 159 | return 1;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | AVInputFormat *inputFormat = NULL;
|
|---|
| 163 | AVFormatContext *pFC = NULL;
|
|---|
| 164 | AVCodec *pCodec = NULL;
|
|---|
| 165 | AVStream *pStream = NULL;
|
|---|
| 166 | AVPacket packet = { 0 };
|
|---|
| 167 | AVFrame* pSrc = NULL;
|
|---|
| 168 | struct SwsContext *pSwsContext = NULL;
|
|---|
| 169 | AVFrame* pDest = NULL;
|
|---|
| 170 |
|
|---|
| 171 | int main(int argc, char **argv)
|
|---|
| 172 | {
|
|---|
| 173 | av_register_all();
|
|---|
| 174 |
|
|---|
| 175 | inputFormat = av_find_input_format("image2");
|
|---|
| 176 |
|
|---|
| 177 | int res = avformat_open_input(&pFC, "F:\\test\\root_banner.jpg", inputFormat, NULL);
|
|---|
| 178 |
|
|---|
| 179 | res = avformat_find_stream_info(pFC, NULL);
|
|---|
| 180 |
|
|---|
| 181 | int idx = av_find_best_stream(pFC, AVMEDIA_TYPE_VIDEO, -1, -1, &pCodec, -1);
|
|---|
| 182 |
|
|---|
| 183 | pStream = pFC->streams[idx];
|
|---|
| 184 | res = avcodec_open2(pStream->codec, pCodec, NULL);
|
|---|
| 185 |
|
|---|
| 186 | av_read_frame(pFC, &packet);
|
|---|
| 187 |
|
|---|
| 188 | int gotPicture;
|
|---|
| 189 | pSrc = avcodec_alloc_frame();
|
|---|
| 190 | avcodec_decode_video2(pStream->codec, pSrc, &gotPicture, &packet);
|
|---|
| 191 |
|
|---|
| 192 | av_free_packet(&packet);
|
|---|
| 193 |
|
|---|
| 194 | pSwsContext = sws_getCachedContext(pSwsContext,
|
|---|
| 195 | pSrc->width, pSrc->height,
|
|---|
| 196 | /*(PixelFormat)*/(pSrc->format),
|
|---|
| 197 | 1, 60, PIX_FMT_BGRA,
|
|---|
| 198 | SWS_BILINEAR, NULL, NULL, NULL
|
|---|
| 199 | );
|
|---|
| 200 |
|
|---|
| 201 | pDest = avcodec_alloc_frame();
|
|---|
| 202 | avpicture_alloc((AVPicture *)(pDest), PIX_FMT_BGRA, 1, 60);
|
|---|
| 203 | avpicture_free((AVPicture *)(pDest));
|
|---|
| 204 |
|
|---|
| 205 | avpicture_alloc((AVPicture *)(pDest), PIX_FMT_BGRA, 1, 60);
|
|---|
| 206 | sws_scale(pSwsContext, pSrc->data, pSrc->linesize,
|
|---|
| 207 | 0, pSrc->height, pDest->data, pDest->linesize
|
|---|
| 208 | );
|
|---|
| 209 |
|
|---|
| 210 | // in debug mode: HEAP[JpegTest.exe]: Heap block at 00706758 modified at 00706874 past requested size of 114
|
|---|
| 211 | avpicture_free((AVPicture *)(pDest));
|
|---|
| 212 | av_freep(&pDest);
|
|---|
| 213 | av_freep(&pSrc);
|
|---|
| 214 | avcodec_close(pStream->codec);
|
|---|
| 215 | avformat_close_input(&pFC);
|
|---|
| 216 |
|
|---|
| 217 | return 0;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|