KEMBAR78
C# - How Can I Embed Icon and Video Stream - Stack Overflow | PDF | Icon (Computing) | Computer File
0% found this document useful (0 votes)
127 views3 pages

C# - How Can I Embed Icon and Video Stream - Stack Overflow

The document discusses embedding an icon or bitmap into an mp4 or mpeg video file. It provides a code example using C++ and OpenCV to accomplish this: 1. The code decodes the input video file frame-by-frame. 2. For each frame, it processes the frame to add the icon/image in the top-left corner. 3. It re-encodes the modified frame and saves it to a new output video file. The code provided shows how to open the input video, read each frame, resize and add the input image to the corner of the frame, write it out to a new video file, and display the output. This allows embedding an icon

Uploaded by

anas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views3 pages

C# - How Can I Embed Icon and Video Stream - Stack Overflow

The document discusses embedding an icon or bitmap into an mp4 or mpeg video file. It provides a code example using C++ and OpenCV to accomplish this: 1. The code decodes the input video file frame-by-frame. 2. For each frame, it processes the frame to add the icon/image in the top-left corner. 3. It re-encodes the modified frame and saves it to a new output video file. The code provided shows how to open the input video, read each frame, resize and add the input image to the corner of the frame, write it out to a new video file, and display the output. This allows embedding an icon

Uploaded by

anas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

6/21/2017 c#HowcaniembediconandvideostreamStackOverflow

xDismiss

JointheStackOverflowCommunity

Stack Overflow is a community of 7.3 million


programmers, just like you, helping each other.
Join them it only takes a minute:

Signup

Howcaniembediconandvideostream

Ihavesomemp4videofileandiwanttosetinthisvideofilesomesmallicon(canbesimplebitmap).

Iwanttowritesomeapplicationthattheinputismp4/mpegfileandsomeiconorbitmapandtheoutputisthesamemp4withthisiconembed
intheleftcorner.

Howtodoit?Istheresomecodeexampleforthis?

c# c++ video videostreaming videocapture

editedMar13'14at21:13 askedMar13'14at13:16
129followers,1.7kquestions rss
Yanshof
Questionsrelatedtocomputerorientedvideocaptureandthe 3,745 10 50 116
programmingtoolsandsolutionsfordealingwithcapturedframes
fromavideo.
Well,almostalliconsarebasedonfiletype.TheonlyexceptionIcanrememberareexecutables,onwhich
frequent info topusers
theiconisjustaresourceallocatedinsidethepackage.msdn.microsoft.com/en
us/library/ms648004%28v=VS.85%29.aspx orezvaniMar25'14at5:56

Ifyoudon'thavetodothisinaprogramofyourownthereisaninstructableshowinghowtoembedalogo
intoyourvideousingwindowsmoviemaker:instructables.com/id/andypMar26'14at19:44

butineedtodoitinmyownprogram. Yanshof Mar27'14at5:17

1Answer

Youcanusealotoflibrariestoaccomplishsuchathing,IwillshowyouawaytodoitusingC++
andOpenCV.

Youbasicallyneedtodothreethings:

1.Youneedtodecodetheinputvideofile
2.Youneedtoprocesseachframeinordertoaddyouricon/imageinitscorner
3.Youneedtoreencodethemodifiedframe,andsaveitintoanewvideofile

OpenCVisalibrarythatspecializesinimageprocessing.Itcanhelpyouaccomplishtask#2.It
alsohassomefunctionalitythatallowsyoutoreadandwritevideofiles,butit'snotasadvanced
asotherlibrariesthatspecializeinencoding/decodingvideofiles(likeffmpeg).

IhavecreatedasamplethatusesOpenCVtoreadavideofile(wmv),andaddtoeachframean
imagefile(jpg).Theresultwillbeanothervideofile(avi).OpenCVcanalsoreadothertypesof
videofiles(mp4),butIcouldn'tgetittosavean.mp4file,Icouldonlymakeitsavean.avifile.

InordertousemysampleyouneedtosetupOpenCVinyourplatformandIDEofchoice.You
canfindinformationabouthowtodothisontheOpenCVwebsite.

InmysampleIusetheMJPEGencodertosavethevideofile.Ifyoureplace
CV_FOURCC('M','J','P','G') with 1 awindowwillpopupthatwillaskyouwhatencoderyou
wanttouse.Ifyouwanttouseanotherencoder,justput 1 inthere.

HereisthecodethatIused:

#include<opencv2/opencv.hpp>

usingnamespacestd;
usingnamespacecv;

https://stackoverflow.com/questions/22379852/howcaniembediconandvideostream 1/3
6/21/2017 c#HowcaniembediconandvideostreamStackOverflow

voidaddImageInCorner(MatvideoFrame,MatresizedImage)
{
//Thedestinationlocationoftheimageintheframe(upperleftcorner)
RectdestinationRect(0,0,resizedImage.cols,resizedImage.rows);
//Copytheimagetothespecifiedlocationintheframe
resizedImage.copyTo(videoFrame(destinationRect));
}

voidmain()
{
stringinputVideoFile="C:\\Users\\Public\\Videos\\SampleVideos\\Wildlife.wmv";
stringinputImageFile="C:\\Users\\Public\\Pictures\\SamplePictures\\Koala.jpg";
stringoutputVideoFile="C:\\Users\\Public\\Videos\\SampleVideos\\output.avi";

//Readimagefile
Matimage=imread(inputImageFile);
MatresizedImage;
resize(image,resizedImage,Size(400,300));

//Openvideocapture
VideoCapturecapture;
capture.open(inputVideoFile);

if(!capture.isOpened())
{
return;
}

//Getthecaptureproperties
doublefps=capture.get(CV_CAP_PROP_FPS);
intvideoWidth=capture.get(CV_CAP_PROP_FRAME_WIDTH);
intvideoHeight=capture.get(CV_CAP_PROP_FRAME_HEIGHT);

//Initializethevideowriter
VideoWriterwriter;
writer.open(outputVideoFile,CV_FOURCC('M','J','P','G'),fps,Size(videoWidth,
videoHeight));

MatcurrentFrame;
namedWindow("video");

//Whilethewindowisstillopen
while(cvGetWindowHandle("video")!=NULL)
{
//Readthenextframe
capture>>currentFrame;

if(currentFrame.empty())
{
//Iftheframecouldnotberead,exittheloop
break;
}

//Addtheimagetothecornerofthevideoframe
addImageInCorner(currentFrame,resizedImage);

writer<<currentFrame;

//Showtheimageinthevideowindow
imshow("video",currentFrame);
waitKey(10);
}

writer.release();
}

Hereistheresultingimage:

Ihopethishelpsyou.

editedMar27'14at13:49 answeredMar27'14at13:42
Ove
4,227 1 24 54

https://stackoverflow.com/questions/22379852/howcaniembediconandvideostream 2/3
6/21/2017 c#HowcaniembediconandvideostreamStackOverflow

https://stackoverflow.com/questions/22379852/howcaniembediconandvideostream 3/3

You might also like