summaryrefslogtreecommitdiff
path: root/v4l2-mfc-encoder/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'v4l2-mfc-encoder/main.c')
-rw-r--r--v4l2-mfc-encoder/main.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/v4l2-mfc-encoder/main.c b/v4l2-mfc-encoder/main.c
new file mode 100644
index 0000000..5681bab
--- /dev/null
+++ b/v4l2-mfc-encoder/main.c
@@ -0,0 +1,106 @@
+/*
+ * mfc codec encoding example application
+ * Andrzej Hajda <a.hajda@samsung.com>
+ *
+ * Main file of the application.
+ *
+ * Copyright 2012 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "common.h"
+#include "args.h"
+#include "in_demo.h"
+#include "in_camera.h"
+#include "out_file.h"
+#include "io_dev.h"
+#include "mfc.h"
+#include "v4l_dev.h"
+
+int main(int argc, char *argv[])
+{
+ struct options opts;
+
+ struct io_dev *input;
+ struct io_dev *mfc;
+ struct io_dev *output;
+ int i;
+
+ struct io_dev *chain[3] = {};
+
+ printf("mfc codec encoding example application\n"
+ "Andrzej Hajda <a.hajda@samsung.com>\n"
+ "Copyright 2012 Samsung Electronics Co., Ltd.\n\n");
+
+ if (parse_args(&opts, argc, argv)) {
+ print_usage(argv[0]);
+ return 1;
+ }
+
+ if (opts.in_name)
+ input = in_camera_create(opts.in_name);
+ else
+ input = in_demo_create(opts.width, opts.height);
+ if (input == NULL)
+ return 1;
+ chain[0] = input;
+
+ input->io[DIR_OUT].limit = opts.duration;
+
+ mfc = mfc_create(opts.mfc_name);
+ if (mfc == NULL)
+ return 1;
+ chain[1] = mfc;
+
+ if (mfc_set_fmt(mfc, DIR_IN, opts.width, opts.height))
+ return 1;
+
+ if (mfc_set_codec(mfc, DIR_OUT, opts.codec))
+ return 1;
+
+ if (mfc_set_rate(mfc, opts.rate))
+ return 1;
+
+ if (mfc_set_bitrate(mfc, opts.bitrate))
+ return 1;
+
+ mfc_set_mpeg_control(mfc, V4L2_CID_MPEG_VIDEO_B_FRAMES, 2);
+
+ if (opts.in_name)
+ if (v4l_copy_fmt(mfc, DIR_IN, input, DIR_OUT))
+ return 1;
+
+ output = out_file_create(opts.out_name);
+ if (output == NULL)
+ return 1;
+ chain[2] = output;
+
+ if (dev_bufs_create(input, mfc, MFC_ENC_IN_NBUF))
+ return 1;
+
+ if (dev_bufs_create(mfc, output, MFC_ENC_OUT_NBUF))
+ return 1;
+
+ if (process_chain(chain, array_len(chain)))
+ return 1;
+
+ for (i = 0; i < array_len(chain); ++i)
+ chain[i]->ops->destroy(chain[i]);
+
+ return 0;
+}