{"id":103,"date":"2016-07-17T23:55:37","date_gmt":"2016-07-17T21:55:37","guid":{"rendered":"http:\/\/bastardo.de\/?p=103"},"modified":"2016-07-17T23:55:37","modified_gmt":"2016-07-17T21:55:37","slug":"video-2-mp4-converter","status":"publish","type":"post","link":"https:\/\/bastardo.de\/index.php\/2016\/07\/17\/video-2-mp4-converter\/","title":{"rendered":"video 2 mp4 converter"},"content":{"rendered":"<p>created a new script for movie 2 mp4 convertion<\/p>\n<p>features:<\/p>\n<p>*\u00a0 save metadata<br \/>\n* save creaton date<br \/>\n* delete greater files if you whant<\/p>\n<pre class=\"brush:bash\">#!\/bin\/bash\n# \n# converter for video files to mp4\n# this script delete also all huger files if you want\n# please take care with DELETE FILES = yes\n# double check our output first if the quality is good enough for you\n# this script keeps metadata and date of creaton for the file\n#\n# written 2016\/07\/17 by Daniel Gohlke to clean up my NAS\n#\n# you need ffmpeg and some codecs, if i forget something please update this script\n# sudo apt-get install libavcodec-extra-53 libavutil-extra-51 libavformat-extra-53 libx264-146 ffmpeg\n# change what ever you need\n\nEXTENSION_NEW=\"mp4\"\nDELETE_FILES=\"no\"\nDEFAULT_CRF=\"22\" # some kind of medium\nOUTPUT_DIR=\"output\"\n\nread -p \"Please enter CRF Quality \/ higher value is lower quality [51 worst .. 0 Loseless (default $DEFAULT_CRF) ]: \" CRF\nCRF=${CRF:-$DEFAULT_CRF}\necho \"convert with CRF $CRF\"\n\n\n# error handling\nfunction finish {\n  if [ $FILENAME ]; then\n    echo \"some error occoured, cleanup file $OUTPUT_DIR\/$FILENAME.mp4\"\n    echo \"Error on line $1\"\n    rm -f \"$OUTPUT_DIR\/$FILENAME.mp4\"\n  else\n    echo \"User Break, leave $d untouched\"\n  fi\n  rm -f $OUTPUT_DIR\/filelist.txt\n}\n\n# Trap if something failed\ntrap 'finish $LINENO' ERR\n#trap 'finish $LINENO' EXIT\n\n\nfunction start_convert {\n\n mkdir -p $OUTPUT_DIR\n find . -type f \\( ! -iname \"filelist.txt\" \\) | grep -v \"$OUTPUT_DIR\" &gt; $OUTPUT_DIR\/filelist.txt \n   for d in $( cat $OUTPUT_DIR\/filelist.txt ); do\n#  for d in *; do\n    echo \"converting with crf $DEFAULT_CRF $d\";\n    FILENAME=$(basename \"$d\")\n    EXTENSION=\"${FILENAME##*.}\"\n    FILENAME=\"${FILENAME%.*}\"\n    \n    # convert\n    ffmpeg -stats -i $d -c:v h264 -strict experimental -crf $CRF -map_metadata 0 $OUTPUT_DIR\/$FILENAME.mp4\n\n    # pply another file's attributes to new file\n    touch -r $d $OUTPUT_DIR\/$FILENAME.mp4    \n    FILESIZE_OLD=$(stat -c%s \"$FILENAME.$EXTENSION\")\n    FILESIZE_NEW=$(stat -c%s \"$OUTPUT_DIR\/$FILENAME.$EXTENSION_NEW\")\n#    echo $FILESIZE_OLD  \n#    echo $FILESIZE_NEW\n    \n    if [ \"$DELETE_FILES\" == \"yes\" ]; then\n      echo \"delete greater files is turned on\"\n  \n      if [ \"$FILESIZE_OLD\" -ge \"$FILESIZE_NEW\" ]; then\n        echo \"delete $FILENAME.$EXTENSION\"\n        rm -f $FILENAME.$EXTENSION\n      else \n       echo \"delete $OUTPUT_DIR\/$FILENAME.$EXTENSION_NEW\"\n       rm -f $OUTPUT_DIR\/$FILENAME.$EXTENSION_NEW\n      fi\n        \n    else \n      echo \"delete greater files is turned off\"\n    fi\n    \n  done\n\nrm -f $OUTPUT_DIR\/filelist.txt\nexit 0\n}\n\n#ffmpeg -stats -i 0621232021DVB-TDasErste.m4v -c:v h264 -strict experimental -crf 20 -map_metadata 0  FILENAMEdefaultcrf20.mp4\n\n# Start Program\nread -p \"Do you wish to start convert your videos? (y\/n)\" yn\ncase $yn in\n  [Yy]* ) start_convert;;\n  [Nn]* ) exit;;\n   * ) echo \"Please answer yes(y) or no(n).\";;\nesac<\/pre>\n<p>&nbsp;<\/p>\n<p>link to github: <a href=\"https:\/\/github.com\/danielgohlke\/scripts\/blob\/master\/converttomp4.sh\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/danielgohlke\/scripts\/blob\/master\/converttomp4.sh<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>created a new script for movie 2 mp4 convertion features: *\u00a0 save metadata * save creaton date * delete greater files if you whant #!\/bin\/bash # # converter for video files to mp4 # this script delete also all huger files if you want # please take care with DELETE FILES = yes # double [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"_links":{"self":[{"href":"https:\/\/bastardo.de\/index.php\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bastardo.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bastardo.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bastardo.de\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bastardo.de\/index.php\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":0,"href":"https:\/\/bastardo.de\/index.php\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"wp:attachment":[{"href":"https:\/\/bastardo.de\/index.php\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bastardo.de\/index.php\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bastardo.de\/index.php\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}