aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-multimedia/v4l2apps/yavta/0001-Add-stdout-mode-to-allow-streaming-over-the-network-.patch
blob: 41a5dbf4fd3319c0ab81e1760efe55b2cb06fe24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
From 141d3b3593722eb3d588e7c4b1542f810bc25853 Mon Sep 17 00:00:00 2001
From: Koen Kooi <koen@dominion.thruhere.net>
Date: Thu, 5 Jun 2014 11:29:20 -0500
Subject: [PATCH] Add stdout mode to allow streaming over the network with nc

Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
Signed-off-by: Chase Maupin <Chase.Maupin@ti.com>
---
 yavta.c |  315 ++++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 169 insertions(+), 146 deletions(-)

diff --git a/yavta.c b/yavta.c
index 32adc26..b398da0 100644
--- a/yavta.c
+++ b/yavta.c
@@ -309,7 +309,7 @@ static bool video_has_fd(struct device *dev)
 static int video_set_fd(struct device *dev, int fd)
 {
 	if (video_has_fd(dev)) {
-		printf("Can't set fd (already open).\n");
+		fprintf(stderr, "Can't set fd (already open).\n");
 		return -1;
 	}
 
@@ -321,18 +321,18 @@ static int video_set_fd(struct device *dev, int fd)
 static int video_open(struct device *dev, const char *devname)
 {
 	if (video_has_fd(dev)) {
-		printf("Can't open device (already open).\n");
+		fprintf(stderr, "Can't open device (already open).\n");
 		return -1;
 	}
 
 	dev->fd = open(devname, O_RDWR);
 	if (dev->fd < 0) {
-		printf("Error opening device %s: %s (%d).\n", devname,
+		fprintf(stderr, "Error opening device %s: %s (%d).\n", devname,
 		       strerror(errno), errno);
 		return dev->fd;
 	}
 
-	printf("Device %s opened.\n", devname);
+	fprintf(stderr, "Device %s opened.\n", devname);
 
 	dev->opened = 1;
 
@@ -352,7 +352,7 @@ static int video_querycap(struct device *dev, unsigned int *capabilities)
 	*capabilities = cap.capabilities & V4L2_CAP_DEVICE_CAPS
 		     ? cap.device_caps : cap.capabilities;
 
-	printf("Device `%s' on `%s' is a video %s (%s mplanes) device.\n",
+	fprintf(stderr, "Device `%s' on `%s' is a video %s (%s mplanes) device.\n",
 		cap.card, cap.bus_info,
 		video_is_capture(dev) ? "capture" : "output",
 		video_is_mplane(dev) ? "with" : "without");
@@ -370,7 +370,7 @@ static int cap_get_buf_type(unsigned int capabilities)
 	} else if (capabilities & V4L2_CAP_VIDEO_OUTPUT) {
 		return V4L2_BUF_TYPE_VIDEO_OUTPUT;
 	} else {
-		printf("Device supports neither capture nor output.\n");
+		fprintf(stderr, "Device supports neither capture nor output.\n");
 		return -EINVAL;
 	}
 
@@ -440,7 +440,7 @@ static int get_control(struct device *dev, unsigned int id, int type,
 		}
 	}
 
-	printf("unable to get control 0x%8.8x: %s (%d).\n",
+	fprintf(stderr, "unable to get control 0x%8.8x: %s (%d).\n",
 		id, strerror(errno), errno);
 	return -1;
 }
@@ -484,12 +484,12 @@ static void set_control(struct device *dev, unsigned int id, int type,
 			val = old.value;
 	}
 	if (ret == -1) {
-		printf("unable to set control 0x%8.8x: %s (%d).\n",
+		fprintf(stderr, "unable to set control 0x%8.8x: %s (%d).\n",
 			id, strerror(errno), errno);
 		return;
 	}
 
-	printf("Control 0x%08x set to %" PRId64 ", is %" PRId64 "\n",
+	fprintf(stderr, "Control 0x%08x set to %" PRId64 ", is %" PRId64 "\n",
 	       id, old_val, val);
 }
 
@@ -504,7 +504,7 @@ static int video_get_format(struct device *dev)
 
 	ret = ioctl(dev->fd, VIDIOC_G_FMT, &fmt);
 	if (ret < 0) {
-		printf("Unable to get format: %s (%d).\n", strerror(errno),
+		fprintf(stderr, "Unable to get format: %s (%d).\n", strerror(errno),
 			errno);
 		return ret;
 	}
@@ -514,7 +514,7 @@ static int video_get_format(struct device *dev)
 		dev->height = fmt.fmt.pix_mp.height;
 		dev->num_planes = fmt.fmt.pix_mp.num_planes;
 
-		printf("Video format: %s (%08x) %ux%u field %s, %u planes: \n",
+	    fprintf(stderr, "Video format: %s (%08x) %ux%u field %s, %u planes: \n",
 			v4l2_format_name(fmt.fmt.pix_mp.pixelformat), fmt.fmt.pix_mp.pixelformat,
 			fmt.fmt.pix_mp.width, fmt.fmt.pix_mp.height,
 			v4l2_field_name(fmt.fmt.pix_mp.field),
@@ -527,7 +527,7 @@ static int video_get_format(struct device *dev)
 					fmt.fmt.pix_mp.plane_fmt[i].bytesperline ?
 						fmt.fmt.pix_mp.plane_fmt[i].sizeimage : 0;
 
-			printf(" * Stride %u, buffer size %u\n",
+			fprintf(stderr, " * Stride %u, buffer size %u\n",
 				fmt.fmt.pix_mp.plane_fmt[i].bytesperline,
 				fmt.fmt.pix_mp.plane_fmt[i].sizeimage);
 		}
@@ -539,7 +539,7 @@ static int video_get_format(struct device *dev)
 		dev->plane_fmt[0].bytesperline = fmt.fmt.pix.bytesperline;
 		dev->plane_fmt[0].sizeimage = fmt.fmt.pix.bytesperline ? fmt.fmt.pix.sizeimage : 0;
 
-		printf("Video format: %s (%08x) %ux%u (stride %u) field %s buffer size %u\n",
+		fprintf(stderr, "Video format: %s (%08x) %ux%u (stride %u) field %s buffer size %u\n",
 			v4l2_format_name(fmt.fmt.pix.pixelformat), fmt.fmt.pix.pixelformat,
 			fmt.fmt.pix.width, fmt.fmt.pix.height, fmt.fmt.pix.bytesperline,
 			v4l2_field_name(fmt.fmt.pix_mp.field),
@@ -581,25 +581,25 @@ static int video_set_format(struct device *dev, unsigned int w, unsigned int h,
 
 	ret = ioctl(dev->fd, VIDIOC_S_FMT, &fmt);
 	if (ret < 0) {
-		printf("Unable to set format: %s (%d).\n", strerror(errno),
+		fprintf(stderr, "Unable to set format: %s (%d).\n", strerror(errno),
 			errno);
 		return ret;
 	}
 
 	if (video_is_mplane(dev)) {
-		printf("Video format set: %s (%08x) %ux%u field %s, %u planes: \n",
+		fprintf(stderr, "Video format set: %s (%08x) %ux%u field %s, %u planes: \n",
 			v4l2_format_name(fmt.fmt.pix_mp.pixelformat), fmt.fmt.pix_mp.pixelformat,
 			fmt.fmt.pix_mp.width, fmt.fmt.pix_mp.height,
 			v4l2_field_name(fmt.fmt.pix_mp.field),
 			fmt.fmt.pix_mp.num_planes);
 
 		for (i = 0; i < fmt.fmt.pix_mp.num_planes; i++) {
-			printf(" * Stride %u, buffer size %u\n",
+			fprintf(stderr, " * Stride %u, buffer size %u\n",
 				fmt.fmt.pix_mp.plane_fmt[i].bytesperline,
 				fmt.fmt.pix_mp.plane_fmt[i].sizeimage);
 		}
 	} else {
-		printf("Video format set: %s (%08x) %ux%u (stride %u) field %s buffer size %u\n",
+		fprintf(stderr, "Video format set: %s (%08x) %ux%u (stride %u) field %s buffer size %u\n",
 			v4l2_format_name(fmt.fmt.pix.pixelformat), fmt.fmt.pix.pixelformat,
 			fmt.fmt.pix.width, fmt.fmt.pix.height, fmt.fmt.pix.bytesperline,
 			v4l2_field_name(fmt.fmt.pix.field),
@@ -619,16 +619,16 @@ static int video_set_framerate(struct device *dev, struct v4l2_fract *time_per_f
 
 	ret = ioctl(dev->fd, VIDIOC_G_PARM, &parm);
 	if (ret < 0) {
-		printf("Unable to get frame rate: %s (%d).\n",
+		fprintf(stderr, "Unable to get frame rate: %s (%d).\n",
 			strerror(errno), errno);
 		return ret;
 	}
 
-	printf("Current frame rate: %u/%u\n",
+	fprintf(stderr, "Current frame rate: %u/%u\n",
 		parm.parm.capture.timeperframe.numerator,
 		parm.parm.capture.timeperframe.denominator);
 
-	printf("Setting frame rate to: %u/%u\n",
+	fprintf(stderr, "Setting frame rate to: %u/%u\n",
 		time_per_frame->numerator,
 		time_per_frame->denominator);
 
@@ -637,19 +637,19 @@ static int video_set_framerate(struct device *dev, struct v4l2_fract *time_per_f
 
 	ret = ioctl(dev->fd, VIDIOC_S_PARM, &parm);
 	if (ret < 0) {
-		printf("Unable to set frame rate: %s (%d).\n", strerror(errno),
+		fprintf(stderr, "Unable to set frame rate: %s (%d).\n", strerror(errno),
 			errno);
 		return ret;
 	}
 
 	ret = ioctl(dev->fd, VIDIOC_G_PARM, &parm);
 	if (ret < 0) {
-		printf("Unable to get frame rate: %s (%d).\n", strerror(errno),
+		fprintf(stderr, "Unable to get frame rate: %s (%d).\n", strerror(errno),
 			errno);
 		return ret;
 	}
 
-	printf("Frame rate set: %u/%u\n",
+	fprintf(stderr, "Frame rate set: %u/%u\n",
 		parm.parm.capture.timeperframe.numerator,
 		parm.parm.capture.timeperframe.denominator);
 	return 0;
@@ -674,7 +674,7 @@ static int video_buffer_mmap(struct device *dev, struct buffer *buffer,
 		buffer->mem[i] = mmap(0, length, PROT_READ | PROT_WRITE, MAP_SHARED,
 				      dev->fd, offset);
 		if (buffer->mem[i] == MAP_FAILED) {
-			printf("Unable to map buffer %u/%u: %s (%d)\n",
+			fprintf(stderr, "Unable to map buffer %u/%u: %s (%d)\n",
 			       buffer->idx, i, strerror(errno), errno);
 			return -1;
 		}
@@ -682,7 +682,7 @@ static int video_buffer_mmap(struct device *dev, struct buffer *buffer,
 		buffer->size[i] = length;
 		buffer->padding[i] = 0;
 
-		printf("Buffer %u/%u mapped at address %p.\n",
+		fprintf(stderr, "Buffer %u/%u mapped at address %p.\n",
 		       buffer->idx, i, buffer->mem[i]);
 	}
 
@@ -697,7 +697,7 @@ static int video_buffer_munmap(struct device *dev, struct buffer *buffer)
 	for (i = 0; i < dev->num_planes; i++) {
 		ret = munmap(buffer->mem[i], buffer->size[i]);
 		if (ret < 0) {
-			printf("Unable to unmap buffer %u/%u: %s (%d)\n",
+			fprintf(stderr, "Unable to unmap buffer %u/%u: %s (%d)\n",
 			       buffer->idx, i, strerror(errno), errno);
 		}
 
@@ -725,7 +725,7 @@ static int video_buffer_alloc_userptr(struct device *dev, struct buffer *buffer,
 		ret = posix_memalign(&buffer->mem[i], page_size,
 				     length + offset + padding);
 		if (ret < 0) {
-			printf("Unable to allocate buffer %u/%u (%d)\n",
+			fprintf(stderr, "Unable to allocate buffer %u/%u (%d)\n",
 			       buffer->idx, i, ret);
 			return -ENOMEM;
 		}
@@ -734,7 +734,7 @@ static int video_buffer_alloc_userptr(struct device *dev, struct buffer *buffer,
 		buffer->size[i] = length;
 		buffer->padding[i] = padding;
 
-		printf("Buffer %u/%u allocated at address %p.\n",
+		fprintf(stderr, "Buffer %u/%u allocated at address %p.\n",
 		       buffer->idx, i, buffer->mem[i]);
 	}
 
@@ -809,12 +809,12 @@ static int video_alloc_buffers(struct device *dev, int nbufs,
 
 	ret = ioctl(dev->fd, VIDIOC_REQBUFS, &rb);
 	if (ret < 0) {
-		printf("Unable to request buffers: %s (%d).\n", strerror(errno),
+		fprintf(stderr, "Unable to request buffers: %s (%d).\n", strerror(errno),
 			errno);
 		return ret;
 	}
 
-	printf("%u buffers requested.\n", rb.count);
+	fprintf(stderr, "%u buffers requested.\n", rb.count);
 
 	buffers = malloc(rb.count * sizeof buffers[0]);
 	if (buffers == NULL)
@@ -835,12 +835,12 @@ static int video_alloc_buffers(struct device *dev, int nbufs,
 
 		ret = ioctl(dev->fd, VIDIOC_QUERYBUF, &buf);
 		if (ret < 0) {
-			printf("Unable to query buffer %u: %s (%d).\n", i,
+			fprintf(stderr, "Unable to query buffer %u: %s (%d).\n", i,
 				strerror(errno), errno);
 			return ret;
 		}
 		get_ts_flags(buf.flags, &ts_type, &ts_source);
-		printf("length: %u offset: %u timestamp type/source: %s/%s\n",
+		fprintf(stderr, "length: %u offset: %u timestamp type/source: %s/%s\n",
 		       buf.length, buf.m.offset, ts_type, ts_source);
 
 		buffers[i].idx = i;
@@ -899,12 +899,12 @@ static int video_free_buffers(struct device *dev)
 
 	ret = ioctl(dev->fd, VIDIOC_REQBUFS, &rb);
 	if (ret < 0) {
-		printf("Unable to release buffers: %s (%d).\n",
+		fprintf(stderr, "Unable to release buffers: %s (%d).\n",
 			strerror(errno), errno);
 		return ret;
 	}
 
-	printf("%u buffers released.\n", dev->nbufs);
+	fprintf(stderr, "%u buffers released.\n", dev->nbufs);
 
 	free(dev->buffers);
 	dev->nbufs = 0;
@@ -974,7 +974,7 @@ static int video_queue_buffer(struct device *dev, int index, enum buffer_fill_mo
 
 	ret = ioctl(dev->fd, VIDIOC_QBUF, &buf);
 	if (ret < 0)
-		printf("Unable to queue buffer: %s (%d).\n",
+		fprintf(stderr, "Unable to queue buffer: %s (%d).\n",
 			strerror(errno), errno);
 
 	return ret;
@@ -987,7 +987,7 @@ static int video_enable(struct device *dev, int enable)
 
 	ret = ioctl(dev->fd, enable ? VIDIOC_STREAMON : VIDIOC_STREAMOFF, &type);
 	if (ret < 0) {
-		printf("Unable to %s streaming: %s (%d).\n",
+		fprintf(stderr, "Unable to %s streaming: %s (%d).\n",
 			enable ? "start" : "stop", strerror(errno), errno);
 		return ret;
 	}
@@ -1009,10 +1009,10 @@ static void video_query_menu(struct device *dev, struct v4l2_queryctrl *query,
 			continue;
 
 		if (query->type == V4L2_CTRL_TYPE_MENU)
-			printf("  %u: %.32s%s\n", menu.index, menu.name,
+			fprintf(stderr, "  %u: %.32s%s\n", menu.index, menu.name,
 			       menu.index == value ? " (*)" : "");
 		else
-			printf("  %u: %lld%s\n", menu.index, menu.value,
+			fprintf(stderr, "  %u: %lld%s\n", menu.index, menu.value,
 			       menu.index == value ? " (*)" : "");
 	};
 }
@@ -1043,7 +1043,7 @@ static void video_list_controls(struct device *dev)
 			continue;
 
 		if (query.type == V4L2_CTRL_TYPE_CTRL_CLASS) {
-			printf("--- %s (class 0x%08x) ---\n", query.name, query.id);
+			fprintf(stderr, "--- %s (class 0x%08x) ---\n", query.name, query.id);
 			continue;
 		}
 
@@ -1053,7 +1053,7 @@ static void video_list_controls(struct device *dev)
 		else
 			sprintf(value, "%" PRId64, val64);
 
-		printf("control 0x%08x `%s' min %d max %d step %d default %d current %s.\n",
+		fprintf(stderr, "control 0x%08x `%s' min %d max %d step %d default %d current %s.\n",
 			query.id, query.name, query.minimum, query.maximum,
 			query.step, query.default_value, value);
 
@@ -1065,9 +1065,9 @@ static void video_list_controls(struct device *dev)
 	}
 
 	if (nctrls)
-		printf("%u control%s found.\n", nctrls, nctrls > 1 ? "s" : "");
+		fprintf(stderr, "%u control%s found.\n", nctrls, nctrls > 1 ? "s" : "");
 	else
-		printf("No control found.\n");
+		fprintf(stderr, "No control found.\n");
 }
 
 static void video_enum_frame_intervals(struct device *dev, __u32 pixelformat,
@@ -1088,30 +1088,30 @@ static void video_enum_frame_intervals(struct device *dev, __u32 pixelformat,
 			break;
 
 		if (i != ival.index)
-			printf("Warning: driver returned wrong ival index "
+			fprintf(stderr, "Warning: driver returned wrong ival index "
 				"%u.\n", ival.index);
 		if (pixelformat != ival.pixel_format)
-			printf("Warning: driver returned wrong ival pixel "
+			fprintf(stderr, "Warning: driver returned wrong ival pixel "
 				"format %08x.\n", ival.pixel_format);
 		if (width != ival.width)
-			printf("Warning: driver returned wrong ival width "
+			fprintf(stderr, "Warning: driver returned wrong ival width "
 				"%u.\n", ival.width);
 		if (height != ival.height)
-			printf("Warning: driver returned wrong ival height "
+			fprintf(stderr, "Warning: driver returned wrong ival height "
 				"%u.\n", ival.height);
 
 		if (i != 0)
-			printf(", ");
+			fprintf(stderr, ", ");
 
 		switch (ival.type) {
 		case V4L2_FRMIVAL_TYPE_DISCRETE:
-			printf("%u/%u",
+			fprintf(stderr, "%u/%u",
 				ival.discrete.numerator,
 				ival.discrete.denominator);
 			break;
 
 		case V4L2_FRMIVAL_TYPE_CONTINUOUS:
-			printf("%u/%u - %u/%u",
+			fprintf(stderr, "%u/%u - %u/%u",
 				ival.stepwise.min.numerator,
 				ival.stepwise.min.denominator,
 				ival.stepwise.max.numerator,
@@ -1119,7 +1119,7 @@ static void video_enum_frame_intervals(struct device *dev, __u32 pixelformat,
 			return;
 
 		case V4L2_FRMIVAL_TYPE_STEPWISE:
-			printf("%u/%u - %u/%u (by %u/%u)",
+			fprintf(stderr, "%u/%u - %u/%u (by %u/%u)",
 				ival.stepwise.min.numerator,
 				ival.stepwise.min.denominator,
 				ival.stepwise.max.numerator,
@@ -1149,23 +1149,23 @@ static void video_enum_frame_sizes(struct device *dev, __u32 pixelformat)
 			break;
 
 		if (i != frame.index)
-			printf("Warning: driver returned wrong frame index "
+			fprintf(stderr, "Warning: driver returned wrong frame index "
 				"%u.\n", frame.index);
 		if (pixelformat != frame.pixel_format)
-			printf("Warning: driver returned wrong frame pixel "
+			fprintf(stderr, "Warning: driver returned wrong frame pixel "
 				"format %08x.\n", frame.pixel_format);
 
 		switch (frame.type) {
 		case V4L2_FRMSIZE_TYPE_DISCRETE:
-			printf("\tFrame size: %ux%u (", frame.discrete.width,
+			fprintf(stderr, "\tFrame size: %ux%u (", frame.discrete.width,
 				frame.discrete.height);
 			video_enum_frame_intervals(dev, frame.pixel_format,
 				frame.discrete.width, frame.discrete.height);
-			printf(")\n");
+			fprintf(stderr, ")\n");
 			break;
 
 		case V4L2_FRMSIZE_TYPE_CONTINUOUS:
-			printf("\tFrame size: %ux%u - %ux%u (",
+			fprintf(stderr, "\tFrame size: %ux%u - %ux%u (",
 				frame.stepwise.min_width,
 				frame.stepwise.min_height,
 				frame.stepwise.max_width,
@@ -1173,11 +1173,11 @@ static void video_enum_frame_sizes(struct device *dev, __u32 pixelformat)
 			video_enum_frame_intervals(dev, frame.pixel_format,
 				frame.stepwise.max_width,
 				frame.stepwise.max_height);
-			printf(")\n");
+			fprintf(stderr, ")\n");
 			break;
 
 		case V4L2_FRMSIZE_TYPE_STEPWISE:
-			printf("\tFrame size: %ux%u - %ux%u (by %ux%u) (\n",
+			fprintf(stderr, "\tFrame size: %ux%u - %ux%u (by %ux%u) (\n",
 				frame.stepwise.min_width,
 				frame.stepwise.min_height,
 				frame.stepwise.max_width,
@@ -1187,7 +1187,7 @@ static void video_enum_frame_sizes(struct device *dev, __u32 pixelformat)
 			video_enum_frame_intervals(dev, frame.pixel_format,
 				frame.stepwise.max_width,
 				frame.stepwise.max_height);
-			printf(")\n");
+			fprintf(stderr, ")\n");
 			break;
 
 		default:
@@ -1211,19 +1211,19 @@ static void video_enum_formats(struct device *dev, enum v4l2_buf_type type)
 			break;
 
 		if (i != fmt.index)
-			printf("Warning: driver returned wrong format index "
+			fprintf(stderr, "Warning: driver returned wrong format index "
 				"%u.\n", fmt.index);
 		if (type != fmt.type)
-			printf("Warning: driver returned wrong format type "
+			fprintf(stderr, "Warning: driver returned wrong format type "
 				"%u.\n", fmt.type);
 
-		printf("\tFormat %u: %s (%08x)\n", i,
+		fprintf(stderr, "\tFormat %u: %s (%08x)\n", i,
 			v4l2_format_name(fmt.pixelformat), fmt.pixelformat);
-		printf("\tType: %s (%u)\n", v4l2_buf_type_name(fmt.type),
+		fprintf(stderr, "\tType: %s (%u)\n", v4l2_buf_type_name(fmt.type),
 			fmt.type);
-		printf("\tName: %.32s\n", fmt.description);
+		fprintf(stderr, "\tName: %.32s\n", fmt.description);
 		video_enum_frame_sizes(dev, fmt.pixelformat);
-		printf("\n");
+		fprintf(stderr, "\n");
 	}
 }
 
@@ -1241,13 +1241,13 @@ static void video_enum_inputs(struct device *dev)
 			break;
 
 		if (i != input.index)
-			printf("Warning: driver returned wrong input index "
+			fprintf(stderr, "Warning: driver returned wrong input index "
 				"%u.\n", input.index);
 
-		printf("\tInput %u: %s.\n", i, input.name);
+		fprintf(stderr, "\tInput %u: %s.\n", i, input.name);
 	}
 
-	printf("\n");
+	fprintf(stderr, "\n");
 }
 
 static int video_get_input(struct device *dev)
@@ -1257,7 +1257,7 @@ static int video_get_input(struct device *dev)
 
 	ret = ioctl(dev->fd, VIDIOC_G_INPUT, &input);
 	if (ret < 0) {
-		printf("Unable to get current input: %s (%d).\n",
+		fprintf(stderr, "Unable to get current input: %s (%d).\n",
 			strerror(errno), errno);
 		return ret;
 	}
@@ -1272,7 +1272,7 @@ static int video_set_input(struct device *dev, unsigned int input)
 
 	ret = ioctl(dev->fd, VIDIOC_S_INPUT, &_input);
 	if (ret < 0)
-		printf("Unable to select input %u: %s (%d).\n", input,
+		fprintf(stderr, "Unable to select input %u: %s (%d).\n", input,
 			strerror(errno), errno);
 
 	return ret;
@@ -1291,14 +1291,14 @@ static int video_set_quality(struct device *dev, unsigned int quality)
 
 	ret = ioctl(dev->fd, VIDIOC_S_JPEGCOMP, &jpeg);
 	if (ret < 0) {
-		printf("Unable to set quality to %u: %s (%d).\n", quality,
+		fprintf(stderr, "Unable to set quality to %u: %s (%d).\n", quality,
 			strerror(errno), errno);
 		return ret;
 	}
 
 	ret = ioctl(dev->fd, VIDIOC_G_JPEGCOMP, &jpeg);
 	if (ret >= 0)
-		printf("Quality set to %u\n", jpeg.quality);
+		fprintf(stderr, "Quality set to %u\n", jpeg.quality);
 
 	return 0;
 }
@@ -1313,7 +1313,7 @@ static int video_load_test_pattern(struct device *dev, const char *filename)
 	if (filename != NULL) {
 		fd = open(filename, O_RDONLY);
 		if (fd == -1) {
-			printf("Unable to open test pattern file '%s': %s (%d).\n",
+			fprintf(stderr, "Unable to open test pattern file '%s': %s (%d).\n",
 				filename, strerror(errno), errno);
 			return -errno;
 		}
@@ -1331,7 +1331,7 @@ static int video_load_test_pattern(struct device *dev, const char *filename)
 		if (filename != NULL) {
 			ret = read(fd, dev->pattern[plane], size);
 			if (ret != (int)size && dev->plane_fmt[plane].bytesperline != 0) {
-				printf("Test pattern file size %u doesn't match image size %u\n",
+				fprintf(stderr, "Test pattern file size %u doesn't match image size %u\n",
 					ret, size);
 				ret = -EINVAL;
 				goto done;
@@ -1341,7 +1341,7 @@ static int video_load_test_pattern(struct device *dev, const char *filename)
 			unsigned int i;
 
 			if (dev->plane_fmt[plane].bytesperline == 0) {
-				printf("Compressed format detected for plane %u and no test pattern filename given.\n"
+				fprintf(stderr, "Compressed format detected for plane %u and no test pattern filename given.\n"
 					"The test pattern can't be generated automatically.\n", plane);
 				ret = -EINVAL;
 				goto done;
@@ -1410,7 +1410,7 @@ static void video_verify_buffer(struct device *dev, struct v4l2_buffer *buf)
 
 		if (dev->plane_fmt[plane].sizeimage &&
 		    dev->plane_fmt[plane].sizeimage != length)
-			printf("Warning: bytes used %u != image size %u for plane %u\n",
+			fprintf(stderr, "Warning: bytes used %u != image size %u for plane %u\n",
 			       length, dev->plane_fmt[plane].sizeimage, plane);
 
 		if (buffer->padding[plane] == 0)
@@ -1424,16 +1424,16 @@ static void video_verify_buffer(struct device *dev, struct v4l2_buffer *buf)
 		}
 
 		if (errors) {
-			printf("Warning: %u bytes overwritten among %u first padding bytes for plane %u\n",
+			fprintf(stderr, "Warning: %u bytes overwritten among %u first padding bytes for plane %u\n",
 			       errors, dirty, plane);
 
 			dirty = (dirty + 15) & ~15;
 			dirty = dirty > 32 ? 32 : dirty;
 
 			for (i = 0; i < dirty; ++i) {
-				printf("%02x ", data[i]);
+				fprintf(stderr, "%02x ", data[i]);
 				if (i % 16 == 15)
-					printf("\n");
+					fprintf(stderr, "\n");
 			}
 		}
 	}
@@ -1481,18 +1481,32 @@ static void video_save_image(struct device *dev, struct v4l2_buffer *buf,
 
 		ret = write(fd, dev->buffers[buf->index].mem[i], length);
 		if (ret < 0) {
-			printf("write error: %s (%d)\n", strerror(errno), errno);
+			fprintf(stderr, "write error: %s (%d)\n", strerror(errno), errno);
 			break;
 		} else if (ret != (int)length)
-			printf("write error: only %d bytes written instead of %u\n",
+			fprintf(stderr, "write error: only %d bytes written instead of %u\n",
 			       ret, length);
 	}
 	close(fd);
 }
 
+static void video_stdout_image(struct device *dev, struct v4l2_buffer *buf)
+{
+    int ret;
+
+    fprintf(stderr, "stdout");
+    ret = fwrite(dev->buffers[buf->index].mem, buf->bytesused, 1, stdout);
+
+    if (ret < 0)
+        fprintf(stderr, "write error: %s (%d)\n", strerror(errno), errno);
+    else if (ret != (int)buf->bytesused)
+        fprintf(stderr, "write error: only %d bytes written instead of %u\n",
+                ret, buf->bytesused);
+}
+
 static int video_do_capture(struct device *dev, unsigned int nframes,
 	unsigned int skip, unsigned int delay, const char *pattern,
-	int do_requeue_last, enum buffer_fill_mode fill)
+	int do_requeue_last, enum buffer_fill_mode fill, int do_stdout)
 {
 	struct v4l2_plane planes[VIDEO_MAX_PLANES];
 	struct v4l2_buffer buf;
@@ -1529,7 +1543,7 @@ static int video_do_capture(struct device *dev, unsigned int nframes,
 		ret = ioctl(dev->fd, VIDIOC_DQBUF, &buf);
 		if (ret < 0) {
 			if (errno != EIO) {
-				printf("Unable to dequeue buffer: %s (%d).\n",
+				fprintf(stderr, "Unable to dequeue buffer: %s (%d).\n",
 					strerror(errno), errno);
 				goto done;
 			}
@@ -1550,7 +1564,7 @@ static int video_do_capture(struct device *dev, unsigned int nframes,
 
 		clock_gettime(CLOCK_MONOTONIC, &ts);
 		get_ts_flags(buf.flags, &ts_type, &ts_source);
-		printf("%u (%u) [%c] %s %u %u B %ld.%06ld %ld.%06ld %.3f fps ts %s/%s\n", i, buf.index,
+		fprintf(stderr, "%u (%u) [%c] %s %u %u B %ld.%06ld %ld.%06ld %.3f fps ts %s/%s\n", i, buf.index,
 			(buf.flags & V4L2_BUF_FLAG_ERROR) ? 'E' : '-',
 			v4l2_field_name(buf.field),
 			buf.sequence, buf.bytesused, buf.timestamp.tv_sec,
@@ -1563,6 +1577,9 @@ static int video_do_capture(struct device *dev, unsigned int nframes,
 		if (video_is_capture(dev) && pattern && !skip)
 			video_save_image(dev, &buf, pattern, i);
 
+		if (video_is_capture(dev) && do_stdout && !skip)
+			video_stdout_image(dev, &buf);
+
 		if (skip)
 			--skip;
 
@@ -1577,7 +1594,7 @@ static int video_do_capture(struct device *dev, unsigned int nframes,
 
 		ret = video_queue_buffer(dev, buf.index, fill);
 		if (ret < 0) {
-			printf("Unable to requeue buffer: %s (%d).\n",
+			fprintf(stderr, "Unable to requeue buffer: %s (%d).\n",
 				strerror(errno), errno);
 			goto done;
 		}
@@ -1587,7 +1604,7 @@ static int video_do_capture(struct device *dev, unsigned int nframes,
 	video_enable(dev, 0);
 
 	if (nframes == 0) {
-		printf("No frames captured.\n");
+		fprintf(stderr, "No frames captured.\n");
 		goto done;
 	}
 
@@ -1604,7 +1621,7 @@ static int video_do_capture(struct device *dev, unsigned int nframes,
 	bps = size/(ts.tv_nsec/1000.0+1000000.0*ts.tv_sec)*1000000.0;
 	fps = i/(ts.tv_nsec/1000.0+1000000.0*ts.tv_sec)*1000000.0;
 
-	printf("Captured %u frames in %lu.%06lu seconds (%f fps, %f B/s).\n",
+	fprintf(stderr, "Captured %u frames in %lu.%06lu seconds (%f fps, %f B/s).\n",
 		i, ts.tv_sec, ts.tv_nsec/1000, fps, bps);
 
 done:
@@ -1616,42 +1633,42 @@ done:
 
 static void usage(const char *argv0)
 {
-	printf("Usage: %s [options] device\n", argv0);
-	printf("Supported options:\n");
-	printf("-B, --buffer-type		Buffer type (\"capture\", \"output\",\n");
-	printf("                                \"capture-mplane\" or \"output-mplane\")\n");
-	printf("-c, --capture[=nframes]		Capture frames\n");
-	printf("-C, --check-overrun		Verify dequeued frames for buffer overrun\n");
-	printf("-d, --delay			Delay (in ms) before requeuing buffers\n");
-	printf("-f, --format format		Set the video format\n");
-	printf("-F, --file[=name]		Read/write frames from/to disk\n");
-	printf("\tFor video capture devices, the first '#' character in the file name is\n");
-	printf("\texpanded to the frame sequence number. The default file name is\n");
-	printf("\t'frame-#.bin'.\n");
-	printf("-h, --help			Show this help screen\n");
-	printf("-i, --input input		Select the video input\n");
-	printf("-I, --fill-frames		Fill frames with check pattern before queuing them\n");
-	printf("-l, --list-controls		List available controls\n");
-	printf("-n, --nbufs n			Set the number of video buffers\n");
-	printf("-p, --pause			Pause before starting the video stream\n");
-	printf("-q, --quality n			MJPEG quality (0-100)\n");
-	printf("-r, --get-control ctrl		Get control 'ctrl'\n");
-	printf("-R, --realtime=[priority]	Enable realtime RR scheduling\n");
-	printf("-s, --size WxH			Set the frame size\n");
-	printf("-t, --time-per-frame num/denom	Set the time per frame (eg. 1/25 = 25 fps)\n");
-	printf("-u, --userptr			Use the user pointers streaming method\n");
-	printf("-w, --set-control 'ctrl value'	Set control 'ctrl' to 'value'\n");
-	printf("    --enum-formats		Enumerate formats\n");
-	printf("    --enum-inputs		Enumerate inputs\n");
-	printf("    --fd                        Use a numeric file descriptor insted of a device\n");
-	printf("    --field			Interlaced format field order\n");
-	printf("    --no-query			Don't query capabilities on open\n");
-	printf("    --offset			User pointer buffer offset from page start\n");
-	printf("    --requeue-last		Requeue the last buffers before streamoff\n");
-	printf("    --timestamp-source		Set timestamp source on output buffers [eof, soe]\n");
-	printf("    --skip n			Skip the first n frames\n");
-	printf("    --sleep-forever		Sleep forever after configuring the device\n");
-	printf("    --stride value		Line stride in bytes\n");
+	fprintf(stderr, "Usage: %s [options] device\n", argv0);
+	fprintf(stderr, "Supported options:\n");
+	fprintf(stderr, "-B, --buffer-type		Buffer type (\"capture\", \"output\",\n");
+	fprintf(stderr, "                                \"capture-mplane\" or \"output-mplane\")\n");
+	fprintf(stderr, "-c, --capture[=nframes]		Capture frames\n");
+	fprintf(stderr, "-C, --check-overrun		Verify dequeued frames for buffer overrun\n");
+	fprintf(stderr, "-d, --delay			Delay (in ms) before requeuing buffers\n");
+	fprintf(stderr, "-f, --format format		Set the video format\n");
+	fprintf(stderr, "-F, --file[=name]		Read/write frames from/to disk\n");
+	fprintf(stderr, "\tFor video capture devices, the first '#' character in the file name is\n");
+	fprintf(stderr, "\texpanded to the frame sequence number. The default file name is\n");
+	fprintf(stderr, "\t'frame-#.bin'.\n");
+	fprintf(stderr, "-h, --help			Show this help screen\n");
+	fprintf(stderr, "-i, --input input		Select the video input\n");
+	fprintf(stderr, "-I, --fill-frames		Fill frames with check pattern before queuing them\n");
+	fprintf(stderr, "-l, --list-controls		List available controls\n");
+	fprintf(stderr, "-n, --nbufs n			Set the number of video buffers\n");
+	fprintf(stderr, "-p, --pause			Pause before starting the video stream\n");
+	fprintf(stderr, "-q, --quality n			MJPEG quality (0-100)\n");
+	fprintf(stderr, "-r, --get-control ctrl		Get control 'ctrl'\n");
+	fprintf(stderr, "-R, --realtime=[priority]	Enable realtime RR scheduling\n");
+	fprintf(stderr, "-s, --size WxH			Set the frame size\n");
+	fprintf(stderr, "-t, --time-per-frame num/denom	Set the time per frame (eg. 1/25 = 25 fps)\n");
+	fprintf(stderr, "-u, --userptr			Use the user pointers streaming method\n");
+	fprintf(stderr, "-w, --set-control 'ctrl value'	Set control 'ctrl' to 'value'\n");
+	fprintf(stderr, "    --enum-formats		Enumerate formats\n");
+	fprintf(stderr, "    --enum-inputs		Enumerate inputs\n");
+	fprintf(stderr, "    --fd                        Use a numeric file descriptor insted of a device\n");
+	fprintf(stderr, "    --field			Interlaced format field order\n");
+	fprintf(stderr, "    --no-query			Don't query capabilities on open\n");
+	fprintf(stderr, "    --offset			User pointer buffer offset from page start\n");
+	fprintf(stderr, "    --requeue-last		Requeue the last buffers before streamoff\n");
+	fprintf(stderr, "    --timestamp-source		Set timestamp source on output buffers [eof, soe]\n");
+	fprintf(stderr, "    --skip n			Skip the first n frames\n");
+	fprintf(stderr, "    --sleep-forever		Sleep forever after configuring the device\n");
+	fprintf(stderr, "    --stride value		Line stride in bytes\n");
 }
 
 #define OPT_ENUM_FORMATS	256
@@ -1665,6 +1682,7 @@ static void usage(const char *argv0)
 #define OPT_FD			264
 #define OPT_TSTAMP_SRC		265
 #define OPT_FIELD		266
+#define OPT_STDOUT		267
 
 static struct option opts[] = {
 	{"buffer-type", 1, 0, 'B'},
@@ -1677,6 +1695,7 @@ static struct option opts[] = {
 	{"field", 1, 0, OPT_FIELD},
 	{"file", 2, 0, 'F'},
 	{"fill-frames", 0, 0, 'I'},
+	{"stdout", 0, 0, OPT_STDOUT},
 	{"format", 1, 0, 'f'},
 	{"help", 0, 0, 'h'},
 	{"input", 1, 0, 'i'},
@@ -1717,7 +1736,8 @@ int main(int argc, char *argv[])
 	int do_list_controls = 0, do_get_control = 0, do_set_control = 0;
 	int do_sleep_forever = 0, do_requeue_last = 0;
 	int do_rt = 0;
-	int no_query = 0;
+	int no_query = 0; 
+	int do_stdout = 0;
 	char *endptr;
 	int c;
 
@@ -1755,7 +1775,7 @@ int main(int argc, char *argv[])
 		case 'B':
 			ret = v4l2_buf_type_from_string(optarg);
 			if (ret == -1) {
-				printf("Bad buffer type \"%s\"\n", optarg);
+				fprintf(stderr, "Bad buffer type \"%s\"\n", optarg);
 				return 1;
 			}
 			video_set_buf_type(&dev, ret);
@@ -1775,7 +1795,7 @@ int main(int argc, char *argv[])
 			do_set_format = 1;
 			info = v4l2_format_by_name(optarg);
 			if (info == NULL) {
-				printf("Unsupported video format '%s'\n", optarg);
+				fprintf(stderr, "Unsupported video format '%s'\n", optarg);
 				return 1;
 			}
 			pixelformat = info->fourcc;
@@ -1812,7 +1832,7 @@ int main(int argc, char *argv[])
 		case 'r':
 			ctrl_name = strtol(optarg, &endptr, 0);
 			if (*endptr != 0) {
-				printf("Invalid control name '%s'\n", optarg);
+				fprintf(stderr, "Invalid control name '%s'\n", optarg);
 				return 1;
 			}
 			do_get_control = 1;
@@ -1826,12 +1846,12 @@ int main(int argc, char *argv[])
 			do_set_format = 1;
 			width = strtol(optarg, &endptr, 10);
 			if (*endptr != 'x' || endptr == optarg) {
-				printf("Invalid size '%s'\n", optarg);
+				fprintf(stderr, "Invalid size '%s'\n", optarg);
 				return 1;
 			}
 			height = strtol(endptr + 1, &endptr, 10);
 			if (*endptr != 0) {
-				printf("Invalid size '%s'\n", optarg);
+				fprintf(stderr, "Invalid size '%s'\n", optarg);
 				return 1;
 			}
 			break;
@@ -1839,12 +1859,12 @@ int main(int argc, char *argv[])
 			do_set_time_per_frame = 1;
 			time_per_frame.numerator = strtol(optarg, &endptr, 10);
 			if (*endptr != '/' || endptr == optarg) {
-				printf("Invalid time per frame '%s'\n", optarg);
+				fprintf(stderr, "Invalid time per frame '%s'\n", optarg);
 				return 1;
 			}
 			time_per_frame.denominator = strtol(endptr + 1, &endptr, 10);
 			if (*endptr != 0) {
-				printf("Invalid time per frame '%s'\n", optarg);
+				fprintf(stderr, "Invalid time per frame '%s'\n", optarg);
 				return 1;
 			}
 			break;
@@ -1854,12 +1874,12 @@ int main(int argc, char *argv[])
 		case 'w':
 			ctrl_name = strtol(optarg, &endptr, 0);
 			if (*endptr != ' ' || endptr == optarg) {
-				printf("Invalid control name '%s'\n", optarg);
+				fprintf(stderr, "Invalid control name '%s'\n", optarg);
 				return 1;
 			}
 			ctrl_value = strtol(endptr + 1, &endptr, 0);
 			if (*endptr != 0) {
-				printf("Invalid control value '%s'\n", optarg);
+				fprintf(stderr, "Invalid control value '%s'\n", optarg);
 				return 1;
 			}
 			do_set_control = 1;
@@ -1873,16 +1893,16 @@ int main(int argc, char *argv[])
 		case OPT_FD:
 			ret = atoi(optarg);
 			if (ret < 0) {
-				printf("Bad file descriptor %d\n", ret);
+				fprintf(stderr, "Bad file descriptor %d\n", ret);
 				return 1;
 			}
-			printf("Using file descriptor %d\n", ret);
+			fprintf(stderr, "Using file descriptor %d\n", ret);
 			video_set_fd(&dev, ret);
 			break;
 		case OPT_FIELD:
 			field = v4l2_field_from_string(optarg);
 			if (field == (enum v4l2_field)-1) {
-				printf("Invalid field order '%s'\n", optarg);
+				fprintf(stderr, "Invalid field order '%s'\n", optarg);
 				return 1;
 			}
 			break;
@@ -1907,22 +1927,25 @@ int main(int argc, char *argv[])
 			} else if (!strcmp(optarg, "soe")) {
 				dev.buffer_output_flags |= V4L2_BUF_FLAG_TSTAMP_SRC_SOE;
 			} else {
-				printf("Invalid timestamp source %s\n", optarg);
+				fprintf(stderr, "Invalid timestamp source %s\n", optarg);
 				return 1;
 			}
 			break;
 		case OPT_USERPTR_OFFSET:
 			userptr_offset = atoi(optarg);
 			break;
+		case OPT_STDOUT:
+			do_stdout = 1;
+			break;
 		default:
-			printf("Invalid option -%c\n", c);
-			printf("Run %s -h for help.\n", argv[0]);
+			fprintf(stderr, "Invalid option -%c\n", c);
+			fprintf(stderr, "Run %s -h for help.\n", argv[0]);
 			return 1;
 		}
 	}
 
 	if ((fill_mode & BUFFER_FILL_PADDING) && memtype != V4L2_MEMORY_USERPTR) {
-		printf("Buffer overrun can only be checked in USERPTR mode.\n");
+		fprintf(stderr, "Buffer overrun can only be checked in USERPTR mode.\n");
 		return 1;
 	}
 
@@ -1959,7 +1982,7 @@ int main(int argc, char *argv[])
 		ret = get_control(&dev, ctrl_name,
 				  get_control_type(&dev, ctrl_name), &val);
 		if (ret >= 0)
-			printf("Control 0x%08x value %" PRId64 "\n", ctrl_name, val);
+			fprintf(stderr, "Control 0x%08x value %" PRId64 "\n", ctrl_name, val);
 	}
 
 	if (do_set_control)
@@ -1970,7 +1993,7 @@ int main(int argc, char *argv[])
 		video_list_controls(&dev);
 
 	if (do_enum_formats) {
-		printf("- Available formats:\n");
+		fprintf(stderr, "- Available formats:\n");
 		video_enum_formats(&dev, V4L2_BUF_TYPE_VIDEO_CAPTURE);
 		video_enum_formats(&dev, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
 		video_enum_formats(&dev, V4L2_BUF_TYPE_VIDEO_OUTPUT);
@@ -1979,14 +2002,14 @@ int main(int argc, char *argv[])
 	}
 
 	if (do_enum_inputs) {
-		printf("- Available inputs:\n");
+		fprintf(stderr, "- Available inputs:\n");
 		video_enum_inputs(&dev);
 	}
 
 	if (do_set_input) {
 		video_set_input(&dev, input);
 		ret = video_get_input(&dev);
-		printf("Input %d selected\n", ret);
+		fprintf(stderr, "Input %d selected\n", ret);
 	}
 
 	/* Set the video format. */
@@ -2028,7 +2051,7 @@ int main(int argc, char *argv[])
 	}
 
 	if (do_pause) {
-		printf("Press enter to start capture\n");
+		fprintf(stderr, "Press enter to start capture\n");
 		getchar();
 	}
 
@@ -2037,12 +2060,12 @@ int main(int argc, char *argv[])
 		sched.sched_priority = rt_priority;
 		ret = sched_setscheduler(0, SCHED_RR, &sched);
 		if (ret < 0)
-			printf("Failed to select RR scheduler: %s (%d)\n",
+			fprintf(stderr, "Failed to select RR scheduler: %s (%d)\n",
 				strerror(errno), errno);
 	}
 
 	if (video_do_capture(&dev, nframes, skip, delay, filename,
-			     do_requeue_last, fill_mode) < 0) {
+			     do_requeue_last, fill_mode, do_stdout) < 0) {
 		video_close(&dev);
 		return 1;
 	}
-- 
1.7.9.5