blob: 45af7fed4184110ea8219d1dae79ceae44a5b181 [file] [log] [blame]
brykt@google.comf5568902012-12-20 11:42:45 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_tools/frame_editing/frame_editing_lib.h"
brykt@google.comf5568902012-12-20 11:42:45 +000012
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "rtc_tools/simple_command_line_parser.h"
brykt@google.comf5568902012-12-20 11:42:45 +000018
19// A command-line tool to edit a YUV-video (I420 sub-sampled).
20int main(int argc, char** argv) {
21 std::string program_name = argv[0];
22 std::string usage = "Deletes a series of frames in a yuv file."
23 " Only I420 is supported!\n"
24 "Example usage:\n" + program_name +
25 " --in_path=input.yuv --width=320 --height=240 --f=60 --interval=1 --l=120"
26 " --out_path=edited_clip.yuv\n"
27 "Command line flags:\n"
28 "--in_path(string): Path and filename to the input file\n"
29 "--width(int): Width in pixels of the frames in the input file."
30 " Default: -1\n"
31 "--height(int): Height in pixels of the frames in the input file."
32 " Default: -1\n"
33 "--f(int): First frame to process. Default: -1\n"
34 "--l(int): Last frame to process. Default: -1\n"
35 "Frame numbering starts at 1. The set of frames to be processed includes "
36 "the frame with the number <f> and <l>.\n"
37 "--interval(int): Interval specifies with what ratio the number of frames "
38 "should be increased or decreased with.\n"
39 "If you set <interval> to a positive number, frames between <f> and <l> "
40 "will be inserted <interval> times."
41 " If you set <interval> to a negative number then the amount of frames "
42 "between <f> and <l> will be decreased with a ratio of abs(interval)."
43 " Set interval=-1 if every frame between <f> and <l> should be "
44 "deleted. Set interval=-2 if every second frame should be deleted, and so "
45 "on. Frame numbering between <f> and <l> starts with 1 and frames with"
46 " number n where (n - 1) % interval == 0 will be kept.\n"
47 "Example 1:\n"
48 "If one clip has 10 frames (1 to 10) and you specify <f>=4, <l>=7 and "
49 "interval=2, then you will get a clip that contains frame "
50 "1, 2, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9 and 10.\n"
51 "Example 2:\n"
52 "If you specify f=4, l=7 and interval=-1, then you will get a clip that"
53 " contains frame 1, 2, 3, 8, 9 and 10.\n"
54 "Example 3:\n"
55 "If one clip has 10 frames (1 to 10), and you specify f=1, l=10 and "
56 " interval=-4, then you will get a clip that contains frame "
57 "1, 5 and 9.\n"
58 "No interpolation is done when up-sampling."
59 " Default: -1\n"
60 "--out_path(string): The output file to which frames are written."
61 " Default: output.yuv\n";
62
63 webrtc::test::CommandLineParser parser;
64
65 // Init the parser and set the usage message
66 parser.Init(argc, argv);
67 parser.SetUsageMessage(usage);
68 parser.SetFlag("in_path", "-1");
69 parser.SetFlag("width", "-1");
70 parser.SetFlag("height", "-1");
71 parser.SetFlag("f", "-1");
72 parser.SetFlag("interval", "-1");
73 parser.SetFlag("l", "-1");
74 parser.SetFlag("out_path", "edited_output.yuv");
75 parser.SetFlag("help", "false");
76
77 parser.ProcessFlags();
78 if (parser.GetFlag("help") == "true") {
79 parser.PrintUsageMessage();
Thiago Farina3a939862015-04-09 15:45:12 +020080 exit(EXIT_SUCCESS);
brykt@google.comf5568902012-12-20 11:42:45 +000081 }
82 parser.PrintEnteredFlags();
83
84 const char* in_path = parser.GetFlag("in_path").c_str();
85 int width = strtol((parser.GetFlag("width")).c_str(), NULL, 10);
86 int height = strtol((parser.GetFlag("height")).c_str(), NULL, 10);
87 int first_frame_to_cut = strtol((parser.GetFlag("f")).c_str(), NULL, 10);
88 int interval = strtol((parser.GetFlag("interval")).c_str(), NULL, 10);
89 int last_frame_to_cut = strtol((parser.GetFlag("l")).c_str(), NULL, 10);
90
91 const char* out_path = parser.GetFlag("out_path").c_str();
92
93 if (!strcmp(in_path, "-1")) {
94 fprintf(stderr, "You must specify a file to edit\n");
95 return -1;
96 }
97
98 if (first_frame_to_cut <= 0 || last_frame_to_cut <= 0) {
99 fprintf(stderr, "Error: You must specify which frames to cut!\n");
100 return -2;
101 }
102
103 if (width <= 0 || height <= 0) {
104 fprintf(stderr, "Error: width or height cannot be <= 0!\n");
105 return -3;
106 }
107 return webrtc::EditFrames(in_path, width, height, first_frame_to_cut,
108 interval, last_frame_to_cut, out_path);
109}