<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Md Morshedul Islam</title>
    <description>The latest articles on DEV Community by Md Morshedul Islam (@riaadmorshed).</description>
    <link>https://dev.to/riaadmorshed</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1257703%2F9c00849d-8d7b-4aa6-801d-c9cefd8f538b.png</url>
      <title>DEV Community: Md Morshedul Islam</title>
      <link>https://dev.to/riaadmorshed</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/riaadmorshed"/>
    <language>en</language>
    <item>
      <title>Adding a Single Audio to Multiple Videos using Python and MoviePy</title>
      <dc:creator>Md Morshedul Islam</dc:creator>
      <pubDate>Wed, 24 Jan 2024 11:34:41 +0000</pubDate>
      <link>https://dev.to/riaadmorshed/adding-a-single-audio-to-multiple-videos-using-python-and-moviepy-3c1i</link>
      <guid>https://dev.to/riaadmorshed/adding-a-single-audio-to-multiple-videos-using-python-and-moviepy-3c1i</guid>
      <description>&lt;p&gt;&lt;a href="https://zulko.github.io/moviepy/"&gt;MoviePy&lt;/a&gt; is a Python module used for video editing. You can automate many video editing tasks using this library. In this blog, we will explore how to add sound to silent(or noisy) video(s).&lt;br&gt;
Make sure you have Python installed, and install the &lt;code&gt;moviepy&lt;/code&gt; library using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;moviepy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Scenario: We have a folder with multiple videos and an audio track to add to all of these videos. If the video length is greater than audio the the audio will loop otherwise trim. We will save the output to another folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading videos and audio track
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;video_files&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;video_folder_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;endswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;.mp4&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="n"&gt;audio_clip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AudioFileClip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;audio_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Process each video
&lt;/h2&gt;

&lt;p&gt;Loop over videos and do the following for each video:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Get the absolute path of the video and define the absolute path of the output video.&lt;/li&gt;
&lt;li&gt;Load the clip to the program using the &lt;code&gt;moviepy&lt;/code&gt; module.&lt;/li&gt;
&lt;li&gt;Check if the video length is greater than the video length then clip the audio otherwise loop the audio to fit in the video length.&lt;/li&gt;
&lt;li&gt;Save and Close the video. Done!
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;video_file&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;video_files&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# Specify the paths for the current video and output video
&lt;/span&gt;        &lt;span class="n"&gt;video_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;video_folder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;video_file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;output_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output_folder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;video_file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# Load the video clip
&lt;/span&gt;        &lt;span class="n"&gt;video_clip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;VideoFileClip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;video_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# Trim or loop the audio to match the duration of the video
&lt;/span&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;audio_clip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;duration&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;video_clip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="c1"&gt;# Trim the audio to match the duration of the video
&lt;/span&gt;            &lt;span class="n"&gt;audio_clip_processed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;audio_clip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subclip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;video_clip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="c1"&gt;# Loop the audio to cover the entire video duration
&lt;/span&gt;            &lt;span class="n"&gt;audio_clip_processed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;audio_clip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;volumex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;video_clip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;duration&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;audio_clip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;duration&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# Set the video clip's audio to be the modified audio
&lt;/span&gt;        &lt;span class="n"&gt;video_clip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;video_clip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_audio&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;audio_clip_processed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# Write the final video with audio using different codec options
&lt;/span&gt;        &lt;span class="n"&gt;video_clip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write_videofile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;codec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;libx264&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;audio_codec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;aac&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# Close the current video clip
&lt;/span&gt;        &lt;span class="n"&gt;video_clip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;audio_clip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! Adding sound to your videos is now just a few lines of Python code away. Happy coding!&lt;/p&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>Excel Generation in C# using NPOI Library</title>
      <dc:creator>Md Morshedul Islam</dc:creator>
      <pubDate>Tue, 16 Jan 2024 11:46:19 +0000</pubDate>
      <link>https://dev.to/riaadmorshed/excel-generation-in-c-using-npoi-library-2jmd</link>
      <guid>https://dev.to/riaadmorshed/excel-generation-in-c-using-npoi-library-2jmd</guid>
      <description>&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/nissl-lab/npoi" rel="noopener noreferrer"&gt;NPOI&lt;/a&gt; is a popular package for reading and manipulating Excel in C#. To get started with &lt;a href="https://github.com/nissl-lab/npoi" rel="noopener noreferrer"&gt;NPOI&lt;/a&gt;, you need to install the &lt;a href="https://www.nuget.org/packages/NPOI/#readme-body-tab" rel="noopener noreferrer"&gt;NPOI NuGet package&lt;/a&gt; into your project. You can do this using the NuGet Package Manager Console by &lt;code&gt;dotnet add package NPOI&lt;/code&gt; or Visual Studio's NuGet Package Manager.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Usage
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create a new workbook&lt;/li&gt;
&lt;li&gt;Add sheets to the workbook&lt;/li&gt;
&lt;li&gt;Populate cells with data&lt;/li&gt;
&lt;li&gt;Add formula&lt;/li&gt;
&lt;li&gt;Merge Cells&lt;/li&gt;
&lt;li&gt;Formatting and styling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Note: Accessing cells is similar to accessing a 2D array.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System;
using System.IO;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;

class Program
{
    static void Main()
    {
        // Create a new workbook and sheet
        IWorkbook workbook = new XSSFWorkbook();
        ISheet sheet = workbook.CreateSheet("Sheet 1");

        IRow row = sheet.CreateRow(0);
        ICell cell = row.CreateCell(0);
        cell.SetCellValue("List of employee");

        // lets make a simple table with header
        IRow headers = sheet.CreateRow(1);
        ICell header_id_cell = headers.CreateCell(0);
        ICell header_name_cell = headers.CreateCell(1);

        // assign value to header cell
        header_id_cell.SetCellValue("ID");
        header_name_cell.SetCellValue("Name");

        // add background color to header
        ICellStyle headerStyle = workbook.CreateCellStyle();
        headerStyle.FillForegroundColor = IndexedColors.LightYellow.Index;
        headerStyle.FillPattern = FillPattern.SolidForeground;

        header_id_cell.CellStyle = headerStyle;
        header_name_cell.CellStyle = headerStyle;


        // Create some data
        for (int i = 2; i &amp;lt; 10; i++)
        {
            row = sheet.CreateRow(i);
            row.CreateCell(0).SetCellValue(i - 1);
            row.CreateCell(1).SetCellValue($"Name {i - 1}");
        }

        // Save the workbook to a file
        string filePath = "Output.xlsx";
        using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
        {
            workbook.Write(fileStream);
        }

        Console.WriteLine($"Excel file created at: {Path.GetFullPath(filePath)}");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can do lots of things with this package. Here are some examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lock specific cell
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Protect the sheet
sheet.ProtectSheet("password");
//Pass the cell you want to make read-only
static void SetCellReadOnly(ICell cell)
{
    // Create a new style with the "locked" property set to true
    ICellStyle style = cell.Sheet.Workbook.CreateCellStyle();
    style.IsLocked = true;

    // Apply the style to the cell
    cell.CellStyle = style;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Merge Cell
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static void MergeCells(ISheet sheet, int firstRow, int lastRow, int firstCol, int lastCol)
{
    sheet.AddMergedRegion(new CellRangeAddress(firstRow, lastRow, firstCol, lastCol));
}
// example:
// Merge cells A1 to D1
MergeCells(sheet, 0, 0, 0, 3);
// Merge cells B2 to D5
MergeCells(sheet, 1, 4, 1, 3);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add Formula
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static void AddFormulaToCell(ICell cell, string formula)
{
    cell.CellFormula = formula;
}
// Example formula: Sum of values in cells B3 to B9
AddFormulaToCell(totalCell, "SUM(B3:B9)");
For using the formula into another sheet: `"Sheet1!A2+Sheet1!A3";`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Auto size row and column
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static void SetAutosize (ISheet sheet, int colNo)
{
    sheet.AutoSizeColumn(colNo);  // for row: AutosizeRow(rowNo)
}
// example :
SetAutosize(sheet, 0) // this  will auto size first col

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Read Existing Excel
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Load the existing workbook
string existingFilePath = "plan.xlsx";
using (FileStream existingFileStream = new FileStream(existingFilePath, FileMode.Open, FileAccess.Read))
{
    IWorkbook workbook = new XSSFWorkbook(existingFileStream);

    // Create a new sheet named "erosNext"
    ISheet erosNextSheet = workbook.CreateSheet("erosNext");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hope this blog will help you. For more examples refer to this &lt;a href="https://github.com/nissl-lab/npoi-examples/tree/main" rel="noopener noreferrer"&gt;github repository&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>npoi</category>
      <category>csharp</category>
    </item>
  </channel>
</rss>
