📄 lqt_transcode.c
字号:
/******************************************************************************* lqt_transcode.c libquicktime - A library for reading and writing quicktime/avi/mp4 files. http://libquicktime.sourceforge.net Copyright (C) 2002 Heroine Virtual Ltd. Copyright (C) 2002-2007 Members of the libquicktime project. This library 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. This library 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 this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*******************************************************************************/ /* * Simple quicktime->quicktime transcoder * Used mainly for testing the encoder capabilities * of libquicktime *//* Limitation: Handles only 1 audio- and one video stream per file */#include <config.h> // ONLY for the PACKAGE macro. Usually, applications never need // to include config.h#define _(str) dgettext(PACKAGE, str)#include <libintl.h>#include <locale.h>#include <quicktime/lqt.h>#include <quicktime/colormodels.h>#include <stdlib.h>#include <stdio.h>#include <string.h>/* Supported colormodels */int colormodels[] = { BC_RGB565, BC_BGR565, BC_BGR888, BC_BGR8888, BC_RGB888, BC_RGBA8888, BC_RGB161616, BC_RGBA16161616, BC_YUVA8888, BC_YUV422, BC_YUV420P, BC_YUV422P, BC_YUV444P, BC_YUV411P, LQT_COLORMODEL_NONE };static struct { char * name; lqt_file_type_t type; char * extension; char * description; char * default_audio_codec; char * default_video_codec; }formats[] = { { "qt", LQT_FILE_QT, "mov", "Quicktime (QT7 compatible)", "faac", "ffmpeg_mpg4" }, { "qtold", LQT_FILE_QT_OLD, "mov", "Quicktime (qt4l and old lqt)", "twos", "mjpa" }, { "avi", LQT_FILE_AVI, "avi", "AVI (< 2G)", "lame", "ffmpeg_msmpeg4v3" }, { "avi_odml", LQT_FILE_AVI_ODML, "avi", "AVI (> 2G)", "lame", "ffmpeg_msmpeg4v3" }, { "mp4", LQT_FILE_MP4, "mp4", "ISO MPEG-4", "faac", "ffmpeg_mpg4" }, { "m4a", LQT_FILE_M4A, "m4a", "m4a (iTunes compatible)", "faac", "ffmpeg_mpg4" }, };static void list_formats() { int i; printf(_("Supported formats\n")); for(i = 0; i < sizeof(formats)/sizeof(formats[0]); i++) { printf(_("%8s: %s (default codecs: %s/%s)\n"), formats[i].name, formats[i].description, formats[i].default_audio_codec, formats[i].default_video_codec); } }typedef struct { quicktime_t * in_file; quicktime_t * out_file; int64_t num_video_frames; int64_t video_duration; int64_t num_audio_samples; int64_t audio_samples_written; int64_t video_frames_written; unsigned char ** video_buffer; float ** audio_buffer_f; int16_t ** audio_buffer_i; int samples_per_frame; int do_audio; int do_video; /* Format information */ int colormodel; int width; int height; int rowspan; int rowspan_uv; int frame_duration; int timescale; int samplerate; int num_channels; int audio_bits; /* Progress (0..1) */ float progress; } transcode_handle;static void print_usage() { printf(_("Usage: lqt_transcode [[-avi]|[-f <format>]] [-floataudio] [-qtvr <obj|pano>] [-qtvr_columns <columns>] [-qtvr_rows <rows>] [-ac <audio_codec>] [-vc <video_codec>] <in_file> <out_file>\n")); printf(_(" Transcode <in_file> to <out_file> using <audio_codec> and <video_codec>\n\n")); printf(_(" lqt_transcode -lv\n")); printf(_(" List video encoders\n\n")); printf(_(" lqt_transcode -la\n")); printf(_(" List audio encoders\n")); printf(_(" lqt_transcode -lf\n")); printf(_(" List output formats\n")); }static void list_info(lqt_codec_info_t ** info) { int i, j; int max_len; int len; max_len = 0; i = 0; while(info[i]) { len = strlen(info[i]->name); if(len > max_len) max_len = len; i++; } max_len++; i = 0; while(info[i]) { len = strlen(info[i]->name); printf("%s:", info[i]->name); len = strlen(info[i]->name); for(j = 0; j < max_len - len; j++) printf(" "); printf("%s\n", info[i]->long_name); i++; } }static void list_video_codecs() { lqt_codec_info_t ** info; info = lqt_query_registry(0, 1, 1, 0); list_info(info); lqt_destroy_codec_info(info); }static void list_audio_codecs() { lqt_codec_info_t ** info; info = lqt_query_registry(1, 0, 1, 0); list_info(info); lqt_destroy_codec_info(info); }static int transcode_init(transcode_handle * h, char * in_file, char * out_file, char * video_codec, char * audio_codec, int floataudio, lqt_file_type_t type, char * qtvr, int qtvr_rows, int qtvr_columns) { lqt_codec_info_t ** codec_info; int i; int in_cmodel, out_cmodel; char * extension; h->in_file = quicktime_open(in_file, 1, 0); if(!h->in_file) { fprintf(stderr, _("Cannot open input file %s\n"), in_file); return 0; } /* Get the output format */ if(type == LQT_FILE_NONE) { extension = strrchr(out_file, '.'); if(!extension) { fprintf(stderr, _("Need a file extension when autoguessing output format\n")); return 0; } extension++; for(i = 0; i < sizeof(formats)/sizeof(formats[0]); i++) { if(!strcasecmp(extension, formats[i].extension)) { type = formats[i].type; break; } } } if(type == LQT_FILE_NONE) { fprintf(stderr, _("Cannot detect output format. Specify a valid extension or use -f <format>\n")); return 0; } if(!audio_codec || !video_codec) { for(i = 0; i < sizeof(formats)/sizeof(formats[0]); i++) { if(type == formats[i].type) { if(!audio_codec) audio_codec = formats[i].default_audio_codec; if(!video_codec) video_codec = formats[i].default_video_codec; } } } h->out_file = lqt_open_write(out_file, type); if(!h->out_file) { fprintf(stderr, _("Cannot open output file %s\n"), out_file); return 0; } /* Check for video */ if(quicktime_video_tracks(h->in_file) && quicktime_supported_video(h->in_file, 0)) h->do_video = 1; if(h->do_video) { h->width = quicktime_video_width(h->in_file, 0); h->height = quicktime_video_height(h->in_file, 0); h->timescale = lqt_video_time_scale(h->in_file, 0); h->frame_duration = lqt_frame_duration(h->in_file, 0, NULL); /* Codec info for encoding */ codec_info = lqt_find_video_codec_by_name(video_codec); if(!codec_info) { fprintf(stderr, _("Unsupported video cocec %s, try -lv\n"), video_codec); return 0; } /* Set up the output track */ lqt_set_video(h->out_file, 1, h->width, h->height, h->frame_duration, h->timescale, codec_info[0]); /* Get colormodel */ in_cmodel = lqt_get_cmodel(h->in_file, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -