commit bb471c24ae61fa06c68dc34371285a17a606884a
Author: phantomjinx <p.g.richard...@phantomjinx.co.uk>
Date:   Sat Dec 11 23:35:21 2010 +0000

    Adds support for converting videos to ipod spec mp4s
    
    * video filetype uses generic convert-2mp4.sh script to convert videos to
      mp4s.
    
    * convert-2mp4.sh
      * Uses ffmpeg for the conversion
      * Adds tag information using ffmpeg's metadata options.
      * Log file added for debugging problems

 libgtkpod/prefs.c                     |    7 ++++-
 plugins/core_preferences/core_prefs.c |    2 +
 plugins/filetype_video/plugin.c       |    4 +-
 plugins/filetype_video/videofile.c    |    9 ++++++
 plugins/filetype_video/videofile.h    |    2 +
 scripts/Makefile.am                   |    1 +
 scripts/convert-2mp4.sh               |   49 +++++++++++++++++++++++++++++++++
 scripts/gtkpod-convert-common.sh      |    4 +-
 8 files changed, 73 insertions(+), 5 deletions(-)
---
diff --git a/libgtkpod/prefs.c b/libgtkpod/prefs.c
index b38dd25..bfd769d 100644
--- a/libgtkpod/prefs.c
+++ b/libgtkpod/prefs.c
@@ -188,6 +188,11 @@ static void set_default_preferences() {
     g_free(str);
     prefs_set_int("convert_wav", FALSE);
 
+    str = g_build_filename(get_script_dir(), "convert-2mp4.sh", NULL);
+    prefs_set_string("path_conv_mp4", str);
+    g_free(str);
+    prefs_set_int("convert_mp4", TRUE);
+
     /* Set colum preferences */
     for (i = 0; i < TM_NUM_COLUMNS; i++) {
         prefs_set_int_index("col_order", i, i);
@@ -879,7 +884,7 @@ static void cleanup_keys() {
 
         const gchar **keyp;
         const gchar *keys[] =
-            { "path_conv_m4a", "path_conv_wav", "path_conv_mp3", 
"path_conv_ogg", "path_conv_flac", NULL };
+            { "path_conv_m4a", "path_conv_wav", "path_conv_mp3", 
"path_conv_ogg", "path_conv_flac", "path_conv_mp4", NULL };
 
         for (keyp = keys; *keyp; ++keyp) {
             buf = prefs_get_string(*keyp);
diff --git a/plugins/core_preferences/core_prefs.c 
b/plugins/core_preferences/core_prefs.c
index 0a98de6..0cc6bd9 100644
--- a/plugins/core_preferences/core_prefs.c
+++ b/plugins/core_preferences/core_prefs.c
@@ -95,6 +95,7 @@ const gchar *conv_checkbox_map[][3] = {
     { "convert_mp3", "convert_mp3", NULL },
     { "convert_aac", "convert_m4a", NULL },
     { "convert_wav", "convert_wav", NULL },
+    { "convert_mp4", "convert_mp4", NULL },
     { "display_conversion_log", "", NULL },
 };
 
@@ -117,6 +118,7 @@ ind_string conv_paths[] = {
     { TARGET_FORMAT_AAC, "path_conv_m4a" },
     { TARGET_FORMAT_MP3, "path_conv_mp3" },
     { -1, "path_conv_wav" },
+    { -1, "path_conv_mp4" }
 };
 
 static TempPrefs *temp_prefs = NULL;
diff --git a/plugins/filetype_video/plugin.c b/plugins/filetype_video/plugin.c
index 2dd448d..01b5a99 100644
--- a/plugins/filetype_video/plugin.c
+++ b/plugins/filetype_video/plugin.c
@@ -87,8 +87,8 @@ static void video_filetype_iface_init(FileTypeInterface 
*iface) {
     iface->read_lyrics = filetype_no_read_lyrics; /* FIXME */
     iface->write_lyrics = filetype_no_write_lyrics; /* FIXME */
     iface->read_gapless = filetype_no_read_gapless; /* FIXME ?? */
-    iface->can_convert = filetype_no_convert;
-    iface->get_conversion_cmd = filetype_no_conversion_cmd;
+    iface->can_convert = video_can_convert;
+    iface->get_conversion_cmd = video_get_conversion_cmd;
     iface->get_gain_cmd = filetype_no_gain_cmd;
 }
 
diff --git a/plugins/filetype_video/videofile.c 
b/plugins/filetype_video/videofile.c
index 8afd0f0..a3fcc65 100644
--- a/plugins/filetype_video/videofile.c
+++ b/plugins/filetype_video/videofile.c
@@ -48,3 +48,12 @@ Track *video_get_file_info(const gchar *filename) {
 
     return track;
 }
+
+gboolean video_can_convert() {
+    gchar *cmd = video_get_conversion_cmd();
+    return cmd && cmd[0] && prefs_get_int("convert_mp4");
+}
+
+gchar *video_get_conversion_cmd() {
+    return prefs_get_string("path_conv_mp4");
+}
diff --git a/plugins/filetype_video/videofile.h 
b/plugins/filetype_video/videofile.h
index 5ba30a9..dcc2381 100644
--- a/plugins/filetype_video/videofile.h
+++ b/plugins/filetype_video/videofile.h
@@ -33,5 +33,7 @@
 #include "libgtkpod/itdb.h"
 
 Track *video_get_file_info(const gchar *name);
+gboolean video_can_convert();
+gchar *video_get_conversion_cmd();
 
 #endif
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 563e0bb..51c98cd 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -7,6 +7,7 @@ scriptdir = $(pkgdatadir)/scripts
 script_SCRIPTS = \
        convert-2m4a.sh \
        convert-2mp3.sh \
+       convert-2mp4.sh \
        gtkpod-convert-common.sh \
        ldif2vcf.sh \
        mab2vcard \
diff --git a/scripts/convert-2mp4.sh b/scripts/convert-2mp4.sh
new file mode 100755
index 0000000..acfb803
--- /dev/null
+++ b/scripts/convert-2mp4.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# Script that converts a file into an mp4 file
+#
+# USAGE:
+#
+# convert-2mp4.sh [options] inputfile
+#
+# For a list of allowed options please consult gtkpod-convert-common.sh
+#
+# STDOUT's last line is the converted filename.
+# Return Codes:
+#   0 ok
+#   1 input file not found
+#   2 output file cannot be created
+#   3 cannot get info
+#   4 cannot exec decoding
+#   5 cannot exec encoding
+#   6 conversion failed
+#   7 unknown option
+#
+
+# Constants
+extension="mp4"
+ENCODER_OPTS="-y -sameq -acodec aac -ab 160k -b 1100k -s 640x480 -aspect 4:3"
+ENCODER="ffmpeg"
+
+echo "Attempting to convert file" >> $LOG
+
+. ${0%/*}/gtkpod-convert-common.sh
+
+LOG=`dirname "$outfile"`
+LOG=${LOG%.log}
+
+"$encoder" -i "$infile" $ENCODER_OPTS -metadata author="$artist" -metadata 
title="$title" -metadata album="$album" -metadata year="$year" -metadata 
track="$track" -metadata genre="$genre" -metadata comment="$comment" "$outfile" 
>> $LOG 2>&1
+
+# Check result
+if [ "x$?" != "x0" ]; then
+       echo "Failed with status 6" >> $LOG
+    exit 6
+fi
+
+if [ ! -f "$outfile" ]; then
+       echo "Failed with status 6" >> $LOG
+       exit 8
+fi
+
+# Seems to be ok: display filename for gtkpod
+echo $outfile
+exit 0
diff --git a/scripts/gtkpod-convert-common.sh b/scripts/gtkpod-convert-common.sh
index f62456f..33b87e2 100755
--- a/scripts/gtkpod-convert-common.sh
+++ b/scripts/gtkpod-convert-common.sh
@@ -3,7 +3,7 @@
 #
 # USAGE:
 #
-# Called by convert-2mp3.sh and convert-2m4a.sh.
+# Called by convert-2mp3.sh, convert-2m4a.sh, convert-2mp4.sh.
 #
 # The following command line arguments are being used
 #
@@ -96,7 +96,7 @@ case "$filetype" in
                decoder="oggdec" ; options="--quiet --output - --" ;;
        m4a)    decoder="faad" ; options="-o -" ;;
        wav)    decoder="" ;;
-       *)      exit 4 ;;
+       *)      decoder="ffmpeg" ;;
 esac
 
 # Check for the existence of decoder

------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages, 
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev 
_______________________________________________
gtkpod-cvs2 mailing list
gtkpod-cvs2@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to