Last active
          January 23, 2025 17:03 
        
      - 
      
- 
        Save Cemu0/9469d8f859f49378dbba9e5d461b9b62 to your computer and use it in GitHub Desktop. 
    ffmpeg python create mp4
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| while true; do | |
| # Capture a frame from the RTSP stream | |
| filename="$(date +\%Y-\%m-\%d_\%H-\%M-\%S).png" | |
| filepath="/output2/$(date +\%Y-\%m-\%d_\%H-\%M-\%S).png" | |
| ffmpeg -rtsp_transport tcp -i 'rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=0' -vframes 1 -q:v 1 -s hd1080 -pix_fmt yuv420p "$filepath" | |
| # Append the filename to files.txt | |
| echo "$filename" >> /output2/files.txt | |
| # Sleep for 60 seconds | |
| sleep 60 | |
| done | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | version: '3.8' | |
| services: | |
| rtsp-capture: | |
| image: jrottenberg/ffmpeg:4.3-alpine | |
| container_name: rtsp-capture | |
| volumes: | |
| - ./output:/output | |
| - ./output2:/output2 | |
| - ./capture.sh:/capture.sh | |
| entrypoint: ["sh", "/capture.sh"] | |
| network_mode: host | |
| restart: always | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import os | |
| import subprocess | |
| print("Starting the process...") | |
| # Directory containing the .png files | |
| image_folder = 'output2' | |
| # Output video file | |
| video_file = 'timelapse_video2.mp4' | |
| # Frame rate (frames per second) | |
| fps = 23 | |
| # Remove the existing file if it exists | |
| if os.path.exists(video_file): | |
| os.remove(video_file) | |
| print(f"Removed existing file: {video_file}") | |
| print("Creating video with ffmpeg...") | |
| # Use ffmpeg to create the video | |
| subprocess.run([ | |
| 'ffmpeg', | |
| '-framerate', str(fps), | |
| '-pattern_type', 'glob', | |
| '-i', os.path.join(image_folder, '*.png'), | |
| '-c:v', 'libx264', | |
| '-preset', 'fast', # Use 'slow' or 'veryslow' for better quality | |
| '-crf', '30', # Lower CRF value for better quality | |
| '-pix_fmt', 'yuv420p', | |
| video_file | |
| ]) | |
| print("Video creation complete!") | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment