[Arduino-IDE] Seeed Studio XIAO ESP32S3 Sense 기본 예제 및 에러 조치

프로그래밍/C, C++|2024. 11. 1. 18:48
반응형

Seeed Studio XIAO ESP32S3 Sense는 카메라(OV2640)와 디지털 마이크가 내장된 ESP32-S3 기반 개발 보드로, Wi-Fi를 통해 영상 스트리밍이 가능합니다.

아래에서는 HamoniKR 7 환경에서 작성하였습니다.

 

 

1. Arduino IDE 기본 세팅

 

Arduino IDE 실행 > 파일 > 기본 설정 > (중간) Language 에 한국어 선택 후 [확인]을 누릅니다.

 

Arduino IDE 실행 > 파일 > 기본 설정 > (맨아래) 추가 보드 관리자 URL 에 아래 내용입력 후 [확인]을 누릅니다.

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

 

Arduino IDE 실행 > 도구 > 보드 > 보드매니저 실행해서 아래 두개를 설치합니다.

- Arduino ESP32 Boards

- esp32

 

Arduino IDE 실행 > 도구 > 보드 > esp32 > 아래로 한참 내려서 XIAO_ESP32S3를 선택합니다.

 

USB 에 기기 연결 후, 상단 셀렉트 옵션에서 해당 보드를 선택합니다.

 

 

2. 시리얼 포트 접근 권한 추가

 

리눅스 시스템에서 시리얼 포트에 대한 접근 권한을 주어야 합니다.

권한이 없을 경우, 아래와 같은 에러 메세지가 출력됩니다.

[Errno 13] could not open port /dev/ttyACM0: [Errno 13] Permission denied: '/dev/ttyACM0'

 

다음과 같이 사용자를 dialout 그룹에 추가합니다.

$ sudo usermod -a -G dialout $USER

 

시리얼 포트에 직접 권한을 부여 합니다.

$ sudo chmod 666 /dev/ttyACM0

 

두번째 명령은 임시적인 해결책으로, 재부팅 후에는 다시 권한을 설정해야 합니다.

 

 

3. 예제 입력 및 컴파일

 

Arduino IDE에는 여러가지 예제가 준비되어 있습니다.

ESP32S3 카메라를 올바르게 사용하기 위해 기본 제공되는 예제를 사용해 봅니다.

 

Arduino IDE 실행 > 파일 > 예제 > ESP32 > Camera > CameraWebServer를 선택합니다.

 

열려진 예제 코드에서 아래 두군데를 수정합니다.

 

1) 카메라 모델 변경

기본 카메라 모델 #define CAMERA_MODEL_ESP_EYE 앞에 슬래시 두개(//) 를 입력해 주석 처리하고,

#define CAMERA_MODEL_XIAO_ESP32S3을 주석 해제 합니다. (사용 한다는 뜻)

 

2) WiFi 설정 변경

연결 가능한 Wifi의 SSID값과 패스워드를 정확히 입력합니다.
const char* ssid = "CDH";                   // Wi-Fi SSID
const char* password = "12345678";  // Wi-Fi 비밀번호

 

그리고 메뉴 : 파일 > 도구 > PSRAM: disabled 를 "OPI PSRAM"으로 변경합니다.


업로드를 실행 합니다. (오른쪽 화살표 버튼)

 

아래와 같은 결과가 출력되면 성공한 것입니다.

 

[출력]

스케치는 프로그램 저장 공간 990114 바이트(29%)를 사용. 최대 3342336 바이트.
전역 변수는 동적 메모리 62996바이트(19%)를 사용, 264684바이트의 지역변수가 남음.  최대는 327680 바이트.
...

(생략)

...
riting at 0x000f8f09... (97 %)
Writing at 0x000fef8b... (100 %)
Wrote 990256 bytes (646409 compressed) at 0x00010000 in 6.7 seconds (effective 1174.6 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting with RTC WDT...

 

 

4. 실시간 영상 확인

 

Wifi 또는 핫스팟 기기에서 할당받은 ESP32S3 sense 웹서버IP 주소를 확인을 위해 '시리얼 모니터 (메뉴 > 도구 > 시리얼모니터)' 를 열면 되는데,

/dev/ttyACM0 에 연결할 수 없다고 할 것입니다.

(업로드 하면 자동으로 기기가 동작되어 업로드 상태가 해제됩니다)

 

그래서, 이상태 그대로 위 '2번' 항목의 명령을 다시 실행하면, 시리얼 모니터에 기기 IP 주소가 출력됩니다.

$ sudo usermod -a -G dialout $USER

$ sudo chmod 666 /dev/ttyACM0

 

그 주소로 접속하여 실시간 영상을 확인할 수 있습니다.

 

 

5. 참고 : 에러 모음

 

[ 에러 ]

/dev/ttyACM0 가 보였다 안보였다 하는 증상은 Arduino IDE 에서 포트가 보였다 안보였다 하는 증상과 같습니다.

이는 업로드를 이미 했거나, 하는중 오류가 발생하였거나 기타 등등의 문제로 인해 생기는데,

해결책은 아래와 같습니다.

 

[ 해결 ]

데이터 케이블과 ESP32S3 Sense (기기) 와 분리합니다.

C-Type 머리가 보이게, 그리고 위로 올린 방향으로 두면 C-Type 오른쪽으로 보이는 버튼이 BOOT 버튼입니다.

BOOT 버튼을 누른채 데이터 케이블을 연결하면 불이 깜빡이며, 멈추었을때 손을 떼면 초기화 됩니다.

초기화 된 상태에서 다시 케이블을 분리하면 원래대로 돌아갑니다.

그러므로 연결된 상태 그대로 소스코드를 수정하고 업로드 해야 합니다.

 

※ BootLoader 모드란?
- 공장 초기화가 아닌, 새로운 펌웨어를 강제로 업로드할 수 있도록 하는 모드 

- 기존의 프로그램이 손상되었거나 업로드가 실패할 때, 이 모드를 통해 새로운 펌웨어를 강제로 설치 가능 

- 일반적인 운영 중에는 사용되지 않으며, 포트 인식 오류나 업로드 문제 해결 시 사용

 

[ 에러 ]

업로드시 아래와 같은 에러메세지가 출력된다면, 현재 사용자에게 장치 접근 권한을 추가해야 합니다.

 

스케치는 프로그램 저장 공간 1000446 바이트(76%)를 사용. 최대 1310720 바이트. 전역 변수는 동적 메모리 62908바이트(19%)를 사용, 264772바이트의 지역변수가 남음. 최대는 327680 바이트. esptool.py v4.8.1 Serial port /dev/ttyACM0 A fatal error occurred: Could not open /dev/ttyACM0, the port is busy or doesn't exist. ([Errno 13] could not open port /dev/ttyACM0: [Errno 13] Permission denied: '/dev/ttyACM0') Hint: Try to add user into dialout or uucp group. Failed uploading: uploading error: exit status 2

 

[ 해결 ]

# sudo usermod -a -G dialout $USER

그런 다음 로그아웃, 로그인없이 적용하기 위해서 현재 터미널에서 새 그룹 권한을 바로 적용합니다.

# newgrp dialout

 

이제 android-ide 를 실행하면  /dev/ttyACM0 장치에 대한 접근권한이 생깁니다.

 

반응형

댓글()

빈글

리눅스/OS 일반|2024. 11. 1. 18:48
반응형
반응형

댓글()

Notification 알림으로 인한 Activity 중복 호출 방지

반응형

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Activity 중복 생성 방지
        if (!isTaskRoot) {
            finish()
            return
        }

}

 

반응형

댓글()

[Android Kotlin] 포그라운드 서비스 (Foreground Service)

반응형

[출처] https://iamjm29.tistory.com/13

 

자세한 설명은 출처를 확인하도록 합니다.

 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
http://schemas.android.com/apk/res/android"</linearlayout xmlns:android="
    xmlns:app="
http://schemas.android.com/apk/res-auto"
    xmlns:tools="
http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    tools:context=".MainActivity">

    <Button
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:text="Start Service"
        android:id="@+id/btn_start"/>

    <Button
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:text="Stop Service"
        android:id="@+id/btn_stop"/>

</LinearLayout>

 

 

AndroidManifest.xml

아래 전체를 복사하지 말고, 색칠한 곳만 참고하도록 합니다.

생성된 패키지명이 다르면 테마 이름도 다르기 때문입니다.

<?xml version="1.0" encoding="utf-8"?>
http://schemas.android.com/apk/res/android"</manifest xmlns:android="
    xmlns:tools="
http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Test"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service
            android:name=".MyService"
            android:enabled="true"
            android:exported="true" />

    </application>

</manifest>

 

 

MainActivity.kt

package kr.sysdocu.test

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    //Button
    var btn_start: Button? = null
    var btn_stop: Button? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        btn_start = findViewById(R.id.btn_start)
        btn_stop = findViewById(R.id.btn_stop)

        btn_start!!.setOnClickListener(View.OnClickListener {
            val serviceIntent = Intent(this@MainActivity, MyService::class.java)
            startService(serviceIntent)
            Toast.makeText(this@MainActivity, "Service start", Toast.LENGTH_SHORT).show()
        })

        btn_stop!!.setOnClickListener(View.OnClickListener {
            val serviceIntent = Intent(this@MainActivity, MyService::class.java)
            stopService(serviceIntent)
            Toast.makeText(this@MainActivity, "Service stop", Toast.LENGTH_SHORT).show()
        })
    }
}

 


MyService.kt

package kr.sysdocu.test

import android.app.*
import android.content.Intent
import android.graphics.Color
import android.os.Build
import android.os.IBinder
import android.util.Log
import androidx.core.app.NotificationCompat

class MyService : Service() {
    private var mThread: Thread? = null

    companion object {
        private const val TAG = "MyService"
        private const val NOTI_ID = 1
    }

    private fun createNotification() {
        val builder = NotificationCompat.Builder(this, "default")
        builder.setSmallIcon(R.mipmap.ic_launcher)
        builder.setContentTitle("Foreground Service")
        builder.setContentText("포그라운드 서비스")
        builder.color = Color.RED

        val notificationIntent = Intent(this, MainActivity::class.java)
        notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
        val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE)
        builder.setContentIntent(pendingIntent) // 알림 클릭 시 이동

        val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            notificationManager.createNotificationChannel(
                NotificationChannel(
                    "default",
                    "기본 채널",
                    NotificationManager.IMPORTANCE_DEFAULT
                )
            )
        }
        val notification = builder.build()
        startForeground(NOTI_ID, notification)
    }

    override fun onCreate() {
        super.onCreate()
        createNotification()
        mThread = object : Thread("My Thread") {
            override fun run() {
                super.run()
                for (i in 0..99) {
                    Log.d(TAG, "count : $i")
                    try {
                        sleep(1000)
                    } catch (e: InterruptedException) {
                        currentThread().interrupt()
                        break
                    }
                }
            }
        }
        mThread!!.start()
        Log.d(TAG, "onCreate")
    }

    override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
        Log.d(TAG, "onStartCommand")
        return START_NOT_STICKY
    }

    override fun onDestroy() {
        super.onDestroy()
        if (mThread != null) {
            mThread!!.interrupt()
            mThread = null
        }
        Log.d(TAG, "onDestroy")
    }

    override fun onBind(intent: Intent?): IBinder? {
        return null
    }
}

 

 

 

 

반응형

댓글()

AndroidStudio 에서 JAVA 로 GPS 현재 위치 확인하기

프로그래밍/Android (Java)|2024. 11. 1. 18:47
반응형

[출처] https://mainia.tistory.com/1153

출처에서 activity_main.xml 파일 내용만 추가하여 테스트하였고 정상 동작 확인하였습니다.

 

 

1. AndroidManifest.xml

...
    </uses-permission android:name="android.permission.internet" >
    </uses-permission android:name="android.permission.access_fine_location" >
    </uses-permission android:name="android.permission.access_coarse_location">
...

 

 

2. MainActivity.java

package kr.sysdocu.position;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

/** GPS 샘플 */
public class MainActivity extends Activity {

    private Button btnShowLocation;
    private TextView txtLat;
    private TextView txtLon;
    private final int PERMISSIONS_ACCESS_FINE_LOCATION = 1000;
    private final int PERMISSIONS_ACCESS_COARSE_LOCATION = 1001;
    private boolean isAccessFineLocation = false;
    private boolean isAccessCoarseLocation = false;
    private boolean isPermission = false;

    // GPSTracker class
    private GpsInfo gps;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnShowLocation = (Button) findViewById(R.id.btn_start);
        txtLat = (TextView) findViewById(R.id.tv_latitude);
        txtLon = (TextView) findViewById(R.id.tv_longitude);

        // GPS 정보를 보여주기 위한 이벤트 클래스 등록
        btnShowLocation.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                // 권한 요청을 해야 함
                if (!isPermission) {
                    callPermission();
                    return;
                }

                gps = new GpsInfo(MainActivity.this);
                // GPS 사용유무 가져오기
                if (gps.isGetLocation()) {

                    double latitude = gps.getLatitude();
                    double longitude = gps.getLongitude();

                    txtLat.setText(String.valueOf(latitude));
                    txtLon.setText(String.valueOf(longitude));

                    Toast.makeText(
                            getApplicationContext(),
                            "당신의 위치 - \n위도: " + latitude + "\n경도: " + longitude,
                            Toast.LENGTH_LONG).show();
                } else {
                    // GPS 를 사용할수 없으므로
                    gps.showSettingsAlert();
                }
            }
        });

        callPermission();  // 권한 요청을 해야 함
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions,
                                           int[] grantResults) {
        if (requestCode == PERMISSIONS_ACCESS_FINE_LOCATION
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            isAccessFineLocation = true;

        } else if (requestCode == PERMISSIONS_ACCESS_COARSE_LOCATION
                && grantResults[0] == PackageManager.PERMISSION_GRANTED){

            isAccessCoarseLocation = true;
        }

        if (isAccessFineLocation && isAccessCoarseLocation) {
            isPermission = true;
        }
    }

    // 전화번호 권한 요청
    private void callPermission() {
        // Check the SDK version and whether the permission is already granted or not.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
                && checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
                != PackageManager.PERMISSION_GRANTED) {

            requestPermissions(
                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                    PERMISSIONS_ACCESS_FINE_LOCATION);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
                && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
                != PackageManager.PERMISSION_GRANTED){

            requestPermissions(
                    new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
                    PERMISSIONS_ACCESS_COARSE_LOCATION);
        } else {
            isPermission = true;
        }
    }
}

 

 

3. activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp">

    <!-- 시작 버튼 -->
    <Button
        android:id="@+id/btn_start"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="위치 가져오기" />

    <!-- 위도 표시 -->
    <TextView
        android:id="@+id/tv_latitude"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="위도: "
        android:textSize="18sp"
        android:paddingTop="20dp" />

    <!-- 경도 표시 -->
    <TextView
        android:id="@+id/tv_longitude"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="경도: "
        android:textSize="18sp"
        android:paddingTop="10dp" />

</LinearLayout>

 

 

4. GpsInfo.java

package kr.sysdocu.test;

import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import androidx.core.content.ContextCompat;

public class GpsInfo extends Service implements LocationListener {

    private final Context mContext;

    // 현재 GPS 사용유무
    boolean isGPSEnabled = false;

    // 네트워크 사용유무
    boolean isNetworkEnabled = false;

    // GPS 상태값
    boolean isGetLocation = false;

    Location location;
    double lat; // 위도
    double lon; // 경도

    // 최소 GPS 정보 업데이트 거리 10미터
    private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10;

    // 최소 GPS 정보 업데이트 시간 밀리세컨이므로 1분
    private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1;

    protected LocationManager locationManager;

    public GpsInfo(Context context) {
        this.mContext = context;
        getLocation();
    }

    @TargetApi(23)
    public Location getLocation() {
        if ( Build.VERSION.SDK_INT >= 23 &&
                ContextCompat.checkSelfPermission(
                        mContext, android.Manifest.permission.ACCESS_FINE_LOCATION )
                        != PackageManager.PERMISSION_GRANTED &&
                ContextCompat.checkSelfPermission(
                        mContext, android.Manifest.permission.ACCESS_COARSE_LOCATION)
                        != PackageManager.PERMISSION_GRANTED) {

            return null;
        }

        try {
            locationManager = (LocationManager) mContext
                    .getSystemService(LOCATION_SERVICE);

            // GPS 정보 가져오기
            isGPSEnabled = locationManager
                    .isProviderEnabled(LocationManager.GPS_PROVIDER);

            // 현재 네트워크 상태 값 알아오기
            isNetworkEnabled = locationManager
                    .isProviderEnabled(LocationManager.NETWORK_PROVIDER);

            if (!isGPSEnabled && !isNetworkEnabled) {
                // GPS 와 네트워크사용이 가능하지 않을때 소스 구현
            } else {
                this.isGetLocation = true;
                // 네트워크 정보로 부터 위치값 가져오기
                if (isNetworkEnabled) {
                    locationManager.requestLocationUpdates(
                            LocationManager.NETWORK_PROVIDER,
                            MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

                    if (locationManager != null) {
                        location = locationManager
                                .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                        if (location != null) {
                            // 위도 경도 저장
                            lat = location.getLatitude();
                            lon = location.getLongitude();
                        }
                    }
                }

                if (isGPSEnabled) {
                    if (location == null) {
                        locationManager.requestLocationUpdates(
                                LocationManager.GPS_PROVIDER,
                                MIN_TIME_BW_UPDATES,
                                MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                        if (locationManager != null) {
                            location = locationManager
                                    .getLastKnownLocation(LocationManager.GPS_PROVIDER);
                            if (location != null) {
                                lat = location.getLatitude();
                                lon = location.getLongitude();
                            }
                        }
                    }
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return location;
    }

    /**
     * GPS 종료
     * */
    public void stopUsingGPS(){
        if(locationManager != null){
            locationManager.removeUpdates(GpsInfo.this);
        }
    }

    /**
     * 위도값을 가져옵니다.
     * */
    public double getLatitude(){
        if(location != null){
            lat = location.getLatitude();
        }
        return lat;
    }

    /**
     * 경도값을 가져옵니다.
     * */
    public double getLongitude(){
        if(location != null){
            lon = location.getLongitude();
        }
        return lon;
    }

    /**
     * GPS 나 wife 정보가 켜져있는지 확인합니다.
     * */
    public boolean isGetLocation() {
        return this.isGetLocation;
    }

    /**
     * GPS 정보를 가져오지 못했을때
     * 설정값으로 갈지 물어보는 alert 창
     * */
    public void showSettingsAlert(){
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

        alertDialog.setTitle("GPS 사용유무셋팅");
        alertDialog.setMessage("GPS 셋팅이 되지 않았을수도 있습니다. \n 설정창으로 가시겠습니까?");

        // OK 를 누르게 되면 설정창으로 이동합니다.
        alertDialog.setPositiveButton("Settings",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int which) {
                        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        mContext.startActivity(intent);
                    }
                });
        // Cancle 하면 종료 합니다.
        alertDialog.setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

        alertDialog.show();
    }

    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub

    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }
}

 

 

 

 

 

 

 

 

반응형

댓글()

ffmpeg 명령어로 포맷 변환 예제 (mkv to mp4, mp4 to mp3)

리눅스/OS 일반|2024. 11. 1. 18:47
반응형

ffmpeg 명령으로 할 수 있는것은 다양하지만, 필자의 필요에 의해서 아래 내용만 기록해 둡니다. 

 

 

1. mkv to mp4

 

# ffmpeg -i example.mkv -c:v copy -c:a copy example.mp4

 

입력 파일 : example.mkv

출력 파일 : example.mp4

 

위 옵션 사용시 비디오 및 오디오 스트림이 원본 품질로 유지됩니다.

이 방식은 매우 빠르고 효율적이며, 데이터 손실이 없습니다.

 

 

2. mp4 to mp3

 

영상에서 오디오만 추출이 가능합니다.

 

# ffmpeg -i input.mp4 -q:a 0 -map a output.mp3

 

-i input.mp4 : 입력 MP4 파일

-q:a 0 : 오디오 품질을 최상으로 설정 (-q:a 0 대신에 -b:a 128k 와 같이 비트레이트 지정 가능)

-map a : 오디오 스트림만 추출

output.mp3 : 출력 MP3 파일 이름

 

특정 시간대의 오디오만 추출하려면 -ss (시작 시간) 와 -t (지속 시간) 를 추가합니다.

 

# ffmpeg -ss 00:01:00 -i input.mp4 -to 00:00:30 -q:a 0 -map a output.mp3

 

-ss 00:01:00 : 추출 시작 시간 (1분 0초)

-t 00:00:30 : 추출 지속 시간 (0분 30초)

-q:a 0 : 오디오 품질을 최상으로 설정 (-q:a 0 대신에 -b:a 128k 와 같이 비트레이트 지정 가능)

빠른 처리를 위해 -ss 옵션을 입력 파일 앞에 배치 하였습니다.

  이 경우, ffmpeg는 해당 시간대부터 직접 처리하므로 더욱 빠릅니다.

- mp4 말고 오디오파일 mp3 에서 부분 추출도 가능합니다.

 

반응형

댓글()

VideoJS 로 웹페이지에서 동영상 플레이어 사용하기

반응형

소스코드는 굉장히 단순합니다.

아래 옵션중 vjs-big-play-centered 는 플레이 버튼을 중앙에 두며, 미설정시 좌측 상단에 버튼이 위치합니다.

스마트폰에서 재생 버튼이 느리게 동작되어 영상을 다운로드 후 재생하는 듯 보인다면 웹서버에 H.264 모듈을 설치하여 스트리밍이 가능합니다.

 

<head>
        <meta charset="UTF-8">
        <link href="https://cdnjs.cloudflare.com/ajax/libs/video.js/7.10.2/video-js.min.css" rel="stylesheet" />

        <script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/7.10.2/video.min.js"></script>

</head>


<body>
<video id="my-video" 

class="video-js vjs-big-play-centered

controls 

preload="auto" 

width="320

height="180

data-setup='{
"autoplay": true
}'>
        <source src="The.mkv" type='video/mp4'>

        <track kind="subtitles" src="The.vtt" srclang="ko" label="Korean" default />

</video>

</body>

 

 

* 참고 (SRT -> VTT 자막 변경 명령어)

아래 3가지만 고치면 되지만, 번거로우므로 명령어를 사용합니다.

- 시간 정보에 , (콤마) 대신 . (점)

- 자막 순번 제거

- 맨 위에 WEBVTT 라고 명시

# ffmpeg -i The.srt The.vtt

반응형

댓글()

Ubuntu 24.04 GNOME 46 Orchis 테마 적용하기

리눅스/OS 일반|2024. 9. 26. 13:53
반응형

- 로컬PC 일반 계정에서 적용이 잘 되는것 확인하였습니다.

 

파일 배포 URL

https://www.pling.com/p/2176652/

plymouth-theme.zip
0.46MB
neofetch-config.zip
0.00MB
GTK-Themes.zip
2.56MB
cava-config.zip
0.00MB
conky-config.zip
0.41MB
cursors-theme.zip
4.57MB
fonts1.zip
14.32MB
fonts2.zip
12.89MB

(fonts1.zip 과 font2.zip 는 fonts.zip 을 나누어 올린것임)

gnome-extensions.zip
1.76MB
ubuntu-desktop-settings.zip
0.01MB
fishomp-config.zip
0.12MB
wallpapers.zip
0.37MB
icon-themes.zip
19.35MB

 

 

세팅 방법 동영상 강좌

https://www.youtube.com/watch?v=5nJdzjoiygc&t=3s

 

 

Documents 에 나오는 명령어 입니다.

컨테이너 XRDP 접근하여 ubuntu 계정으로 로그인하고 진행하였습니다.

 

OS 환경 업데이트

$ sudo apt update && sudo apt dist-upgrade -y

 

어플 및 의존성 패키지 설치

$ sudo apt install curl \

rsync \

git \

gdebi \

nautilus-admin \

nautilus-extension-gnome-terminal \

sassc \

gnome-tweaks \

gnome-shell-extension-manager -y

 

리소스 파일 다운로드 (12개 파일 - fonts.zip 은 한개로 침)

$ cd Downloads

$ sudo apt -y install wget

$ wget http://sysdocu.kr/orchis/filelist.txt

$ wget -i filelist.txt

$ cd ..

 

GNOME 확장 설치

$ unzip -o $HOME/Downloads/gnome-extensions.zip -d $HOME/.local/share/gnome-shell/

 

GTK 테마 설치

$ mkdir -p $HOME/.themes
$ unzip -o $HOME/Downloads/GTK-Themes.zip -d $HOME/.themes

$ mkdir -p $HOME/.config/gtk-4.0
$ ln -sf $HOME/.themes/Orchis-Dark/gtk-4.0/{assets,gtk.css,gtk-dark.css} $HOME/.config/gtk-4.0/

 

아이콘, 커서 테마 설치

$ mkdir -p $HOME/.local/share/icons
$ unzip -o $HOME/Downloads/icon-themes.zip -d $HOME/.local/share/icons

$ mkdir -p $HOME/.icons
$ unzip -o $HOME/Downloads/cursors-theme.zip -d $HOME/.icons

 

폰트, 바탕화면 설치

$ unzip -o $HOME/Downloads/fonts.zip -d $HOME/.local/share/

$ sudo unzip -o $HOME/Downloads/wallpapers.zip -d /usr/share/backgrounds/

 

Conky 위젯 설치 및 설정

$ sudo apt install conky-all jq curl playerctl -y
$ unzip -o $HOME/Downloads/conky-config.zip -d $HOME/.config

Cava, 터미널, 오디오, 가상화, NeoFetch 설치

$ sudo apt install cava -y

$ unzip -o $HOME/Downloads/cava-config.zip -d $HOME/.config

$ sudo apt install neofetch -y

$ unzip -o $HOME/Downloads/neofetch-config.zip -d $HOME/.config

 

Fish 쉘, Oh My Posh 설치

$ sudo apt install fish -y

$ chsh -s /usr/bin/fish
Password: (ubuntu 계정 패스워드 입력)

$ sudo wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh

$ sudo chmod +x /usr/local/bin/oh-my-posh 
$ unzip -o $HOME/Downloads/fishomp-config.zip -d $HOME
$ chmod u+rw ~/.poshthemes/*.json

 

Flatpak, Appimage 지원 활성화

$ sudo apt install gnome-software gnome-software-plugin-flatpak flatpak libfuse2 -y

$ flatpak remote-add --if-not-exists flathub http://flathub.org/repo/flathub.flatpakrepo

(화면 팝업으로 패스워드 입력)

$ sudo flatpak install flathub io.bassi.Amberol -y    // 여기에서 원래는 sudo 가 없지만, LXC 에서는 권한이 없어 추가해보았음

 

(위가 잘 안되면 반복 하거나 메모리 증설해볼 것. 나는 어떻게 넘어감...)

 

$ sudo flatpak override --filesystem=$HOME/.themes
$ sudo flatpak override --filesystem=$HOME/.local/share/icons
$ sudo flatpak override --filesystem=xdg-config/gtk-4.0

 

GNOME 앱 설치

$ sudo apt install gnome-weather \

gnome-maps \

gnome-audio \

gnome-calendar \

gnome-clocks \

gnome-connections \

gnome-console \

gnome-contacts \

gnome-music \

vlc \

gnome-shell-pomodoro -y

 

Plymouth 테마 설치 및 변경

$ sudo apt install plymouth -y
$ sudo unzip -o $HOME/Downloads/plymouth-theme.zip -d /usr/share/plymouth/themes
$ sudo update-alternatives --install /usr/share/plymouth/themes/default.plymouth default.plymouth /usr/share/plymouth/themes/hexagon_dots/hexagon_dots.plymouth 100

$ sudo update-alternatives --config default.plymouth

(여기에서  /usr/share/plymouth/themes/hexagon_dots/hexagon_dots.plymouth   100       manual mode 행으로 된것을 찾아 앞 번호를 입력하면 됨)
$ sudo update-initramfs -u    // LXC 에서 명령어가 없다면 명령어부터 설치 sudo apt install initramfs-tools

 

GNOME 쉘 세팅 적용

$ unzip -o $HOME/Downloads/ubuntu-desktop-settings.zip -d $HOME/Downloads/
$ dconf load / < $HOME/Downloads/ubuntu-desktop-settings.conf

 

데스크톱이라면  이때 배경이 바뀌는게 보임.

LXC 는 ubuntu 계정으로 다시 로그인해야 보일지도? 메뉴를 눌러 로그아웃을 못하는 경우 호스트에서 컨테이너를 stop, start 해보자. 잘 안되네... 배경은 적용된 것 같기도 하고.. 근데 날씨 API 를 등록해야 하니, 이런건 컨테이너에서 사용 못하겠다.

 

SNAP 앱과 서비스 삭제

$ cp -afv $HOME/snap $HOME/Downloads/
$ sudo snap remove --purge firefox
$ sudo snap remove --purge snap-store
$ sudo snap remove --purge gnome-42-2204
$ sudo snap remove --purge gtk-common-themes
$ sudo snap remove --purge snapd-desktop-integration
$ sudo snap remove --purge firmware-updater
$ sudo snap remove --purge core22
$ sudo snap remove --purge bare
$ sudo snap remove --purge snapd
$ sudo apt autoremove --remove snapd -y

$ sudo rm -rf /var/cache/snapd/

$ echo "Package: snapd
Pin: release a=*
Pin-Priority: -10" | sudo tee /etc/apt/preferences.d/nosnap.pref

$ sudo apt update

 

파이어폭스 웹브라우저 설치

$ sudo add-apt-repository -y ppa:mozillateam/ppa && sudo apt update

$ echo 'APT::Key::Assert-Pubkey-Algo "";' | sudo tee /etc/apt/apt.conf.d/99weakkey-warning

$ sudo apt update

$ sudo apt install -y -t 'o=LP-PPA-mozillateam' firefox

$ echo "Unattended-Upgrade::Allowed-Origins:: \"LP-PPA-mozillateam:$distro_codename\";" | sudo tee /etc/apt/apt.conf.d/51unattended-upgrades-firefox

$ echo 'Package: firefox*
Pin: release o=LP-PPA-mozillateam
Pin-Priority: 501' | sudo tee /etc/apt/preferences.d/mozillateamppa

$ sudo apt update

 

파이어폭스 테마 설치

$ cd $HOME/Downloads

$ git clone https://github.com/vinceliuice/WhiteSur-firefox-theme.git

$ cd WhiteSur-firefox-theme/

$ sudo ./install.sh -m    // 데스크톱은 모르겠는데 LXC 에서는 sudo 를 붙여주어야 했음. 매뉴얼에서는 안붙임.

 

끝.

 

바탕화면 날씨정보 지역 ID 및 API 발급 (로그인 필요)

$ vi ~/.config/conky/Alfirk-MOD/scripts/weather-v2.0.sh

수정 후 스크립트 실행하면 적용됨

https://openweathermap.org

 

 

반응형

댓글()

Ubuntu 24.04 Desktop 에서 Samsung SL-J3560FW 프린터 잡기

리눅스/OS 일반|2024. 9. 25. 09:31
반응형

프린터 설정에서 프린터를 추가할때 Samsung SL-J3560FW 모델과 동일한 드라이버가 출력되지 않고, 삼성 홈페이지에서 조차 리눅스용 드라이버를 제공하지 않습니다.

이러한 환경에서 아래 드라이버를 선택하여 설치하였더니 잘 되는 것으로 확인 했습니다.

 

- 설정 > 프린터 > [프린터 추가] > 하단 검색창에 프린터 IP 입력

 

조금 기다리면 아래 세가지 항목이 선택항목으로 출력됩니다.

-  JetDirect

- LPD

- SL-J3560FW

 

여기에서 올바른 모델명을 선택하여 진행하면 인쇄시 글씨가 깨져 출력되므로,

JetDirect 를 선택, [추가] 하고 아래 모델명을 찾아 설치합니다.

- 제조사 : Hewlett-Packard

- 드라이버 : HP Business Inkjet 110, hpcups 3.23.12

 

반응형

댓글()

간단한 리눅스 백업 스크립트 적용하기

리눅스/OS 일반|2024. 9. 19. 08:58
반응형

백업본을 저장할 디렉토리를 생성합니다.

# mkdir /backup

 

백업 스크립트를 생성합니다.

필요에 따라 아래 내용을 수정하여 사용하면 됩니다.

# vi /root/backup.sh

#!/bin/bash

# 오래된 파일 및 디렉토리 삭제
find "/backup/" -type f -mtime +5 -exec rm -f {} \;
find "/backup/" -type d -mtime +5 -exec rm -rf {} \;

# 오늘자 백업 디렉토리 생성
today=$(date +%Y%m%d)
mkdir -p /backup/${today}

# 홈페이지 소스 및 DB 백업
cd /home/sysdocu/
tar cvzf /backup/${today}/public_html.tar.gz public_html
mysqldump -uroot -p12345678 --all-databases > /backup/${today}/all.sql

# 시스템 기본 설정 파일 백업
cd /backup/${today}
cp -arp /etc/iptables/rules.v4 .
cp -arp /etc/crontab .
cp -arp /root/backup.sh .

 

# chmod 700 /root/backup.sh

 

백업 스크립트를 매일 04시에 실행되도록 스케쥴러에 등록합니다.

# echo "0 4 * * * root sh /root/backup.sh" >> /etc/crontab

 

반응형

댓글()

Ubuntu 24.04 vsftpd 설치 및 기본 설정

리눅스/FTP|2024. 9. 13. 14:44
반응형

설치는 아래와 같습니다.
# apt -y install vsftpd

시스템 계정으로 로그인하여 파일 업로드를 사용하기 위해서는 아래 옵션으로 바꿔주어야 합니다.
# vi /etc/vsftpd.conf

# 익명 접근 차단
anonymous_enable=NO

# 로컬 사용자 계정에 대한 FTP 접속 및 쓰기 허용
local_enable=YES
write_enable=YES

# 사용자 홈 디렉토리 상위 디렉토리 이동 차단
chroot_local_user=YES
allow_writeable_chroot=YES

# 패시브 모드 설정 : 지정한 포트 범위로 데이터 전송 (방화벽에 포트 추가 필요)
pasv_enable=YES
pasv_min_port=50001
pasv_max_port=50005


수정 내용은 데몬을 재시작하여 적용합니다.
# systemctl restart vsftpd

반응형

댓글()