• 03-12-2023, 00:18:02
    #1
    moviepy ve flask kütüphanesini bilgisayarina kurman gerekiyor kod tamamiyle kendim yazdım geliştirp kullanabilirsin


    python dosyasına yazılacak kod:
    from flask import Flask, render_template, request, send_file
    from werkzeug.utils import secure_filename
    from moviepy.editor import VideoFileClip
    import os
    app = Flask(__name__)
    # Dosyanın kaydedileceği dizin
    UPLOAD_FOLDER = 'C:\\Users\\User\\Desktop\\ypy\\elementors\\cevir\\sesler'
    app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
    @app.route('/')
    def index():
        return render_template('index.html')
    @app.route('/upload', methods=['POST'])
    def upload():
        uploaded_file = request.files['videoFile']
        if uploaded_file.filename != '':
            filename_cleaned = secure_filename(uploaded_file.filename)
            uploaded_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename_cleaned))
            video = VideoFileClip(os.path.join(app.config['UPLOAD_FOLDER'], filename_cleaned))
            audio = video.audio
            audio_path = f"sesdosyasi_{filename_cleaned}.mp3"
            audio_full_path = os.path.join(app.config['UPLOAD_FOLDER'], audio_path)
            audio.write_audiofile(audio_full_path)
            video.close()
            audio.close()
            return render_template('index.html', audio_path=audio_path, show_download=True)  # Sonucu index.html içinde göster ve indirme butonunu göster
        return 'Video yüklenemedi.'
    @app.route('/download/<path:filename>')
    def download_file(filename):
        file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
        return send_file(file_path, as_attachment=True)
    if __name__ == '__main__':
        app.run(debug=True)
    templates klasörü oluşturulup içine index.html dosyası oluşturuyorsun içine şunu yapiştir.:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Video Yükle</title>
        <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
    </head>
    <body class="container mt-5">
        <div class="text-center">
            <h1>Video Yükle</h1>
            <form action="/upload" method="post" enctype="multipart/form-data" class="mt-4">
                <div class="input-group mb-3">
                    <div class="custom-file">
                        <input type="file" class="custom-file-input" id="videoFile" name="videoFile">
                        <label class="custom-file-label" for="videoFile">Video Seç</label>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary">Videoyu Yükle</button>
            </form>
            {% if show_download %}
                <div id="result" style="display: block;">
                    <h2>Ses Dosyası Oluşturuldu!</h2>
                    <p>Ses Dosyasını İndir:</p>
                    <a href="{{ url_for('download_file', filename=audio_path) }}" download="sesdosyasi.mp3" class="btn btn-success">İndir</a>
                </div>
            {% endif %}
        </div>
    </body>
    </html>

    UPLOAD_FOLDER = 'C:UsersUserDesktopypyelementorscevirsesler' python dosyasındaki bu dizine sesleri nereye kaydedip çekilecegini göstermen gerekiyor..


    daha sonra python dosyasını çalıştırıyorsun http://127.0.0.1:5000/ sana şöyle bir adres veriyr açılan syfadan diledigin kadar videoyuyu sese dönüştür..
  • 03-12-2023, 00:20:56
    #2
    Hocam emeğinize sağlık. yalnız anlayamadım. Videodan sesi mi ayıklıyor sadece?
  • 03-12-2023, 00:21:29
    #3
    B4RIS adlı üyeden alıntı: mesajı görüntüle
    Hocam emeğinize sağlık. yalnız anlayamadım. Videodan sesi mi ayıklıyor sadece?
    evet hocam aynen öyle.
  • 03-12-2023, 01:00:36
    #4
    Proje gayet hoş yazılmış fakat 7. satırı proje taşınabilirliği açısından şöyle yazmanızı öneririm:

    UPLOAD_FOLDER = os.path.join(BASE_DIR, 'uploads')