Last active
          August 29, 2015 14:27 
        
      - 
      
- 
        Save bertrandmartel/518ee8c169dcf4f9a4c0 to your computer and use it in GitHub Desktop. 
    [ BASH ] create a video if not exist and append a series of image to this video taken from WEB (input working directory)
  
        
  
    
      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 | |
| #title :append_new_picture.sh | |
| #author :Bertrand Martel | |
| #date :16/08/2015 | |
| #description :create video if not exist and append a series of image to this video taken from WEB | |
| if [ -z $1 ] | |
| then | |
| echo "output directory is required" | |
| exit | |
| fi | |
| WORKING_DIR=$1 | |
| OUTPUT_FILE_NAME="video_space" | |
| OUTPUT_FILE_PATH="$WORKING_DIR/$OUTPUT_FILE_NAME.avi" | |
| TEMPORARY_FILE_NAME="temp_space" | |
| TEMPORARY_FILE_NAME_VIDEO="temp_video" | |
| declare -a PICTURE_ARRAY=("https://upload.wikimedia.org/wikipedia/commons/4/4e/Anttlers101.jpg" \ | |
| "https://upload.wikimedia.org/wikipedia/commons/3/3b/NASA-SpiralGalaxyM101-20140505.jpg" \ | |
| "https://upload.wikimedia.org/wikipedia/commons/b/b0/Supernova_in_M101_2011-08-25.jpg" \ | |
| "http://1.1.1.5/bmi/images.nationalgeographic.com/wpf/media-live/photos/000/061/cache/earth-full-view_6125_990x742.jpg") | |
| cd $WORKING_DIR | |
| rm -rf $OUTPUT_FILE_PATH | |
| rm -rf $TEMPORARY_FILE_NAME.avi | |
| rm -rf $TEMPORARY_FILE_NAME.jpg | |
| rm -rf $TEMPORARY_FILE_NAME_VIDEO.avi | |
| for i in {0..3} | |
| { | |
| wget ${PICTURE_ARRAY[i]} -O $TEMPORARY_FILE_NAME.jpg | |
| ffmpeg -nostdin -v verbose -f image2 -pattern_type sequence -start_number 0 -r 1 -i $TEMPORARY_FILE_NAME.jpg -s 1920x1080 $TEMPORARY_FILE_NAME.avi | |
| rm $TEMPORARY_FILE_NAME.jpg | |
| if [ -f $OUTPUT_FILE_PATH ]; | |
| then | |
| # concat this video and former video | |
| ffmpeg -nostdin -v verbose -i "concat:$OUTPUT_FILE_NAME.avi|$TEMPORARY_FILE_NAME.avi" -c copy $TEMPORARY_FILE_NAME_VIDEO.avi | |
| rm $TEMPORARY_FILE_NAME.avi | |
| rm $OUTPUT_FILE_NAME.avi | |
| mv $TEMPORARY_FILE_NAME_VIDEO.avi $OUTPUT_FILE_NAME.avi | |
| else | |
| mv $TEMPORARY_FILE_NAME.avi $OUTPUT_FILE_NAME.avi | |
| fi | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment