Add WriteVideoToFile to video_file_reader.

The function checks the file extension to determine YUV or Y4M format.

Also adds a flag aligned_output_file to compare_videos.py, which allows
saving the aligned reference video to a file.

Bug: webrtc:9642
Change-Id: Ia59f5c123a1e41104756eb6b235b6581c4ffbd77
Reviewed-on: https://webrtc-review.googlesource.com/99503
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Commit-Queue: Paulina Hensman <phensman@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24787}
diff --git a/rtc_tools/BUILD.gn b/rtc_tools/BUILD.gn
index ae80585..437dca4 100644
--- a/rtc_tools/BUILD.gn
+++ b/rtc_tools/BUILD.gn
@@ -73,6 +73,20 @@
   ]
 }
 
+rtc_static_library("video_file_writer") {
+  sources = [
+    "video_file_writer.cc",
+    "video_file_writer.h",
+  ]
+  deps = [
+    ":video_file_reader",
+    "../api/video:video_frame",
+    "../api/video:video_frame_i420",
+    "../rtc_base:rtc_base_approved",
+    "//third_party/abseil-cpp/absl/types:optional",
+  ]
+}
+
 rtc_static_library("video_quality_analysis") {
   sources = [
     "frame_analyzer/video_quality_analysis.cc",
@@ -101,6 +115,7 @@
   deps = [
     ":command_line_parser",
     ":video_file_reader",
+    ":video_file_writer",
     ":video_quality_analysis",
     "../rtc_base:stringutils",
     "../test:perf_test",
@@ -343,6 +358,7 @@
       "sanitizers_unittest.cc",
       "simple_command_line_parser_unittest.cc",
       "video_file_reader_unittest.cc",
+      "video_file_writer_unittest.cc",
     ]
 
     if (!build_with_chromium && is_clang) {
@@ -355,6 +371,7 @@
       ":frame_editing_lib",
       ":reference_less_video_analysis_lib",
       ":video_file_reader",
+      ":video_file_writer",
       ":video_quality_analysis",
       "../common_video:common_video",
       "../rtc_base",